Add ability to parse __declspec lists to parser.
This commit is contained in:
5
decl.h
5
decl.h
@@ -90,7 +90,8 @@ enum StorageClass {
|
|||||||
*/
|
*/
|
||||||
class DeclSpecs {
|
class DeclSpecs {
|
||||||
public:
|
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;
|
void Print() const;
|
||||||
|
|
||||||
@@ -117,6 +118,8 @@ public:
|
|||||||
SOA width specified. Otherwise this is zero.
|
SOA width specified. Otherwise this is zero.
|
||||||
*/
|
*/
|
||||||
int soaWidth;
|
int soaWidth;
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, SourcePos> > declSpecList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1
lex.ll
1
lex.ll
@@ -346,6 +346,7 @@ cwhile { RT; return TOKEN_CWHILE; }
|
|||||||
const { RT; return TOKEN_CONST; }
|
const { RT; return TOKEN_CONST; }
|
||||||
continue { RT; return TOKEN_CONTINUE; }
|
continue { RT; return TOKEN_CONTINUE; }
|
||||||
creturn { RT; return TOKEN_CRETURN; }
|
creturn { RT; return TOKEN_CRETURN; }
|
||||||
|
__declspec { RT; return TOKEN_DECLSPEC; }
|
||||||
default { RT; return TOKEN_DEFAULT; }
|
default { RT; return TOKEN_DEFAULT; }
|
||||||
do { RT; return TOKEN_DO; }
|
do { RT; return TOKEN_DO; }
|
||||||
delete { RT; return TOKEN_DELETE; }
|
delete { RT; return TOKEN_DELETE; }
|
||||||
|
|||||||
56
parse.yy
56
parse.yy
@@ -168,6 +168,8 @@ struct ForeachDimension {
|
|||||||
std::vector<Symbol *> *symbolList;
|
std::vector<Symbol *> *symbolList;
|
||||||
ForeachDimension *foreachDimension;
|
ForeachDimension *foreachDimension;
|
||||||
std::vector<ForeachDimension *> *foreachDimensionList;
|
std::vector<ForeachDimension *> *foreachDimensionList;
|
||||||
|
std::pair<std::string, SourcePos> *declspecPair;
|
||||||
|
std::vector<std::pair<std::string, SourcePos> > *declspecList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -181,7 +183,7 @@ struct ForeachDimension {
|
|||||||
%token TOKEN_AND_ASSIGN TOKEN_OR_ASSIGN TOKEN_XOR_ASSIGN
|
%token TOKEN_AND_ASSIGN TOKEN_OR_ASSIGN TOKEN_XOR_ASSIGN
|
||||||
%token TOKEN_SIZEOF TOKEN_NEW TOKEN_DELETE
|
%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_UNIFORM TOKEN_VARYING TOKEN_TYPEDEF TOKEN_SOA
|
||||||
%token TOKEN_CHAR TOKEN_INT TOKEN_SIGNED TOKEN_UNSIGNED TOKEN_FLOAT TOKEN_DOUBLE
|
%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
|
%token TOKEN_INT8 TOKEN_INT16 TOKEN_INT64 TOKEN_CONST TOKEN_VOID TOKEN_BOOL
|
||||||
@@ -233,13 +235,16 @@ struct ForeachDimension {
|
|||||||
%type <storageClass> storage_class_specifier
|
%type <storageClass> storage_class_specifier
|
||||||
%type <declSpecs> declaration_specifiers
|
%type <declSpecs> declaration_specifiers
|
||||||
|
|
||||||
%type <stringVal> string_constant
|
%type <stringVal> string_constant
|
||||||
%type <constCharPtr> struct_or_union_name enum_identifier goto_identifier
|
%type <constCharPtr> struct_or_union_name enum_identifier goto_identifier
|
||||||
%type <intVal> int_constant soa_width_specifier rate_qualified_new
|
%type <intVal> int_constant soa_width_specifier rate_qualified_new
|
||||||
|
|
||||||
%type <foreachDimension> foreach_dimension_specifier
|
%type <foreachDimension> foreach_dimension_specifier
|
||||||
%type <foreachDimensionList> foreach_dimension_list
|
%type <foreachDimensionList> foreach_dimension_list
|
||||||
|
|
||||||
|
%type <declspecPair> declspec_item
|
||||||
|
%type <declspecList> declspec_specifier declspec_list
|
||||||
|
|
||||||
%start translation_unit
|
%start translation_unit
|
||||||
%%
|
%%
|
||||||
|
|
||||||
@@ -645,6 +650,37 @@ soa_width_specifier
|
|||||||
{ $$ = $3; }
|
{ $$ = $3; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
declspec_item
|
||||||
|
: TOKEN_IDENTIFIER
|
||||||
|
{
|
||||||
|
std::pair<std::string, SourcePos> *p = new std::pair<std::string, SourcePos>;
|
||||||
|
p->first = *(yylval.stringVal);
|
||||||
|
p->second = @1;
|
||||||
|
$$ = p;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
declspec_list
|
||||||
|
: declspec_item
|
||||||
|
{
|
||||||
|
$$ = new std::vector<std::pair<std::string, SourcePos> >;
|
||||||
|
$$->push_back(*$1);
|
||||||
|
}
|
||||||
|
| declspec_list ',' declspec_item
|
||||||
|
{
|
||||||
|
if ($1 != NULL)
|
||||||
|
$1->push_back(*$3);
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
declspec_specifier
|
||||||
|
: TOKEN_DECLSPEC '(' declspec_list ')'
|
||||||
|
{
|
||||||
|
$$ = $3;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
declaration_specifiers
|
declaration_specifiers
|
||||||
: storage_class_specifier
|
: storage_class_specifier
|
||||||
{
|
{
|
||||||
@@ -664,6 +700,22 @@ declaration_specifiers
|
|||||||
}
|
}
|
||||||
$$ = ds;
|
$$ = ds;
|
||||||
}
|
}
|
||||||
|
| declspec_specifier
|
||||||
|
{
|
||||||
|
$$ = new DeclSpecs;
|
||||||
|
if ($1 != NULL)
|
||||||
|
$$->declSpecList = *$1;
|
||||||
|
}
|
||||||
|
| declspec_specifier declaration_specifiers
|
||||||
|
{
|
||||||
|
DeclSpecs *ds = (DeclSpecs *)$2;
|
||||||
|
std::vector<std::pair<std::string, SourcePos> > *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
|
| soa_width_specifier
|
||||||
{
|
{
|
||||||
DeclSpecs *ds = new DeclSpecs;
|
DeclSpecs *ds = new DeclSpecs;
|
||||||
|
|||||||
Reference in New Issue
Block a user