summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-12-07 14:08:38 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-12-07 14:08:38 +0800
commit310a8951557a6e6ac200ba08301ab7ef77a64686 (patch)
tree2bafa95fb4e209196733d8f4c55fc1e734f47ea9
parent6e0e1ba8d1d6e309933e636f0ba7a32c4b3d0b3d (diff)
downloadcompiler2015-310a8951557a6e6ac200ba08301ab7ef77a64686.tar
compiler2015-310a8951557a6e6ac200ba08301ab7ef77a64686.tar.gz
compiler2015-310a8951557a6e6ac200ba08301ab7ef77a64686.tar.bz2
compiler2015-310a8951557a6e6ac200ba08301ab7ef77a64686.tar.lz
compiler2015-310a8951557a6e6ac200ba08301ab7ef77a64686.tar.xz
compiler2015-310a8951557a6e6ac200ba08301ab7ef77a64686.tar.zst
compiler2015-310a8951557a6e6ac200ba08301ab7ef77a64686.zip
Allow using typedef with array types
Our parser only allows using typedef with int, float, void, so there should be no user-visible change in this commit. It just makes process_typedef and process_variable look similar.
-rw-r--r--src/semantic-analysis.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/semantic-analysis.c b/src/semantic-analysis.c
index eea37b0..f8652b2 100644
--- a/src/semantic-analysis.c
+++ b/src/semantic-analysis.c
@@ -196,8 +196,8 @@ static bool process_typedef(CcmmcAst *type_decl, CcmmcSymbolTable *table)
assert(type_decl->child->value_id.kind == CCMMC_KIND_ID_NORMAL);
const char *source_str = type_decl->child->value_id.name;
CcmmcSymbol *source_sym = ccmmc_symbol_table_retrive(table, source_str);
- // We don't support an existing array typedef
- assert(ccmmc_symbol_is_scalar(source_sym));
+ // We don't support function pointers
+ assert(!ccmmc_symbol_is_function(source_sym));
if (source_sym == NULL) {
fprintf(stderr, ERROR("ID `%s' undeclared."),
type_decl->line_number, source_str);
@@ -227,9 +227,18 @@ static bool process_typedef(CcmmcAst *type_decl, CcmmcSymbolTable *table)
break;
case CCMMC_KIND_ID_ARRAY: {
size_t array_dimension;
- size_t *array_size = get_array_size(id, &array_dimension);
- if (array_size == NULL)
+ size_t *array_size;
+ if (ccmmc_symbol_is_array(source_sym))
+ array_size = get_array_of_array_size(
+ id, &array_dimension,
+ source_sym->type.array_dimension,
+ source_sym->type.array_size);
+ else
+ array_size = get_array_size(id, &array_dimension);
+ if (array_size == NULL) {
any_error = true;
+ continue;
+ }
CcmmcSymbolType type = {
.type_base = source_sym->type.type_base,
.array_dimension = array_dimension,
@@ -262,6 +271,8 @@ static bool process_variable(CcmmcAst *var_decl, CcmmcSymbolTable *table)
assert(var_decl->child->value_id.kind == CCMMC_KIND_ID_NORMAL);
const char *type_str = var_decl->child->value_id.name;
CcmmcSymbol *type_sym = ccmmc_symbol_table_retrive(table, type_str);
+ // We don't support function pointers
+ assert(!ccmmc_symbol_is_function(type_sym));
if (type_sym == NULL) {
fprintf(stderr, ERROR("ID `%s' undeclared."),
var_decl->line_number, type_str);