@Test public void test3() { String file = "contract c {\n" + " modifier mod1(address a) { if (msg.sender == a) _; }\n" + " modifier mod2 { if (msg.sender == 2) _; }\n" + " function f() mod1(7) mod2 { }\n" + " function f2(){\n" + " var (a,b,c) = g();\n" + " }\n" + " function g() returns (uint, uint, uint) {}\n" + "}\n" + ""; SolidityParsingPhase parser = new SolidityParsingPhase(); SourceUnitContext suc = parser.parse(file); ContractDefinitionContext cdc = suc.contractDefinition().get(0); assertThat(cdc.identifier().getText()).isEqualTo("c"); List<ContractPartContext> cpcList = cdc.contractPart(); assertThat(cpcList).hasSize(5); assertThat(cpcList.get(0).modifierDefinition()).isNotNull(); ModifierDefinitionContext mod = cpcList.get(0).modifierDefinition(); ParameterListContext paramList = mod.parameterList(); assertThat(paramList.parameter(0).identifier().getText()).isEqualTo("a"); IfStatementContext ifStmt = mod.block().statement().get(0).ifStatement(); ExpressionContext exprCtx = ifStmt.expression(); TerminalNode node = (TerminalNode) exprCtx.getChild(1); assertThat(node.getText()).isEqualTo("=="); assertThat(cpcList.get(2).functionDefinition()).isNotNull(); }
public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } SolidityParsingPhase(); }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } SolidityParsingPhase(); SourceUnitContext parse(String fileContents); SourceUnitContext parse(CharStream cs); void addCommentsToSet(List<? extends Token> tokens); Integer getEmptyLines(); void setEmptyLines(Integer emptyLines); Integer getLinesOfComments(); TokenStream getTokens(); }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } SolidityParsingPhase(); SourceUnitContext parse(String fileContents); SourceUnitContext parse(CharStream cs); void addCommentsToSet(List<? extends Token> tokens); Integer getEmptyLines(); void setEmptyLines(Integer emptyLines); Integer getLinesOfComments(); TokenStream getTokens(); final Set<Token> comments; }