/** * Validates boolean value. * * @param booleanValue value to be validated * @param yangConstruct yang construct for creating error message * @param ctx context object of the grammar rule * @return boolean value either true or false */ public static boolean getValidBooleanValue(String booleanValue, YangConstructType yangConstruct, ParserRuleContext ctx) { String value = removeQuotesAndHandleConcat(booleanValue); if (value.equals(TRUE)) { return true; } else if (value.equals(FALSE)) { return false; } else { ParserException parserException = new ParserException("YANG file error : " + YangConstructType.getYangConstructType(yangConstruct) + " value " + value + " is not " + "valid."); parserException.setLine(ctx.getStart().getLine()); parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); throw parserException; } }
public DefUseVisitor(int iter, JavaClass[] classInfos, DataDependenceGraph ddg, Map<ParserRuleContext, Object> pdNodes) { Logger.log("FILE IS: " + currentFile); this.ddg = ddg; changed = false; iteration = iter; analysisVisit = false; this.pdNodes = pdNodes; this.classInfos = classInfos; defList = new LinkedHashSet<>(); useList = new LinkedHashSet<>(); selfFlowList = new LinkedHashSet<>(); activeClasses = new ArrayDeque<>(); methodDefInfo = null; methodParams = new JavaField[0]; localVars = new ArrayList<>(); }
public IfLet(ParserRuleContext ctx, Visitor visitor) { SwiftParser.Condition_clauseContext conditionClause = ctx instanceof SwiftParser.If_statementContext ? ((SwiftParser.If_statementContext)ctx).condition_clause() : ((SwiftParser.Guard_statementContext)ctx).condition_clause(); if(!(WalkerUtil.isDirectDescendant(SwiftParser.Optional_binding_conditionContext.class, conditionClause))) return; ArrayList<ParserRuleContext> ifLets = new ArrayList<ParserRuleContext>(); ifLets.add(conditionClause.condition_list().condition(0).optional_binding_condition().optional_binding_head()); if(conditionClause.condition_list().condition(0).optional_binding_condition().optional_binding_continuation_list() != null) { List<SwiftParser.Optional_binding_continuationContext> moreIfLets = conditionClause.condition_list().condition(0).optional_binding_condition().optional_binding_continuation_list().optional_binding_continuation(); for(int i = 0; i < moreIfLets.size(); i++) ifLets.add(moreIfLets.get(i)); } /*for(int i = 0; i < ifLets.size(); i++) { String varName = visitor.visitWithoutTerminals(ifLets.get(i) instanceof SwiftParser.Optional_binding_headContext ? ((SwiftParser.Optional_binding_headContext)ifLets.get(i)).pattern() : ((SwiftParser.Optional_binding_continuationContext)ifLets.get(i)).pattern()).trim(); Expression varVal = new Expression((ifLets.get(i) instanceof SwiftParser.Optional_binding_headContext ? ((SwiftParser.Optional_binding_headContext)ifLets.get(i)).initializer() : ((SwiftParser.Optional_binding_continuationContext)ifLets.get(i)).initializer()).expression(), null, visitor); varNames.add(varName); varVals.add(varVal.code); varTypes.add(varVal.type); }*/ }
/** * Test of equals method, of class TreeNode. * * @throws java.io.IOException */ @Test public void testEquals() throws IOException { Object object = null; TreeNode instance = new TreeNode(new ParserRuleContext()); boolean expResult = false; boolean result = instance.equals(object); assertEquals("equals method, of class TreeNode's expected result is wrong.", expResult, result); object = new Object(); expResult = false; result = instance.equals(object); assertEquals("equals method, of class TreeNode's expected result is wrong.", expResult, result); ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource(SAMPLE_CLASS_PATH).getFile()); byte[] encoded = Files.readAllBytes(Paths.get(file.getAbsolutePath())); String code = new String(encoded, Charset.defaultCharset()); Forest forest1 = TreeViewGenerator.generate(code); Forest forest2 = TreeViewGenerator.generate(code); expResult = true; object = forest1.getTree(0).getRoot(); instance = forest2.getTree(0).getRoot(); result = instance.equals(object); assertEquals("equals method, of class TreeNode's expected result is wrong.", expResult, result); }
public Location(ParserRuleContext parserRuleContext) { Token start = parserRuleContext.getStart(); this.start = start.getStartIndex(); Token stop = parserRuleContext.getStop(); end = stop.getStopIndex(); line = start.getLine(); }
private void replaceLabelAddress(ParserRuleContext ctx, TerminalNode terminalNode) { if(!secondPass) { return; } String label = terminalNode.getText(); if(!definedBranches.containsKey(label)) { throw new LabelError("\"" + label + "\" is not defined."); } int lineNumber = ctx.start.getLine() - 1; String temp = new String(code[lineNumber]); String address = Integer.toString(definedBranches.get(label)); temp = temp.replace(label, address); code[lineNumber] = temp; }
public static Long calculateLiteralValue( String calculation, Map<String, Long> inputs) { try { ParserRuleContext tree = parseTypeCalculation(calculation); CalculateTypeVisitor visitor = new CalculateTypeVisitor(inputs); BigInteger result = visitor.visit(tree); return result.longValueExact(); } catch (StackOverflowError e) { throw new ParsingException("Type calculation is too large (stack overflow while parsing)"); } }
private <T> List<T> visit(List<? extends ParserRuleContext> contexts, Class<T> clazz) { return contexts.stream() .map(this::visit) .map(clazz::cast) .collect(toList()); }
public ControlFlowVisitor(ControlFlowGraph cfg, String propKey, Map<ParserRuleContext, Object> ctxProps) { preNodes = new ArrayDeque<>(); preEdges = new ArrayDeque<>(); loopBlocks = new ArrayDeque<>(); labeledBlocks = new ArrayList<>(); tryBlocks = new ArrayDeque<>(); casesQueue = new ArrayDeque<>(); classNames = new ArrayDeque<>(); dontPop = false; this.cfg = cfg; // this.propKey = propKey; contexutalProperties = ctxProps; }
private static ParserRuleContext parseTypeCalculation(String calculation) { TypeCalculationLexer lexer = new TypeCalculationLexer(new CaseInsensitiveStream(new ANTLRInputStream(calculation))); CommonTokenStream tokenStream = new CommonTokenStream(lexer); TypeCalculationParser parser = new TypeCalculationParser(tokenStream); lexer.removeErrorListeners(); lexer.addErrorListener(ERROR_LISTENER); parser.removeErrorListeners(); parser.addErrorListener(ERROR_LISTENER); ParserRuleContext tree; try { // first, try parsing with potentially faster SLL mode parser.getInterpreter().setPredictionMode(PredictionMode.SLL); tree = parser.typeCalculation(); } catch (ParseCancellationException ex) { // if we fail, parse with LL mode tokenStream.reset(); // rewind input stream parser.reset(); parser.getInterpreter().setPredictionMode(PredictionMode.LL); tree = parser.typeCalculation(); } return tree; }
/** * Get the original program text for the given parser-rule context. * This is required for preserving whitespaces. */ private String getOriginalCodeText(ParserRuleContext ctx) { int start = ctx.start.getStartIndex(); int stop = ctx.stop.getStopIndex(); Interval interval = new Interval(start, stop); return ctx.start.getInputStream().getText(interval); }
protected EObject createAndCopy(final EObject eObject, final ParserRuleContext ruleContext) { final EClass eClass = eObject.eClass(); final EObject newEObject = create(eClass, ruleContext); final Consumer<EAttribute> copyAttribute = attribute -> newEObject.eSet(attribute, eObject.eGet(attribute)); eClass.getEAllAttributes().forEach(copyAttribute); return newEObject; }
public TreeNode(ParserRuleContext context) { this.children = new ArrayList<>(8); this.context = context; }
public ParserRuleContext getContext() { return this.context; }
/** * @return the error context, can be {@code null} */ public ParserRuleContext getErrorContext() { return ctx; }
public Source_portContext(ParserRuleContext parent, int invokingState, FWPolicy p) { super(parent, invokingState); this.p = p; }
@Override public void enterEveryRule(ParserRuleContext ctx) { //no imp }
private static ParsingException parseError(String message, ParserRuleContext context) { return new ParsingException(message, null, context.getStart().getLine(), context.getStart().getCharPositionInLine()); }
@Override public void enterEveryRule(ParserRuleContext parserRuleContext) { // do nothing. }
public PolicyContext(ParserRuleContext parent, int invokingState, List<FWPolicy> pList) { super(parent, invokingState); this.pList = pList; }
public Dest_portContext(ParserRuleContext parent, int invokingState, FWPolicy p) { super(parent, invokingState); this.p = p; }
public Dest_zoneContext(ParserRuleContext parent, int invokingState, FWPolicy p) { super(parent, invokingState); this.p = p; }
public Dest_zoneContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
@Override protected ParserRuleContext getParserContext(SQLParser parser) { // this is the entry point for a map clause return parser.select_list(); }
@Override public boolean support(ParserRuleContext context) { return context instanceof SingleConditionContext; }
public Dest_ipContext(ParserRuleContext parent, int invokingState, FWPolicy p) { super(parent, invokingState); this.p = p; }
public static int getStartIndex(ParserRuleContext ctx) { return ctx.getStop().getStartIndex(); }
private Location location(ParserRuleContext ctx) { return new Location(sourceName, ctx.getStart().getStartIndex()); }
public Source_zoneContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
@Override public void enterEveryRule(ParserRuleContext arg0) { // Logger.log(Logger.DEBUG,"enterEveryRule" + arg0.getText()); }
public PoliciesContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
public Source_ipContext(ParserRuleContext parent, int invokingState, FWPolicy p) { super(parent, invokingState); this.p = p; }
public Source_ipContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
static AntlrError handleCreationException(ObjectCreationException ex, ParserRuleContext ctx) { Token t = ctx.getStart(); Log.log(Log.LOG_WARNING, ex.getMessage(), ex); return new AntlrError(t, t.getLine(), t.getCharPositionInLine(), ex.getMessage()); }
public Source_portContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
public Dest_serviceContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
public Dest_serviceContext(ParserRuleContext parent, int invokingState, FWPolicy p) { super(parent, invokingState); this.p = p; }
public Dest_ipContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }