📄 nescobjecttreebuilder.g
字号:
configurationFile[CanonicalPath cp] returns [NesCConfigurationFile configFileObj]
{ configFileObj = null;
Configuration configObj = null;
List includeFileObjList = null;
}
: #( n:NConfigurationFile { configFileObj = new NesCConfigurationFile();
configFileObj.setDefNode(n);
ctx.addProcessedObjectTree(cp, configFileObj);
}
(includeFileObjList = includes { configFileObj.addIncludeFiles(includeFileObjList); }
)*
configObj = configuration[configFileObj]
)
;
moduleFile[CanonicalPath cp] returns [NesCModuleFile moduleFileObj]
{ moduleFileObj = null;
Module moduleObj = null;
List includeFileObjList = null;
}
: #( n:NModuleFile { moduleFileObj = new NesCModuleFile();
moduleFileObj.setDefNode(n);
ctx.addProcessedObjectTree(cp, moduleFileObj);
}
(includeFileObjList = includes { moduleFileObj.addIncludeFiles(includeFileObjList); }
)*
moduleObj = module { moduleFileObj.setModule(moduleObj); }
)
;
module returns [Module moduleObj]
{ moduleObj = null;
List portList = null;
ModuleImplementation moduleImplObj = null;
}
: #( m:NModule { moduleObj = new Module();
moduleObj.setDefNode(m);
ctx.setCurrentModule(moduleObj);
}
i:ID { moduleObj.setNameNode(i);
}
portList = interfaceDescription { moduleObj.addPortList(portList); }
moduleImplObj = moduleImplementation{ moduleObj.setImplementation(moduleImplObj); }
{
// just to make sure that noone messes around with this module any more thinking that operating on the current module
ctx.setCurrentModule(null);
}
)
;
configuration[NesCConfigurationFile configFileObj] returns [Configuration configObj]
{ configObj = null;
List portList = null;
}
: #( m:NConfiguration { configObj = new Configuration();
configObj.setDefNode(m);
configFileObj.setConfiguration(configObj);
}
i:ID { configObj.setNameNode(i);
}
portList = interfaceDescription { configObj.addPortList(portList); }
configurationImplementation[configObj]
)
;
interfaceDescription returns [List portList]
{ portList = null;
List usesPortList;
List providesPortList;
}
:#( lc:NInterfaceDescription { portList = new ArrayList(); }
(
usesPortList = uses { portList.addAll(usesPortList); }
| providesPortList = provides { portList.addAll(providesPortList); }
)*
rc:RCURLY
)
;
uses returns [List portList]
{ portList = null; }
:#( u:NUses
portList = interfaceDescriptionItemList[Port.Direction.USES]
)
;
provides returns [List portList]
{ portList = null; }
:#( p:NProvides
portList = interfaceDescriptionItemList[Port.Direction.PROVIDES]
)
;
interfaceDescriptionItemList[int direction] returns [List portList]
{ portList = new ArrayList();
Port portObj = null;
}
: portObj = interfaceDescriptionItem[direction] { portList.add(portObj); }
| ( lc:LCURLY
(portObj = interfaceDescriptionItem[direction]
{ portList.add(portObj); }
)+
rc:RCURLY
)
;
interfaceDescriptionItem[int direction] returns [Port portObj = null]
{
InterfacePort ipObj = null;
FunctionPort fpObj = null;
List decls = null;
// InterfaceAlias interfaceAliasObj = null;
Interface interfaceObj = null;
ParameterTypeList ptlObj = null;
NesCInterfaceFile interfaceFileObj = null;
}
: decls = declaration {
fpObj = new FunctionPort(ctx);
portObj = fpObj;
fpObj.setDirection(direction);
fpObj.setDeclaration((Declaration)decls.get(0));
}
|
i:"interface"
#(
id:ID {
ipObj = new InterfacePort(ctx);
portObj = ipObj;
ipObj.setDirection(direction);
ipObj.setNameNode(id);
}
("as" alias:ID {
ipObj.setNameNode(alias);
}
)?
)
{
// get the AST of the interface file
TNode interfaceFileAST = (TNode)id.getAttribute("interfaceFileAST");
String interfaceFileName = id.getText()+".nc";
ParserMessage container = new ParserMessage(ParserMessage.INFO, "OT: Interface file: "+interfaceFileName, new CodeLocation(i), null);
ctx.addMsg(container);
ctx.pushMessages(container);
NesCFile nesCFileObj = null;
try {
interfaceFileObj = (NesCInterfaceFile)ctx.getObjectTree(interfaceFileName);
interfaceObj = interfaceFileObj.getInterface();
ipObj.setInterface(interfaceObj);
} catch(ParserMessage m) {
ctx.addMsg(m);
} finally {
ctx.popMessages();
}
}
(
ptlObj = interfaceParameters { portObj.setParameterTypeList(ptlObj); }
)?
;
interfaceParameters returns [ParameterTypeList ptlObj = null]
: l:LBRACKET
ptlObj = parameterTypeList
r:RBRACKET
;
moduleImplementation returns [ModuleImplementation implObj = null]
{
List declnList = null;
Declaration declObj = null;
Scope scope = null;
}
: #( i:NImplementation { implObj = new ModuleImplementation();
implObj.setDefNode(i);
scope = new Scope("module " + ctx.getCurrentModule().getName(), ctx.getCurrentScope());
ctx.pushScope(scope);
implObj.setScope(scope);
}
lc:LCURLY
(
declnList = d:declaration { implObj.addDeclarations(declnList); }
| declObj = f:functionDef { implObj.addDeclaration(declObj); }
| asm_expr
| SEMI
| typelessDeclaration
| textNode
)+
rc:RCURLY { ctx.popScope(); }
)
;
configurationImplementation[Configuration configObj]
{
ConfigurationImplementation implObj = configObj.getImplementation();
implObj.setConfiguration(configObj);
List componentListObj = null;
List connectionListObj = null;
}
: #( i:NImplementation { implObj.setDefNode(i);
}
lc:LCURLY
(componentListObj = componentList { implObj.addComponents(componentListObj); }
)*
connectionListObj = connectionList[configObj]
{ implObj.addConnections(connectionListObj); }
rc:RCURLY
)
;
componentList returns [List componentListObj = null]
{ ComponentAlias componentAliasObj = null; }
: #( d:NComponentList { componentListObj = new ArrayList();
}
(
id:ID {
componentAliasObj = new ComponentAlias();
componentAliasObj.setDefNode(id);
String componentFileName = id.getText() + ".nc";
// TNode componentASTObj = (TNode)id.getAttribute("componentFileAST");
ParserMessage container = new ParserMessage(ParserMessage.INFO, "OT: Component file: "+componentFileName, new CodeLocation(id), null);
ctx.addMsg(container);
ctx.pushMessages(container);
NesCComponentFile componentFileObj = null;
try {
componentFileObj = (NesCComponentFile)ctx.getObjectTree(componentFileName);
componentAliasObj.setComponent(componentFileObj.getComponent());
componentListObj.add(componentAliasObj);
} catch(ParserMessage m) {
ctx.addMsg(m);
} finally {
ctx.popMessages();
}
}
("as" alias:ID { componentAliasObj.setDefNode(alias); }
)?
)+
(SEMI)+
)
;
connectionList[Configuration configObj] returns [List connectionListObj = null]
{
Connection connObj = null;
List endPoint1Obj = null;
List endPoint2Obj = null;
List params1Obj = null;
List params2Obj = null;
}
: #( NConnectionList { connectionListObj = new ArrayList(); }
( { connObj = new Connection(ctx);
connObj.setConfigurationImplementation(configObj.getImplementation());
}
endPoint1Obj = endpoint
(params1Obj = interfaceParamArgs)?
( a:ASSIGN { connObj.setDirection(Connection.Direction.EQUATE); }
| p:PTR { connObj.setDirection(Connection.Direction.FROM1TO2); }
| b:BACKPTR { connObj.setDirection(Connection.Direction.FROM2TO1); }
)
endPoint2Obj = endpoint
(params2Obj = interfaceParamArgs)?
(SEMI)+
{
connObj.setEndPoints(endPoint1Obj, params1Obj, endPoint2Obj, params2Obj);
connectionListObj.add(connObj);
}
)*
)
;
endpoint returns [List idListObj = new ArrayList()]
:
i1:ID { idListObj.add(i1); }
( DOT i2:ID { idListObj.add(i2); }
)*
;
textNode :NText
;
externalList[NesCIncludeFile includeFileObj]
{
List declListObj = null;
Declaration declObj = null;
AsmExpr asmExprObj = null;
TypelessDeclaration tldObj = null;
}
:
(
declListObj = declaration { includeFileObj.addExternal(declListObj); }
| declObj = functionDef { includeFileObj.addExternal(declObj); }
| asmExprObj = asm_expr { includeFileObj.addExternal(asmExprObj); }
| s:SEMI { includeFileObj.addExternal(s); }
| tldObj = typelessDeclaration { includeFileObj.addExternal(tldObj); }
| tn:textNode { includeFileObj.addExternal(tn); }
)+
;
typelessDeclaration returns [TypelessDeclaration tldObj = null]
:
#(
dn:NTypeMissing { tldObj = new TypelessDeclaration();
tldObj.setDefNode(dn);
}
(initDecl)+ SEMI
)
;
asm_expr returns [AsmExpr asmExprObj = null]
:
#(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -