use of org.antlr.v4.codegen.model.decl.Decl in project antlr4 by antlr.
the class RuleFunction method getDeclForAltElement.
public List<Decl> getDeclForAltElement(GrammarAST t, String refLabelName, boolean needList, boolean optional) {
List<Decl> decls = new ArrayList<Decl>();
if (t.getType() == RULE_REF) {
Rule rref = factory.getGrammar().getRule(t.getText());
String ctxName = factory.getGenerator().getTarget().getRuleFunctionContextStructName(rref);
if (needList) {
if (factory.getGenerator().getTarget().supportsOverloadedMethods())
decls.add(new ContextRuleListGetterDecl(factory, refLabelName, ctxName));
decls.add(new ContextRuleListIndexedGetterDecl(factory, refLabelName, ctxName));
} else {
decls.add(new ContextRuleGetterDecl(factory, refLabelName, ctxName, optional));
}
} else {
if (needList) {
if (factory.getGenerator().getTarget().supportsOverloadedMethods())
decls.add(new ContextTokenListGetterDecl(factory, refLabelName));
decls.add(new ContextTokenListIndexedGetterDecl(factory, refLabelName));
} else {
decls.add(new ContextTokenGetterDecl(factory, refLabelName, optional));
}
}
return decls;
}
use of org.antlr.v4.codegen.model.decl.Decl in project antlr4 by antlr.
the class RuleFunction method addContextDecl.
/**
* Add decl to struct ctx for rule or alt if labeled
*/
public void addContextDecl(String altLabel, Decl d) {
CodeBlockForOuterMostAlt alt = d.getOuterMostAltCodeBlock();
// if we found code blk and might be alt label, try to add to that label ctx
if (alt != null && altLabelCtxs != null) {
// System.out.println(d.name+" lives in alt "+alt.alt.altNum);
AltLabelStructDecl altCtx = altLabelCtxs.get(altLabel);
if (altCtx != null) {
// we have an alt ctx
// System.out.println("ctx is "+ altCtx.name);
altCtx.addDecl(d);
return;
}
}
// stick in overall rule's ctx
ruleCtx.addDecl(d);
}
use of org.antlr.v4.codegen.model.decl.Decl in project antlr4 by antlr.
the class ParserFactory method wildcard.
@Override
public List<SrcOp> wildcard(GrammarAST ast, GrammarAST labelAST) {
Wildcard wild = new Wildcard(this, ast);
// TODO: dup with tokenRef
if (labelAST != null) {
String label = labelAST.getText();
Decl d = getTokenLabelDecl(label);
wild.labels.add(d);
getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d);
if (labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN) {
TokenListDecl l = getTokenListLabelDecl(label);
getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), l);
}
}
if (controller.needsImplicitLabel(ast, wild))
defineImplicitLabel(ast, wild);
AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(wild, labelAST);
return list(wild, listLabelOp);
}
use of org.antlr.v4.codegen.model.decl.Decl in project antlr4 by antlr.
the class ParserFactory method getChoiceBlock.
@Override
public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts, GrammarAST labelAST) {
int decision = ((DecisionState) blkAST.atnState).decision;
Choice c;
if (!g.tool.force_atn && AnalysisPipeline.disjoint(g.decisionLOOK.get(decision))) {
c = getLL1ChoiceBlock(blkAST, alts);
} else {
c = getComplexChoiceBlock(blkAST, alts);
}
if (labelAST != null) {
// for x=(...), define x or x_list
String label = labelAST.getText();
Decl d = getTokenLabelDecl(label);
c.label = d;
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), d);
if (labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN) {
String listLabel = gen.getTarget().getListLabel(label);
TokenListDecl l = new TokenListDecl(this, listLabel);
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), l);
}
}
return c;
}
Aggregations