summaryrefslogtreecommitdiffstats
path: root/src/lexer.l
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-12-03 02:10:52 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-12-03 02:10:52 +0800
commit5835f4537ae210f83391c5d8344aa7d461de7095 (patch)
tree5ddb2750e59c58b2a2908e374ae3eb1420851e60 /src/lexer.l
parentf2a04b9f3810d1c19f8359bf3f1dbbe38bf07097 (diff)
downloadcompiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.gz
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.bz2
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.lz
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.xz
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.zst
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.zip
Drop all non-namespaced symbols
1. All data types and macros in headers, global variables and functions that have external linkage are namespaced. The only two files that allow non-namespaced symbols are main.c and common.h. common.h should not be included by any other headers. 2. Coding style is fixed when possible. 3. Drop unused variables or struct members. 4. 'name' macro is renamed to 'prog_name' to prevent conflicts with ast.h. 5. %union includes a CON_Type (now CcmmcValueConst) instead of a pointer to it. This prevents an unnecessary malloc. 6. Fix buffer overflow in draw.c. draw.c should not modify the input AST while generating the graph.
Diffstat (limited to 'src/lexer.l')
-rw-r--r--src/lexer.l27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/lexer.l b/src/lexer.l
index 92aa645..168412b 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -93,31 +93,20 @@ ERROR .
return ID;
}
{CONST_INT} {
- CON_Type *p;
- p = malloc(sizeof(CON_Type));
- ERR_FATAL_CHECK(p, malloc);
- p->const_type = INTEGERC;
- p->const_u.intval = atoi(yytext);
- yylval->const1 = p;
+ yylval->value_const.kind = CCMMC_KIND_CONST_INT;
+ yylval->value_const.const_int = atoi(yytext);
return CONST;
}
{CONST_FLOAT} {
- CON_Type *p;
- p = malloc(sizeof(CON_Type));
- ERR_FATAL_CHECK(p, malloc);
- p->const_type = FLOATC;
- p->const_u.fval = atof(yytext);
- yylval->const1 = p;
+ yylval->value_const.kind = CCMMC_KIND_CONST_FLOAT;
+ yylval->value_const.const_float = atof(yytext);
return CONST;
}
{CONST_STRING} {
- CON_Type *p;
- p = malloc(sizeof(CON_Type));
- ERR_FATAL_CHECK(p, malloc);
- p->const_type = STRINGC;
- p->const_u.sc = strdup(yytext);
- ERR_FATAL_CHECK(p->const_u.sc, strdup);
- yylval->const1 = p;
+ size_t len = strlen(yytext);
+ yylval->value_const.kind = CCMMC_KIND_CONST_STRING;
+ yylval->value_const.const_string = strndup(yytext + 1, len - 2);
+ ERR_FATAL_CHECK(yylval->value_const.const_string, strdup);
return CONST;
}
{COMMENT} {