From c189b2afe2fb1ba6ae887bf0ea636003e3cc2e9b Mon Sep 17 00:00:00 2001 From: Jeffrey C Johnson Date: Sun, 22 May 2016 00:36:05 -0700 Subject: [PATCH] switch sort of working --- ast_stmt.cc | 21 ++- parser.y | 10 +- test.sh | 9 +- y.output | 2 +- y.tab.c | 554 +++++++++++++++++++++++++++++++++++++++++++----------------- y.tab.h | 44 ++--- 6 files changed, 451 insertions(+), 189 deletions(-) diff --git a/ast_stmt.cc b/ast_stmt.cc index 5e8a31e..4fe06e7 100644 --- a/ast_stmt.cc +++ b/ast_stmt.cc @@ -318,6 +318,8 @@ llvm::Value * ReturnStmt::Emit(){ } //stack for both + +// TODO : DEFAULT DOESN'T WORK RIGHT AND ONLY THE FIRST STATEMENT IN A BLOCK IS USED llvm::Value * SwitchStmt::Emit(){ llvm::SwitchInst * val; @@ -330,18 +332,29 @@ llvm::Value * SwitchStmt::Emit(){ } //Emit of expression llvm::Value * exprVal=expr->Emit(); + llvm::BasicBlock* footer = llvm::BasicBlock::Create(*context, "switchFooter", func); + irgen.SetFooterBlock(footer); //create switch instruction pass in default - val=llvm::SwitchInst::Create(exprVal, blockArr[cases->NumElements()], cases->NumElements(), irgen.GetBasicBlock()); + val=llvm::SwitchInst::Create(exprVal, blockArr[cases->NumElements()-1], cases->NumElements(), irgen.GetBasicBlock()); //for each case 'addCase to switch stmt', EMIT for stmt in case, create terminator instruction for(int i=0; iNumElements();i++){ //add addCase to switch stmt //addcase to val method - val->addCase (llvm::ConstantInt::get(llvm::IntegerType::get(*context, 32), i), blockArr[i]); - cases->Nth(i)->Emit(); - irgen.GetBasicBlock()->getTerminator(); + irgen.SetBasicBlock(blockArr[i]); + llvm::Value* c = cases->Nth(i)->Emit(); + // I think this is only necessary because the parse is buggy + // and interprets "case 1: foo(); break;" as 2 cases + if(dynamic_cast(c)) + { + val->addCase (dynamic_cast(c), blockArr[i]); + } + if(!blockArr[i]->getTerminator()) { + llvm::BranchInst::Create(footer, blockArr[i]); + } } + irgen.SetBasicBlock(footer); return val; } diff --git a/parser.y b/parser.y index 91e1cd8..2cea7f2 100644 --- a/parser.y +++ b/parser.y @@ -130,7 +130,7 @@ void yyerror(const char *msg); // standard error-handling routine * ----- * All productions and actions should be placed between the start and stop * %% markers which delimit the Rules section. - + */ Program : DeclList { @1; @@ -433,12 +433,12 @@ EqualityExpr : RelationExpr { $$ = $1; } | EqualityExpr T_EQ RelationExpr { Operator *op = new Operator(yylloc, $2); - $$ = new ArithmeticExpr($1, op, $3); + $$ = new EqualityExpr($1, op, $3); } | EqualityExpr T_NE RelationExpr { Operator *op = new Operator(yylloc, $2); - $$ = new ArithmeticExpr($1, op, $3); + $$ = new EqualityExpr($1, op, $3); } ; @@ -446,7 +446,7 @@ LogicAndExpr : EqualityExpr { $$ = $1; } | LogicAndExpr T_And EqualityExpr { Operator *op = new Operator(yylloc, $2); - $$ = new ArithmeticExpr($1, op, $3); + $$ = new LogicalExpr($1, op, $3); } ; @@ -454,7 +454,7 @@ LogicOrExpr : LogicAndExpr { $$ = $1; } | LogicOrExpr T_Or LogicAndExpr { Operator *op = new Operator(yylloc, $2); - $$ = new ArithmeticExpr($1, op, $3); + $$ = new LogicalExpr($1, op, $3); } ; diff --git a/test.sh b/test.sh index 3ed5fc5..53cc4ff 100755 --- a/test.sh +++ b/test.sh @@ -3,10 +3,10 @@ set -bm trap 'if [[ $? -eq 139 ]]; then echo "segfault $testbasename!" >> $testbasename.out; fi' CHLD -if (! [ -d public_samples ]); then - echo "public_samples folder not found. Creating one for you" +if (! [ -d Checkpoint ]); then + echo "Checkpoint folder not found. Creating one for you" echo "Copy all .glsl .dat and .out test file inside this folder" - mkdir public_samples + mkdir Checkpoint exit 1 fi @@ -15,7 +15,7 @@ make echo "Compiling Done" -if cd public_samples; then +if cd Checkpoint; then cp ../glc ./ chmod +x ./gli @@ -35,6 +35,7 @@ if [ -f glc ]; then do testid=$(basename $testname) testbasename=${testid%.glsl} + echo "testing $testbasename" rm -rf "$testbasename".ll rm -rf "$testbasename".bc ./glc <$testname > $testbasename.bc diff --git a/y.output b/y.output index 3ddc147..aa92e37 100644 --- a/y.output +++ b/y.output @@ -1,4 +1,4 @@ -Terminals which are not used +Terminals unused in grammar T_Uint T_Bvec2 diff --git a/y.tab.c b/y.tab.c index ff54c9f..54f2f34 100644 --- a/y.tab.c +++ b/y.tab.c @@ -1,24 +1,23 @@ -/* A Bison parser, made by GNU Bison 2.3. */ -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* A Bison parser, made by GNU Bison 2.4.1. */ - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +/* Skeleton implementation for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -29,7 +28,7 @@ special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. - + This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ @@ -47,7 +46,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.3" +#define YYBISON_VERSION "2.4.1" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -55,11 +54,59 @@ /* Pure parsers. */ #define YYPURE 0 +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + /* Using locations. */ #define YYLSP_NEEDED 1 +/* Copy the first part of user declarations. */ + +/* Line 189 of yacc.c */ +#line 11 "parser.y" + + +/* Just like lex, the text within this first region delimited by %{ and %} + * is assumed to be C/C++ code and will be copied verbatim to the y.tab.c + * file ahead of the definitions of the yyparse() function. Add other header + * file inclusions or C++ variable declarations/prototypes that are needed + * by your code here. + */ +#include "scanner.h" // for yylex +#include "parser.h" +#include "errors.h" + +void yyerror(const char *msg); // standard error-handling routine + + + +/* Line 189 of yacc.c */ +#line 90 "y.tab.c" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + + /* Tokens. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE @@ -217,46 +264,13 @@ -/* Copy the first part of user declarations. */ -#line 11 "parser.y" - - -/* Just like lex, the text within this first region delimited by %{ and %} - * is assumed to be C/C++ code and will be copied verbatim to the y.tab.c - * file ahead of the definitions of the yyparse() function. Add other header - * file inclusions or C++ variable declarations/prototypes that are needed - * by your code here. - */ -#include "scanner.h" // for yylex -#include "parser.h" -#include "errors.h" - -void yyerror(const char *msg); // standard error-handling routine - - - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 1 -#endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 -#endif - #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE -#line 41 "parser.y" { + +/* Line 214 of yacc.c */ +#line 41 "parser.y" + int integerConstant; bool boolConstant; double floatConstant; @@ -274,13 +288,15 @@ typedef union YYSTYPE Operator *ops; Identifier *funcId; List *argList; -} -/* Line 193 of yacc.c. */ -#line 280 "y.tab.c" - YYSTYPE; + + + +/* Line 214 of yacc.c */ +#line 296 "y.tab.c" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 -# define YYSTYPE_IS_TRIVIAL 1 #endif #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED @@ -300,8 +316,8 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ -/* Line 216 of yacc.c. */ -#line 305 "y.tab.c" +/* Line 264 of yacc.c */ +#line 321 "y.tab.c" #ifdef short # undef short @@ -351,7 +367,7 @@ typedef short int yytype_int16; #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS +# if YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) @@ -376,14 +392,14 @@ typedef short int yytype_int16; #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static int -YYID (int i) +YYID (int yyi) #else static int -YYID (i) - int i; +YYID (yyi) + int yyi; #endif { - return i; + return yyi; } #endif @@ -465,9 +481,9 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss; - YYSTYPE yyvs; - YYLTYPE yyls; + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; + YYLTYPE yyls_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ @@ -502,12 +518,12 @@ union yyalloc elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack) \ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack, Stack, yysize); \ - Stack = &yyptr->Stack; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ yyptr += yynewbytes / sizeof (*yyptr); \ } \ @@ -987,7 +1003,7 @@ while (YYID (0)) we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# if YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ @@ -1103,17 +1119,20 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) #else static void -yy_stack_print (bottom, top) - yytype_int16 *bottom; - yytype_int16 *top; +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; #endif { YYFPRINTF (stderr, "Stack now"); - for (; bottom <= top; ++bottom) - YYFPRINTF (stderr, " %d", *bottom); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } YYFPRINTF (stderr, "\n"); } @@ -1148,11 +1167,11 @@ yy_reduce_print (yyvsp, yylsp, yyrule) /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { - fprintf (stderr, " $%d = ", yyi + 1); + YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) , &(yylsp[(yyi + 1) - (yynrhs)]) ); - fprintf (stderr, "\n"); + YYFPRINTF (stderr, "\n"); } } @@ -1434,10 +1453,8 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp) break; } } - /* Prevent warnings from -Wmissing-prototypes. */ - #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus int yyparse (void *YYPARSE_PARAM); @@ -1453,23 +1470,23 @@ int yyparse (); #endif /* ! YYPARSE_PARAM */ - -/* The look-ahead symbol. */ +/* The lookahead symbol. */ int yychar; -/* The semantic value of the look-ahead symbol. */ +/* The semantic value of the lookahead symbol. */ YYSTYPE yylval; +/* Location data for the lookahead symbol. */ +YYLTYPE yylloc; + /* Number of syntax errors so far. */ int yynerrs; -/* Location data for the look-ahead symbol. */ -YYLTYPE yylloc; -/*----------. -| yyparse. | -`----------*/ +/*-------------------------. +| yyparse or yypush_parse. | +`-------------------------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ @@ -1493,78 +1510,87 @@ yyparse () #endif #endif { - - int yystate; - int yyn; - int yyresult; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - /* Look-ahead token as an internal (translated) token number. */ - int yytoken = 0; -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif - /* Three stacks and their tools: - `yyss': related to states, - `yyvs': related to semantic values, - `yyls': related to locations. - Refer to the stacks thru separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss = yyssa; - yytype_int16 *yyssp; + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + `yyls': related to locations. - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - YYSTYPE *yyvsp; + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ - /* The location stack. */ - YYLTYPE yylsa[YYINITDEPTH]; - YYLTYPE *yyls = yylsa; - YYLTYPE *yylsp; - /* The locations where the error started and ended. */ - YYLTYPE yyerror_range[2]; + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + /* The location stack. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls; + YYLTYPE *yylsp; + + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[2]; - YYSIZE_T yystacksize = YYINITDEPTH; + YYSIZE_T yystacksize; + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; YYLTYPE yyloc; +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) + /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yyls = yylsa; + yystacksize = YYINITDEPTH; + YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ + yychar = YYEMPTY; /* Cause a token to be read. */ /* Initialize stack pointers. Waste one element of value and location stack so that they stay on the same level as the state stack. The wasted elements are never initialized. */ - yyssp = yyss; yyvsp = yyvs; yylsp = yyls; -#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + +#if YYLTYPE_IS_TRIVIAL /* Initialize the default location before parsing starts. */ yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 0; + yylloc.first_column = yylloc.last_column = 1; #endif goto yysetstate; @@ -1603,6 +1629,7 @@ yyparse () &yyvs1, yysize * sizeof (*yyvsp), &yyls1, yysize * sizeof (*yylsp), &yystacksize); + yyls = yyls1; yyss = yyss1; yyvs = yyvs1; @@ -1624,9 +1651,9 @@ yyparse () (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss); - YYSTACK_RELOCATE (yyvs); - YYSTACK_RELOCATE (yyls); + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); + YYSTACK_RELOCATE (yyls_alloc, yyls); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); @@ -1647,6 +1674,9 @@ yyparse () YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + if (yystate == YYFINAL) + YYACCEPT; + goto yybackup; /*-----------. @@ -1655,16 +1685,16 @@ yyparse () yybackup: /* Do appropriate processing given the current state. Read a - look-ahead token if we need one and don't already have one. */ + lookahead token if we need one and don't already have one. */ - /* First try to decide what to do without reference to look-ahead token. */ + /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; - /* Not known => get a look-ahead token if don't already have one. */ + /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); @@ -1696,20 +1726,16 @@ yybackup: goto yyreduce; } - if (yyn == YYFINAL) - YYACCEPT; - /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; - /* Shift the look-ahead token. */ + /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - /* Discard the shifted token unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; + /* Discard the shifted token. */ + yychar = YYEMPTY; yystate = yyn; *++yyvsp = yylval; @@ -1750,6 +1776,8 @@ yyreduce: switch (yyn) { case 2: + +/* Line 1455 of yacc.c */ #line 135 "parser.y" { (yylsp[(1) - (1)]); @@ -1768,36 +1796,50 @@ yyreduce: break; case 3: + +/* Line 1455 of yacc.c */ #line 151 "parser.y" { ((yyval.declList)=(yyvsp[(1) - (2)].declList))->Append((yyvsp[(2) - (2)].decl)); } break; case 4: + +/* Line 1455 of yacc.c */ #line 152 "parser.y" { ((yyval.declList) = new List)->Append((yyvsp[(1) - (1)].decl)); } break; case 5: + +/* Line 1455 of yacc.c */ #line 163 "parser.y" { (yyval.decl) = (yyvsp[(1) - (1)].decl); } break; case 6: + +/* Line 1455 of yacc.c */ #line 164 "parser.y" { (yyvsp[(1) - (2)].funcDecl)->SetFunctionBody((yyvsp[(2) - (2)].stmt)); (yyval.decl) = (yyvsp[(1) - (2)].funcDecl); } break; case 7: + +/* Line 1455 of yacc.c */ #line 175 "parser.y" { (yyval.decl) = (yyvsp[(1) - (2)].funcDecl); } break; case 8: + +/* Line 1455 of yacc.c */ #line 176 "parser.y" { (yyval.decl) = (yyvsp[(1) - (2)].varDecl); } break; case 9: + +/* Line 1455 of yacc.c */ #line 180 "parser.y" { Identifier *id = new Identifier(yylloc, (const char *)(yyvsp[(2) - (4)].identifier)); @@ -1807,6 +1849,8 @@ yyreduce: break; case 10: + +/* Line 1455 of yacc.c */ #line 186 "parser.y" { Identifier *id = new Identifier(yylloc, (const char *)(yyvsp[(2) - (5)].identifier)); @@ -1815,16 +1859,22 @@ yyreduce: break; case 11: + +/* Line 1455 of yacc.c */ #line 192 "parser.y" { ((yyval.varDeclList) = new List)->Append((yyvsp[(1) - (1)].varDecl)); } break; case 12: + +/* Line 1455 of yacc.c */ #line 193 "parser.y" { ((yyval.varDeclList) = (yyvsp[(1) - (3)].varDeclList))->Append((yyvsp[(3) - (3)].varDecl)); } break; case 13: + +/* Line 1455 of yacc.c */ #line 197 "parser.y" { Identifier *id = new Identifier(yylloc, (const char *)(yyvsp[(2) - (2)].identifier)); @@ -1833,6 +1883,8 @@ yyreduce: break; case 14: + +/* Line 1455 of yacc.c */ #line 202 "parser.y" { Identifier *id = new Identifier(yylloc, (const char *)(yyvsp[(3) - (3)].identifier)); @@ -1841,6 +1893,8 @@ yyreduce: break; case 15: + +/* Line 1455 of yacc.c */ #line 207 "parser.y" { // incomplete: drop the initializer here @@ -1850,6 +1904,8 @@ yyreduce: break; case 16: + +/* Line 1455 of yacc.c */ #line 213 "parser.y" { Identifier *id = new Identifier(yylloc, (const char *)(yyvsp[(3) - (5)].identifier)); @@ -1858,6 +1914,8 @@ yyreduce: break; case 17: + +/* Line 1455 of yacc.c */ #line 218 "parser.y" { Identifier *id = new Identifier((yylsp[(2) - (5)]), (const char *)(yyvsp[(2) - (5)].identifier)); @@ -1866,6 +1924,8 @@ yyreduce: break; case 18: + +/* Line 1455 of yacc.c */ #line 223 "parser.y" { Identifier *id = new Identifier((yylsp[(3) - (6)]), (yyvsp[(3) - (6)].identifier)); @@ -1874,116 +1934,162 @@ yyreduce: break; case 19: + +/* Line 1455 of yacc.c */ #line 230 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 20: + +/* Line 1455 of yacc.c */ #line 233 "parser.y" {(yyval.typeQualifier) = TypeQualifier::inTypeQualifier;} break; case 21: + +/* Line 1455 of yacc.c */ #line 234 "parser.y" {(yyval.typeQualifier) = TypeQualifier::outTypeQualifier;} break; case 22: + +/* Line 1455 of yacc.c */ #line 235 "parser.y" {(yyval.typeQualifier) = TypeQualifier::constTypeQualifier;} break; case 23: + +/* Line 1455 of yacc.c */ #line 236 "parser.y" {(yyval.typeQualifier) = TypeQualifier::uniformTypeQualifier;} break; case 24: + +/* Line 1455 of yacc.c */ #line 239 "parser.y" { (yyval.typeDecl) = Type::intType; } break; case 25: + +/* Line 1455 of yacc.c */ #line 240 "parser.y" { (yyval.typeDecl) = Type::voidType; } break; case 26: + +/* Line 1455 of yacc.c */ #line 241 "parser.y" { (yyval.typeDecl) = Type::floatType; } break; case 27: + +/* Line 1455 of yacc.c */ #line 242 "parser.y" { (yyval.typeDecl) = Type::boolType; } break; case 28: + +/* Line 1455 of yacc.c */ #line 243 "parser.y" { (yyval.typeDecl) = Type::vec2Type; } break; case 29: + +/* Line 1455 of yacc.c */ #line 244 "parser.y" { (yyval.typeDecl) = Type::vec3Type; } break; case 30: + +/* Line 1455 of yacc.c */ #line 245 "parser.y" { (yyval.typeDecl) = Type::vec4Type; } break; case 31: + +/* Line 1455 of yacc.c */ #line 246 "parser.y" { (yyval.typeDecl) = Type::mat2Type; } break; case 32: + +/* Line 1455 of yacc.c */ #line 247 "parser.y" { (yyval.typeDecl) = Type::mat3Type; } break; case 33: + +/* Line 1455 of yacc.c */ #line 248 "parser.y" { (yyval.typeDecl) = Type::mat4Type; } break; case 34: + +/* Line 1455 of yacc.c */ #line 251 "parser.y" { (yyval.stmt) = new StmtBlock(new List, new List); } break; case 35: + +/* Line 1455 of yacc.c */ #line 252 "parser.y" { (yyval.stmt) = new StmtBlock(new List, (yyvsp[(2) - (3)].stmtList)); } break; case 36: + +/* Line 1455 of yacc.c */ #line 255 "parser.y" { ((yyval.stmtList) = new List)->Append((yyvsp[(1) - (1)].stmt)); } break; case 37: + +/* Line 1455 of yacc.c */ #line 256 "parser.y" { ((yyval.stmtList) = (yyvsp[(1) - (2)].stmtList))->Append((yyvsp[(2) - (2)].stmt)); } break; case 38: + +/* Line 1455 of yacc.c */ #line 259 "parser.y" { (yyval.stmt) = (yyvsp[(1) - (1)].stmt); } break; case 39: + +/* Line 1455 of yacc.c */ #line 260 "parser.y" { (yyval.stmt) = (yyvsp[(1) - (1)].stmt); } break; case 40: + +/* Line 1455 of yacc.c */ #line 263 "parser.y" { (yyval.stmt) = new EmptyExpr(); } break; case 41: + +/* Line 1455 of yacc.c */ #line 265 "parser.y" { (yyval.stmt) = new DeclStmt((yyvsp[(1) - (2)].varDecl)); @@ -1991,41 +2097,57 @@ yyreduce: break; case 42: + +/* Line 1455 of yacc.c */ #line 268 "parser.y" { (yyval.stmt) = (yyvsp[(1) - (2)].expression); } break; case 43: + +/* Line 1455 of yacc.c */ #line 269 "parser.y" { (yyval.stmt) = (yyvsp[(1) - (1)].stmt); } break; case 44: + +/* Line 1455 of yacc.c */ #line 270 "parser.y" { (yyval.stmt) = (yyvsp[(1) - (1)].stmt); } break; case 45: + +/* Line 1455 of yacc.c */ #line 271 "parser.y" { (yyval.stmt) = (yyvsp[(1) - (1)].stmt); } break; case 46: + +/* Line 1455 of yacc.c */ #line 272 "parser.y" { (yyval.stmt) = (yyvsp[(1) - (1)].stmt); } break; case 47: + +/* Line 1455 of yacc.c */ #line 273 "parser.y" { (yyval.stmt) = (yyvsp[(1) - (1)].stmt); } break; case 48: + +/* Line 1455 of yacc.c */ #line 274 "parser.y" { (yyval.stmt) = (yyvsp[(1) - (1)].stmt); } break; case 49: + +/* Line 1455 of yacc.c */ #line 278 "parser.y" { (yyval.stmt) = new IfStmt((yyvsp[(3) - (7)].expression), (yyvsp[(5) - (7)].stmt), (yyvsp[(7) - (7)].stmt)); @@ -2033,6 +2155,8 @@ yyreduce: break; case 50: + +/* Line 1455 of yacc.c */ #line 282 "parser.y" { (yyval.stmt) = new IfStmt((yyvsp[(3) - (5)].expression), (yyvsp[(5) - (5)].stmt), NULL); @@ -2040,6 +2164,8 @@ yyreduce: break; case 51: + +/* Line 1455 of yacc.c */ #line 288 "parser.y" { (yyval.stmt) = new SwitchStmt((yyvsp[(3) - (7)].expression), (yyvsp[(6) - (7)].stmtList), NULL); @@ -2047,41 +2173,57 @@ yyreduce: break; case 52: + +/* Line 1455 of yacc.c */ #line 292 "parser.y" { (yyval.stmt) = new Case((yyvsp[(2) - (4)].expression), (yyvsp[(4) - (4)].stmt)); } break; case 53: + +/* Line 1455 of yacc.c */ #line 293 "parser.y" { (yyval.stmt) = new Default((yyvsp[(3) - (3)].stmt)); } break; case 54: + +/* Line 1455 of yacc.c */ #line 296 "parser.y" { (yyval.stmt) = new BreakStmt(yylloc); } break; case 55: + +/* Line 1455 of yacc.c */ #line 297 "parser.y" { (yyval.stmt) = new ContinueStmt(yylloc); } break; case 56: + +/* Line 1455 of yacc.c */ #line 298 "parser.y" { (yyval.stmt) = new ReturnStmt(yylloc); } break; case 57: + +/* Line 1455 of yacc.c */ #line 299 "parser.y" { (yyval.stmt) = new ReturnStmt(yyloc, (yyvsp[(2) - (3)].expression)); } break; case 58: + +/* Line 1455 of yacc.c */ #line 302 "parser.y" { (yyval.stmt) = new WhileStmt((yyvsp[(3) - (5)].expression), (yyvsp[(5) - (5)].stmt)); } break; case 59: + +/* Line 1455 of yacc.c */ #line 306 "parser.y" { (yyval.stmt) = new ForStmt((yyvsp[(3) - (9)].expression), (yyvsp[(5) - (9)].expression), (yyvsp[(7) - (9)].expression), (yyvsp[(9) - (9)].stmt)); @@ -2089,6 +2231,8 @@ yyreduce: break; case 60: + +/* Line 1455 of yacc.c */ #line 311 "parser.y" { Identifier *id = new Identifier(yylloc, (const char*)(yyvsp[(1) - (1)].identifier)); (yyval.expression) = new VarExpr(yyloc, id); @@ -2096,82 +2240,114 @@ yyreduce: break; case 61: + +/* Line 1455 of yacc.c */ #line 314 "parser.y" { (yyval.expression) = new IntConstant(yylloc, (yyvsp[(1) - (1)].integerConstant)); } break; case 62: + +/* Line 1455 of yacc.c */ #line 315 "parser.y" { (yyval.expression) = new FloatConstant(yylloc, (yyvsp[(1) - (1)].floatConstant)); } break; case 63: + +/* Line 1455 of yacc.c */ #line 316 "parser.y" { (yyval.expression) = new BoolConstant(yylloc, (yyvsp[(1) - (1)].boolConstant)); } break; case 64: + +/* Line 1455 of yacc.c */ #line 317 "parser.y" { (yyval.expression) = (yyvsp[(2) - (3)].expression);} break; case 65: + +/* Line 1455 of yacc.c */ #line 320 "parser.y" { (yyval.expression) = (yyvsp[(1) - (2)].expression); } break; case 66: + +/* Line 1455 of yacc.c */ #line 321 "parser.y" { (yyval.expression) = (yyvsp[(1) - (2)].expression); } break; case 67: + +/* Line 1455 of yacc.c */ #line 324 "parser.y" { (yyval.expression) = new Call((yylsp[(1) - (3)]), NULL, (yyvsp[(1) - (3)].funcId), new List); } break; case 68: + +/* Line 1455 of yacc.c */ #line 325 "parser.y" { (yyval.expression) = new Call((yylsp[(1) - (2)]), NULL, (yyvsp[(1) - (2)].funcId), new List); } break; case 69: + +/* Line 1455 of yacc.c */ #line 328 "parser.y" { (yyval.expression) = new Call((yylsp[(1) - (3)]), NULL, (yyvsp[(1) - (3)].funcId), (yyvsp[(3) - (3)].argList));} break; case 70: + +/* Line 1455 of yacc.c */ #line 331 "parser.y" { ((yyval.argList) = new List)->Append((yyvsp[(1) - (1)].expression));} break; case 71: + +/* Line 1455 of yacc.c */ #line 332 "parser.y" { ((yyval.argList) = (yyvsp[(1) - (3)].argList))->Append((yyvsp[(3) - (3)].expression));} break; case 72: + +/* Line 1455 of yacc.c */ #line 335 "parser.y" { (yyval.funcId) = new Identifier((yylsp[(1) - (1)]), (yyvsp[(1) - (1)].identifier)); } break; case 73: + +/* Line 1455 of yacc.c */ #line 338 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 74: + +/* Line 1455 of yacc.c */ #line 339 "parser.y" { (yyval.expression) = new ArrayAccess((yylsp[(1) - (4)]), (yyvsp[(1) - (4)].expression), (yyvsp[(3) - (4)].expression)); } break; case 75: + +/* Line 1455 of yacc.c */ #line 341 "parser.y" { } break; case 76: + +/* Line 1455 of yacc.c */ #line 344 "parser.y" { Operator *op = new Operator(yylloc, (const char *)(yyvsp[(2) - (2)].identifier)); @@ -2180,6 +2356,8 @@ yyreduce: break; case 77: + +/* Line 1455 of yacc.c */ #line 349 "parser.y" { Operator *op = new Operator(yylloc, (const char *)(yyvsp[(2) - (2)].identifier)); @@ -2188,6 +2366,8 @@ yyreduce: break; case 78: + +/* Line 1455 of yacc.c */ #line 354 "parser.y" { Identifier *id = new Identifier(yylloc, (const char *)(yyvsp[(3) - (3)].identifier)); @@ -2196,11 +2376,15 @@ yyreduce: break; case 79: + +/* Line 1455 of yacc.c */ #line 360 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 80: + +/* Line 1455 of yacc.c */ #line 362 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(1) - (2)].identifier)); @@ -2209,6 +2393,8 @@ yyreduce: break; case 81: + +/* Line 1455 of yacc.c */ #line 367 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(1) - (2)].identifier)); @@ -2217,6 +2403,8 @@ yyreduce: break; case 82: + +/* Line 1455 of yacc.c */ #line 372 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(1) - (2)].identifier)); @@ -2225,6 +2413,8 @@ yyreduce: break; case 83: + +/* Line 1455 of yacc.c */ #line 377 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(1) - (2)].identifier)); @@ -2233,11 +2423,15 @@ yyreduce: break; case 84: + +/* Line 1455 of yacc.c */ #line 383 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 85: + +/* Line 1455 of yacc.c */ #line 385 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); @@ -2246,6 +2440,8 @@ yyreduce: break; case 86: + +/* Line 1455 of yacc.c */ #line 390 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); @@ -2254,11 +2450,15 @@ yyreduce: break; case 87: + +/* Line 1455 of yacc.c */ #line 396 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 88: + +/* Line 1455 of yacc.c */ #line 398 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); @@ -2267,6 +2467,8 @@ yyreduce: break; case 89: + +/* Line 1455 of yacc.c */ #line 403 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); @@ -2275,11 +2477,15 @@ yyreduce: break; case 90: + +/* Line 1455 of yacc.c */ #line 409 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 91: + +/* Line 1455 of yacc.c */ #line 411 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); @@ -2288,6 +2494,8 @@ yyreduce: break; case 92: + +/* Line 1455 of yacc.c */ #line 416 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); @@ -2296,6 +2504,8 @@ yyreduce: break; case 93: + +/* Line 1455 of yacc.c */ #line 421 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); @@ -2304,6 +2514,8 @@ yyreduce: break; case 94: + +/* Line 1455 of yacc.c */ #line 426 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); @@ -2312,58 +2524,76 @@ yyreduce: break; case 95: + +/* Line 1455 of yacc.c */ #line 432 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 96: + +/* Line 1455 of yacc.c */ #line 434 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); - (yyval.expression) = new ArithmeticExpr((yyvsp[(1) - (3)].expression), op, (yyvsp[(3) - (3)].expression)); + (yyval.expression) = new EqualityExpr((yyvsp[(1) - (3)].expression), op, (yyvsp[(3) - (3)].expression)); } break; case 97: + +/* Line 1455 of yacc.c */ #line 439 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); - (yyval.expression) = new ArithmeticExpr((yyvsp[(1) - (3)].expression), op, (yyvsp[(3) - (3)].expression)); + (yyval.expression) = new EqualityExpr((yyvsp[(1) - (3)].expression), op, (yyvsp[(3) - (3)].expression)); } break; case 98: + +/* Line 1455 of yacc.c */ #line 445 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 99: + +/* Line 1455 of yacc.c */ #line 447 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); - (yyval.expression) = new ArithmeticExpr((yyvsp[(1) - (3)].expression), op, (yyvsp[(3) - (3)].expression)); + (yyval.expression) = new LogicalExpr((yyvsp[(1) - (3)].expression), op, (yyvsp[(3) - (3)].expression)); } break; case 100: + +/* Line 1455 of yacc.c */ #line 453 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 101: + +/* Line 1455 of yacc.c */ #line 455 "parser.y" { Operator *op = new Operator(yylloc, (yyvsp[(2) - (3)].identifier)); - (yyval.expression) = new ArithmeticExpr((yyvsp[(1) - (3)].expression), op, (yyvsp[(3) - (3)].expression)); + (yyval.expression) = new LogicalExpr((yyvsp[(1) - (3)].expression), op, (yyvsp[(3) - (3)].expression)); } break; case 102: + +/* Line 1455 of yacc.c */ #line 461 "parser.y" { (yyval.expression) = (yyvsp[(1) - (1)].expression); } break; case 103: + +/* Line 1455 of yacc.c */ #line 463 "parser.y" { (yyval.expression) = new ConditionalExpr((yyvsp[(1) - (5)].expression), (yyvsp[(3) - (5)].expression), (yyvsp[(5) - (5)].expression)); @@ -2371,6 +2601,8 @@ yyreduce: break; case 104: + +/* Line 1455 of yacc.c */ #line 467 "parser.y" { (yyval.expression) = new AssignExpr((yyvsp[(1) - (3)].expression), (yyvsp[(2) - (3)].ops), (yyvsp[(3) - (3)].expression)); @@ -2378,33 +2610,44 @@ yyreduce: break; case 105: + +/* Line 1455 of yacc.c */ #line 472 "parser.y" { (yyval.ops) = new Operator(yylloc, (yyvsp[(1) - (1)].identifier)); } break; case 106: + +/* Line 1455 of yacc.c */ #line 473 "parser.y" { (yyval.ops) = new Operator(yylloc, "+="); } break; case 107: + +/* Line 1455 of yacc.c */ #line 474 "parser.y" { (yyval.ops) = new Operator(yylloc, "-="); } break; case 108: + +/* Line 1455 of yacc.c */ #line 475 "parser.y" { (yyval.ops) = new Operator(yylloc, "*="); } break; case 109: + +/* Line 1455 of yacc.c */ #line 476 "parser.y" { (yyval.ops) = new Operator(yylloc, "/="); } break; -/* Line 1267 of yacc.c. */ -#line 2408 "y.tab.c" + +/* Line 1455 of yacc.c */ +#line 2651 "y.tab.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2480,7 +2723,7 @@ yyerrlab: if (yyerrstatus == 3) { - /* If just tried and failed to reuse look-ahead token after an + /* If just tried and failed to reuse lookahead token after an error, discard it. */ if (yychar <= YYEOF) @@ -2497,7 +2740,7 @@ yyerrlab: } } - /* Else will try to reuse look-ahead token after shifting the error + /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; @@ -2555,14 +2798,11 @@ yyerrlab1: YY_STACK_PRINT (yyss, yyssp); } - if (yyn == YYFINAL) - YYACCEPT; - *++yyvsp = yylval; yyerror_range[1] = yylloc; /* Using YYLLOC is tempting, but would change the location of - the look-ahead. YYLOC is available though. */ + the lookahead. YYLOC is available though. */ YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); *++yylsp = yyloc; @@ -2587,7 +2827,7 @@ yyabortlab: yyresult = 1; goto yyreturn; -#ifndef yyoverflow +#if !defined(yyoverflow) || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -2598,7 +2838,7 @@ yyexhaustedlab: #endif yyreturn: - if (yychar != YYEOF && yychar != YYEMPTY) + if (yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc); /* Do not reclaim the symbols of the rule which action triggered @@ -2624,6 +2864,8 @@ yyreturn: } + +/* Line 1675 of yacc.c */ #line 479 "parser.y" diff --git a/y.tab.h b/y.tab.h index 5c801c4..1c9897b 100644 --- a/y.tab.h +++ b/y.tab.h @@ -1,24 +1,23 @@ -/* A Bison parser, made by GNU Bison 2.3. */ -/* Skeleton interface for Bison's Yacc-like parsers in C +/* A Bison parser, made by GNU Bison 2.4.1. */ - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -29,10 +28,11 @@ special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. - + This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ + /* Tokens. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE @@ -192,8 +192,11 @@ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE -#line 41 "parser.y" { + +/* Line 1676 of yacc.c */ +#line 41 "parser.y" + int integerConstant; bool boolConstant; double floatConstant; @@ -211,13 +214,15 @@ typedef union YYSTYPE Operator *ops; Identifier *funcId; List *argList; -} -/* Line 1529 of yacc.c. */ -#line 217 "y.tab.h" - YYSTYPE; + + + +/* Line 1676 of yacc.c */ +#line 222 "y.tab.h" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 -# define YYSTYPE_IS_TRIVIAL 1 #endif extern YYSTYPE yylval; @@ -236,3 +241,4 @@ typedef struct YYLTYPE #endif extern YYLTYPE yylloc; + -- 1.9.1