summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkugwa <kugwa2000@gmail.com>2015-12-08 22:17:09 +0800
committerkugwa <kugwa2000@gmail.com>2015-12-08 22:17:09 +0800
commitce67c908a1d0819d2b3898d5c30c0b1b325bc0d3 (patch)
treeb0c6a9ba7bec91e134fd4a39010385e8d4ad414d
parent7c8774b25e6562e301af606f919ff130f26be7fb (diff)
downloadcompiler2015-ce67c908a1d0819d2b3898d5c30c0b1b325bc0d3.tar
compiler2015-ce67c908a1d0819d2b3898d5c30c0b1b325bc0d3.tar.gz
compiler2015-ce67c908a1d0819d2b3898d5c30c0b1b325bc0d3.tar.bz2
compiler2015-ce67c908a1d0819d2b3898d5c30c0b1b325bc0d3.tar.lz
compiler2015-ce67c908a1d0819d2b3898d5c30c0b1b325bc0d3.tar.xz
compiler2015-ce67c908a1d0819d2b3898d5c30c0b1b325bc0d3.tar.zst
compiler2015-ce67c908a1d0819d2b3898d5c30c0b1b325bc0d3.zip
Can declare local variable and write empty statements
-rw-r--r--src/semantic-analysis.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/semantic-analysis.c b/src/semantic-analysis.c
index 84046c0..dfb4ab0 100644
--- a/src/semantic-analysis.c
+++ b/src/semantic-analysis.c
@@ -465,6 +465,17 @@ static bool process_variable(
return any_error;
}
+static bool process_statement(CcmmcAst *stmt, CcmmcSymbolTable *table)
+{
+ bool any_error = false;
+
+ if (stmt->type_node == CCMMC_AST_NODE_NUL)
+ return any_error;
+ assert(stmt->type_node == CCMMC_AST_NODE_STMT);
+
+ return any_error;
+}
+
static bool process_block(CcmmcAst *block, CcmmcSymbolTable *table)
{
bool any_error = false;
@@ -479,6 +490,7 @@ static bool process_block(CcmmcAst *block, CcmmcSymbolTable *table)
ccmmc_symbol_table_insert(table, "void", CCMMC_SYMBOL_KIND_TYPE,
(CcmmcSymbolType){ .type_base = CCMMC_AST_VALUE_VOID });
+ // This is a function block
if (block->parent->type_node == CCMMC_AST_NODE_DECL &&
block->parent->value_decl.kind == CCMMC_KIND_DECL_FUNCTION) {
// Insert the parameters
@@ -486,8 +498,8 @@ static bool process_block(CcmmcAst *block, CcmmcSymbolTable *table)
block->leftmost_sibling->right_sibling->value_id.name);
CcmmcAst *param;
size_t i;
- for (param = block->leftmost_sibling->right_sibling->right_sibling->child, i = 0;
- i < func->type.param_count; param = param->right_sibling, i++) {
+ for (param = block->leftmost_sibling->right_sibling->right_sibling->child,
+ i = 0; i < func->type.param_count; param = param->right_sibling, i++) {
if (ccmmc_symbol_scope_exist(table->current,
param->child->right_sibling->value_id.name)) {
any_error = true;
@@ -501,9 +513,18 @@ static bool process_block(CcmmcAst *block, CcmmcSymbolTable *table)
}
}
+ CcmmcAst *child = block->child;
// Process the list of local declarations
-
+ if (child != NULL && child->type_node == CCMMC_AST_NODE_VARIABLE_DECL_LIST) {
+ for (CcmmcAst *var_decl = child->child; var_decl != NULL; var_decl = var_decl->right_sibling)
+ any_error = process_variable(var_decl, table, false) | any_error;
+ child = child->right_sibling;
+ }
// Process the list of statements
+ if (child != NULL && child->type_node == CCMMC_AST_NODE_STMT_LIST) {
+ for (CcmmcAst *stmt = child->child; stmt != NULL; stmt = stmt->right_sibling)
+ any_error = process_statement(stmt, table) | any_error;
+ }
// Pop this scope
ccmmc_symbol_table_close_scope(table);