📄 nescobjecttreebuilder.g
字号:
dn:"asm" { asmExprObj = new AsmExpr();
asmExprObj.setDefNode(dn);
}
( "volatile" )? LCURLY expr RCURLY ( SEMI )+
)
;
declaration returns [List declnList]
{ declnList = new ArrayList();
Declaration tmpDeclnObj = null;
Declaration declnObj = null;
StorageClassSpecifier scsObj = null;
TypeQualifier tqObj = null;
TypeSpecifier tsObj = null;
Declarator declrObj = null;
TypeBuilder tmpBuilderObj = null;
TypeBuilder builderObj = null;
Attribute attrObj = null;
}
:#( dn:NDeclaration {
tmpDeclnObj = new Declaration();
tmpDeclnObj.setDefNode(dn);
tmpBuilderObj = new TypeBuilder();
}
( scsObj = storageClassSpecifier { tmpDeclnObj.addStorageClassSpecifier(scsObj); }
| tqObj = typeQualifier { tmpBuilderObj.addTypeQualifier(tqObj); }
| tsObj = typeSpecifier {
//try {
tmpBuilderObj.addTypeSpecifier(tsObj);
//} catch (TypeResolutionException ex) {
// ctx.addError(new Error(ex, ex.getMessage(), new CodeLocation(tsObj.getDefNode())));
//}
}
)+
(
( SEMI )+ { // it seems we have a declaration without any declarators
// add the declaration to the list as it is
tmpDeclnObj.setType(tmpBuilderObj.getType());
declnList.add(tmpDeclnObj);
}
|
(
#( i:NInitDecl
declrObj = declarator { // make a copy of the temp declaration object
declnObj = (Declaration)tmpDeclnObj.clone();
builderObj = (TypeBuilder)tmpBuilderObj.clone();
try {
builderObj.addDeclarator(declrObj);
if(builderObj.getDeclarator() instanceof Declarator) {
Declarator namedDeclObj = (Declarator)builderObj.getDeclarator();
declnObj.setNameNode(namedDeclObj.getNameNode());
}
declnObj.setType(builderObj.getType());
} catch (TypeResolutionException ex) {
ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(declrObj.getDefNode()), ex));
}
}
( attrObj = attributeDecl
{ declnObj.addAttribute(attrObj); }
)*
( ASSIGN iv:initializer
{ declnObj.setInitializer(iv); }
| COLON expr
)?
)
{ if(declnObj.getType() instanceof FunctionType && declnObj.getName()!=null) {
declnObj = new FunctionDeclaration(declnObj);
}
declnObj.addToScope(ctx);
declnList.add(declnObj);
}
)+ ( SEMI )+
)
)
;
declSpecifiers :( storageClassSpecifier
| typeQualifier
| typeSpecifier
)+
;
storageClassSpecifier returns [StorageClassSpecifier scsObj]
{ scsObj = new StorageClassSpecifier(); }
: a:"auto" { scsObj.setDefNode(a); }
| b:"register" { scsObj.setDefNode(b); }
| c:"typedef" { scsObj.setDefNode(c); }
| d:"norace" { scsObj.setDefNode(d); }
| scsObj = functionStorageClassSpecifier
;
functionStorageClassSpecifier returns [StorageClassSpecifier scsObj]
{ scsObj = new StorageClassSpecifier(); }
: a:"extern" { scsObj.setDefNode(a); }
| b:"static" { scsObj.setDefNode(b); }
| c:"inline" { scsObj.setDefNode(c); }
| e:"default" { scsObj.setDefNode(e); }
| h:"task" { scsObj.setDefNode(h); }
| scsObj = directionSpecifier
| scsObj = synchronySpecifier
;
synchronySpecifier returns [SynchronySpecifier ssObj]
{ ssObj = new SynchronySpecifier(); }
: d:"async" { ssObj.setDefNode(d); }
;
directionSpecifier returns [DirectionSpecifier dsObj]
{ dsObj = new DirectionSpecifier(); }
: f:"command" { dsObj.setDefNode(f); }
| g:"event" { dsObj.setDefNode(g); }
;
typeQualifier returns [TypeQualifier tqObj]
{ tqObj = new TypeQualifier(); }
: a:"const" { tqObj.setDefNode(a); }
| b:"volatile" { tqObj.setDefNode(b); }
;
typeSpecifier returns [TypeSpecifier tsObj]
{
tsObj = new TypeSpecifier(ctx);
Attribute attrObj = null;
}
: a:"void" { tsObj.setDefNode(a);
tsObj.setSpecifierNameNode(a);
}
| b:"char" { tsObj.setDefNode(b);
tsObj.setSpecifierNameNode(b);
}
| c:"short" { tsObj.setDefNode(c);
tsObj.setSpecifierNameNode(c);
}
| d:"int" { tsObj.setDefNode(d);
tsObj.setSpecifierNameNode(d);
}
| e:"long" { tsObj.setDefNode(e);
tsObj.setSpecifierNameNode(e);
}
| f:"float" { tsObj.setDefNode(f);
tsObj.setSpecifierNameNode(f);
}
| g:"double" { tsObj.setDefNode(g);
tsObj.setSpecifierNameNode(g);
}
| h:"signed" { tsObj.setDefNode(h);
tsObj.setSpecifierNameNode(h);
}
| i:"unsigned" { tsObj.setDefNode(i);
tsObj.setSpecifierNameNode(i);
}
| j:"__complex" { tsObj.setDefNode(j);
tsObj.setSpecifierNameNode(j);
}
| tsObj = structOrUnionSpecifier
( attrObj = attributeDecl { ((StructOrUnionSpecifier)tsObj).addAttribute(attrObj); }
)*
| tsObj = enumSpecifier
| tsObj = typedefName
| #("typeof" LPAREN { // FIXME: implement this
}
( (typeName )=> typeName
| expr
)
RPAREN
)
;
typedefName returns [ TypedefName tdnObj ] { tdnObj = null; }
:#(n:NTypedefName id:ID { tdnObj = new TypedefName(ctx);
tdnObj.setDefNode(n);
tdnObj.setSpecifierNameNode(id);
}
)
;
structOrUnionSpecifierBody[StructOrUnionSpecifier susObj]
{ List sdlObj = null; }
:
(label:ID { susObj.setSpecifierNameNode(label);
}
)?
(
lc:LCURLY
( sdlObj = structDeclarationList { susObj.addDeclarations(sdlObj); }
)?
RCURLY
)?
;
structOrUnionSpecifier returns [StructOrUnionSpecifier susObj]
{ susObj = null; }
:
#( s:"struct" { susObj = new StructSpecifier(ctx);
susObj.setDefNode(s);
}
structOrUnionSpecifierBody[susObj] )
|
#(u:"union" { susObj = new UnionSpecifier(ctx);
susObj.setDefNode(u);
}
structOrUnionSpecifierBody[susObj] )
;
structDeclarationList returns [List sdlObj = new ArrayList()]
:( sd:structDeclaration { sdlObj.add(sd); }
)+
;
structDeclaration :specifierQualifierList structDeclaratorList
;
specifierQualifierList :(
typeSpecifier
| typeQualifier
)+
;
structDeclaratorList :( structDeclarator )+
;
structDeclarator :#( NStructDeclarator
( declarator )?
( COLON expr )?
( attributeDecl )*
)
;
enumSpecifier returns [EnumSpecifier esObj] { esObj = new EnumSpecifier(ctx);
Expression exprObj = null;
Attribute attrObj = null;
}
:#( en: "enum" { esObj.setDefNode(en); }
( enid: ID { esObj.setSpecifierNameNode(enid);
}
)?
( LCURLY
(
er:ID
( ASSIGN exprObj = ae:expr )?
{
Enumerator eObj = new Enumerator();
eObj.setDefNode(er);
eObj.setNameNode(er);
eObj.setExpression(exprObj);
esObj.addEnumerator(eObj);
}
)+
RCURLY )?
( attrObj = attributeDecl { esObj.addAttribute(attrObj); }
)* { // esObj.buildType(ctx);
}
)
;
attributeDecl returns [Attribute attrObj = null]
:
#( dn1:"__attribute" {
attrObj = new Attribute();
attrObj.setDefNode(dn1);
}
(.)* )
| #( dn2:NAsmAttribute {
attrObj = new Attribute();
attrObj.setDefNode(dn2);
}
LPAREN expr RPAREN )
;
initDecl
:#( i:NInitDecl
d:declarator
( attributeDecl )*
( ASSIGN iv:initializer
| COLON expr
)?
)
;
pointerGroup returns [PointerGroup pgObj]
{ TypeQualifier tqObj = null;
pgObj = null;
}
: #( NPointerGroup { pgObj = new PointerGroup(); }
( STAR { pgObj.addStar(); }
( tqObj = typeQualifier { pgObj.addTypeQualifier(tqObj); }
)*
)+
)
;
idList :ID ( COMMA ID )*
;
initializer :#( NInitializer (initializerElementLabel)? expr )
| lcurlyInitializer
;
initializerElementLabel :#( NInitializerElementLabel
(
( LBRACKET expr RBRACKET (ASSIGN)? )
| ID COLON
| DOT ID ASSIGN
)
)
;
lcurlyInitializer :#( NLcurlyInitializer
initializerList
RCURLY
)
;
initializerList :( initializer )*
;
declarator returns [Declarator declObj]
{ declObj = null;
PointerGroup pgObj = null;
Declarator childDeclObj = null;
ParameterTypeList ptlObj = null;
ArrayConstructor acObj = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -