diff --git a/decl.h b/decl.h index 2d7e662b..0bae20b8 100644 --- a/decl.h +++ b/decl.h @@ -90,7 +90,8 @@ enum StorageClass { */ class DeclSpecs { public: - DeclSpecs(const Type *t = NULL, StorageClass sc = SC_NONE, int tq = TYPEQUAL_NONE); + DeclSpecs(const Type *t = NULL, StorageClass sc = SC_NONE, + int tq = TYPEQUAL_NONE); void Print() const; @@ -117,6 +118,8 @@ public: SOA width specified. Otherwise this is zero. */ int soaWidth; + + std::vector > declSpecList; }; diff --git a/lex.ll b/lex.ll index 517d7871..4130372f 100644 --- a/lex.ll +++ b/lex.ll @@ -346,6 +346,7 @@ cwhile { RT; return TOKEN_CWHILE; } const { RT; return TOKEN_CONST; } continue { RT; return TOKEN_CONTINUE; } creturn { RT; return TOKEN_CRETURN; } +__declspec { RT; return TOKEN_DECLSPEC; } default { RT; return TOKEN_DEFAULT; } do { RT; return TOKEN_DO; } delete { RT; return TOKEN_DELETE; } diff --git a/parse.yy b/parse.yy index 7197d44c..f962d0f3 100644 --- a/parse.yy +++ b/parse.yy @@ -168,6 +168,8 @@ struct ForeachDimension { std::vector *symbolList; ForeachDimension *foreachDimension; std::vector *foreachDimensionList; + std::pair *declspecPair; + std::vector > *declspecList; } @@ -181,7 +183,7 @@ struct ForeachDimension { %token TOKEN_AND_ASSIGN TOKEN_OR_ASSIGN TOKEN_XOR_ASSIGN %token TOKEN_SIZEOF TOKEN_NEW TOKEN_DELETE -%token TOKEN_EXTERN TOKEN_EXPORT TOKEN_STATIC TOKEN_INLINE TOKEN_TASK +%token TOKEN_EXTERN TOKEN_EXPORT TOKEN_STATIC TOKEN_INLINE TOKEN_TASK TOKEN_DECLSPEC %token TOKEN_UNIFORM TOKEN_VARYING TOKEN_TYPEDEF TOKEN_SOA %token TOKEN_CHAR TOKEN_INT TOKEN_SIGNED TOKEN_UNSIGNED TOKEN_FLOAT TOKEN_DOUBLE %token TOKEN_INT8 TOKEN_INT16 TOKEN_INT64 TOKEN_CONST TOKEN_VOID TOKEN_BOOL @@ -233,13 +235,16 @@ struct ForeachDimension { %type storage_class_specifier %type declaration_specifiers -%type string_constant +%type string_constant %type struct_or_union_name enum_identifier goto_identifier %type int_constant soa_width_specifier rate_qualified_new %type foreach_dimension_specifier %type foreach_dimension_list +%type declspec_item +%type declspec_specifier declspec_list + %start translation_unit %% @@ -645,6 +650,37 @@ soa_width_specifier { $$ = $3; } ; +declspec_item + : TOKEN_IDENTIFIER + { + std::pair *p = new std::pair; + p->first = *(yylval.stringVal); + p->second = @1; + $$ = p; + } + ; + +declspec_list + : declspec_item + { + $$ = new std::vector >; + $$->push_back(*$1); + } + | declspec_list ',' declspec_item + { + if ($1 != NULL) + $1->push_back(*$3); + $$ = $1; + } + ; + +declspec_specifier + : TOKEN_DECLSPEC '(' declspec_list ')' + { + $$ = $3; + } + ; + declaration_specifiers : storage_class_specifier { @@ -664,6 +700,22 @@ declaration_specifiers } $$ = ds; } + | declspec_specifier + { + $$ = new DeclSpecs; + if ($1 != NULL) + $$->declSpecList = *$1; + } + | declspec_specifier declaration_specifiers + { + DeclSpecs *ds = (DeclSpecs *)$2; + std::vector > *declSpecList = $1; + if (ds != NULL && declSpecList != NULL) { + for (int i = 0; i < (int)declSpecList->size(); ++i) + ds->declSpecList.push_back((*declSpecList)[i]); + } + $$ = ds; + } | soa_width_specifier { DeclSpecs *ds = new DeclSpecs;