/** * Parse the useragent and return every part that was found. * * @param userAgent The useragent instance that needs to be parsed * @return If the parse was valid (i.e. were there any parser errors: true=valid; false=has errors */ private UserAgent parseIntoCleanUserAgent(UserAgent userAgent) { if (userAgent.getUserAgentString() == null) { userAgent.set(SYNTAX_ERROR, "true", 1); return userAgent; // Cannot parse this } // Parse the userAgent into tree UserAgentContext userAgentContext = parseUserAgent(userAgent); // Walk the tree an inform the calling analyzer about all the nodes found state = new ParseTreeProperty<>(); State rootState = new State("agent"); rootState.calculatePath(PathType.CHILD, false); state.put(userAgentContext, rootState); if (userAgent.hasSyntaxError()) { inform(null, SYNTAX_ERROR, "true"); } else { inform(null, SYNTAX_ERROR, "false"); } WALKER.walk(this, userAgentContext); return userAgent; }
/** * Sets the file name, and clears all parse tree properties. */ public void setFileName(String filename) { this.filename = filename; imports.clear(); section = new ParseTreeProperty<String>(); components = new ParseTreeProperty<ComponentExpression<T>>(); formula = new ParseTreeProperty<PredicateExpression>(); instances = new ParseTreeProperty<InstanceExpression<T>>(); terms = new ParseTreeProperty<TermExpression>(); termsList = new ParseTreeProperty<List<TermExpression>>(); signatureExpressions = new ParseTreeProperty<SignatureExpression>(); parameterlists = new ParseTreeProperty<List<ParameterExpression>>(); parameters = new ParseTreeProperty<ParameterExpression>(); nodelists = new ParseTreeProperty<List<NodeExpression>>(); nodes = new ParseTreeProperty<NodeExpression>(); typetags = new ParseTreeProperty<TypeTag>(); portlists = new ParseTreeProperty<List<PortExpression>>(); ports = new ParseTreeProperty<PortExpression>(); variables = new ParseTreeProperty<VariableExpression>(); atoms = new ParseTreeProperty<T>(); }
public OTLDListener() { this.functions = new ParseTreeProperty<>(); this.conditionals = new ParseTreeProperty<>(); this.stack = new Stack<>(); this.errors = new ArrayList<>(); this.waypoints = new HashMap<>(); this.lastFunction = null; }
/** * Starts the context checking. * * Will print out the amount of errors afterwards. If there were any errors, calls {@link System#exit System.exit}. * * @param tree * The parse tree to be context checked. * @return {@link #parseTreeDecoration} */ public ParseTreeProperty<Symbol> check(ParseTree tree) { this.parseTreeDecoration = new ParseTreeProperty<Symbol>(); this.visit(tree); if (this.getErrorCount() > 0) { System.err.println("There were " + this.getErrorCount() + " errors detected."); System.err.println("Aborting compilation: cannot compile code with errors."); System.exit(1); // Did not compile correctly } return this.parseTreeDecoration; }
@VisibleForTesting static void resolveSymbols(ParserRuleContext parseTree, ParseTreeProperty<NodeState> states, ExecutionContext executionContext, Function currentFunction, long pc) { SymbolResolutionVisitor resolutionVisitor = new SymbolResolutionVisitor(states, executionContext, currentFunction, pc); parseTree.accept(resolutionVisitor); }
@VisibleForTesting static void typeCheckExpression(ParserRuleContext parseTree, ParseTreeProperty<NodeState> states) { TypeCheckingVisitor typeCheckingVisitor = new TypeCheckingVisitor(states); parseTree.accept(typeCheckingVisitor); }
@VisibleForTesting static void simplifyExpression(ParserRuleContext parseTree, ParseTreeProperty<NodeState> states, ExecutionContext executionContext) { ExpressionSimplificationVisitor visitor = new ExpressionSimplificationVisitor(states, executionContext); parseTree.accept(visitor); }
@VisibleForTesting static Expression generateCode(ParserRuleContext parseTree, ParseTreeProperty<NodeState> states, ExecutionContext executionContext) { CodeGenVisitor visitor = new CodeGenVisitor(states, executionContext); return parseTree.accept(visitor); }
public SymbolResolutionVisitor(ParseTreeProperty<NodeState> states, ExecutionContext executionContext, Function currentFunction, long pc) { super(states); this.currentFunction = currentFunction; this.pc = pc; this.executable = executionContext.getExecutable(); }
private static SymbolResolutionVisitor createVisitor() throws Exception { ExecutionContext executionContext = mock(ExecutionContext.class); Function currentFunction = mock(Function.class); ParseTreeProperty<NodeState> states = new ParseTreeProperty<>(); return new SymbolResolutionVisitor(states, executionContext, currentFunction, 0); }
private void runSimplification(ParserRuleContext parseTree, ParseTreeProperty<NodeState> states, ExecutionContext executionContext) throws Exception { long pc = executionContext.getCurrentThread().getPC(); Function currentFunction = executionContext.getExecutable().getContainingFunction(pc); CExpressionCompiler.resolveSymbols(parseTree, states, executionContext, currentFunction, pc); CExpressionCompiler.typeCheckExpression(parseTree, states); CExpressionCompiler.simplifyExpression(parseTree, states, executionContext); }
private void testSimplification(String input, String output, ExecutionContext executionContext) throws Exception { ParseTreeProperty<NodeState> states = new ParseTreeProperty<>(); ParserRuleContext parseTree = CExpressionCompiler.createParseTree(input); runSimplification(parseTree, states, executionContext); NodeState nodeState = states.get(parseTree); assertNotNull(nodeState); assertNotNull(nodeState.getExpressionValue()); assertEquals(nodeState.getExpressionValue().toString(), output); }
/** * Flush the {@link #values} mapping for allowing garbage collection. */ void clearValues() { values = new ParseTreeProperty<>(); }
public ParseTreeProperty<Expression> expressions() { return exprs; }
public ParseTreeProperty<Map<String, Expression>> arguments() { return args; }
public ParseTreeProperty<List<Expression>> argumentLists() { return argsLists; }
protected ParseTreeProperty<Double> getNumberNodesAnnotations() { return numberNodesAnnotations; }
protected void setNumberNodesAnnotations( ParseTreeProperty<Double> numberNodesAnnotations) { this.numberNodesAnnotations = numberNodesAnnotations; }
public CodeGenVisitor(ParseTreeProperty<NodeState> states, ExecutionContext executionContext) { super(states); this.executionContext = executionContext; }
public TypeCheckingVisitor(ParseTreeProperty<NodeState> states) { super(states); }
public ExpressionSimplificationVisitor(ParseTreeProperty<NodeState> states, ExecutionContext executionContext) { super(states); this.executionContext = executionContext; }
protected BaseExpressionVisitor(ParseTreeProperty<NodeState> states) { this.states = states; }
private static TypeCheckingVisitor createVisitor() throws Exception { ParseTreeProperty<NodeState> states = new ParseTreeProperty<>(); return new TypeCheckingVisitor(states); }
private RegexListener(Set<Symbol> alphabet) { this.automatons = new ParseTreeProperty<>(); this.automaton = null; this.alphabet = alphabet; }
public SemanticListener(List<Symbol> builtinDeclarations) { this.semanticErrors = new LinkedList<>(); this.expressionTypes = new ParseTreeProperty<>(); this.functions = new ParseTreeProperty<>(); this.builtinDeclarations = builtinDeclarations; }