add cpp support

This commit is contained in:
Gang ZHANG 2018-10-19 18:46:38 +08:00
parent cc02daf915
commit a65bed10e9
3 changed files with 6 additions and 40 deletions

View File

@ -9,8 +9,9 @@
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<antlr4.visitor>true</antlr4.visitor>
<antlr4.listener>true</antlr4.listener>
</properties>
<build>
<plugins>
<plugin>

View File

@ -40,47 +40,12 @@ public class CppEntitiesListener extends CPP14BaseListener {
}
@Override
public void enterFunctiondefinition(FunctiondefinitionContext ctx) {
// String functionName = "";
// if (ctx.declarator().ptrdeclarator()!=null) {
// if (ctx.declarator().ptrdeclarator().noptrdeclarator()!=null) {
// functionName = getFunctionName(ctx.declarator().ptrdeclarator().noptrdeclarator());
// }
// }
// if (ctx.declarator().noptrdeclarator()!=null) {
// functionName = getFunctionName(ctx.declarator().ptrdeclarator().noptrdeclarator());
// }
// Collection<VarEntity> parameters = new ArrayList<>();
// String returnType = "void";
// List<String> throwedType = new ArrayList<>();
// context.foundMethodDeclarator(functionName,
// parameters, returnType, throwedType);
FunctiondefinitionContextHelper helper = new FunctiondefinitionContextHelper(ctx);
context.foundMethodDeclarator(helper.getFunctionName(),
helper.getParameters(),helper.getReturnType(), helper.getThrowedType());
super.enterFunctiondefinition(ctx);
}
@Override
public void enterDeclaratorid(DeclaratoridContext ctx) {
IdexpressionContext id = ctx.idexpression();
if (id.unqualifiedid()!=null) {
Collection<VarEntity> parameters = new ArrayList<>();
String returnType = "void";
List<String> throwedType = new ArrayList<>();
context.foundMethodDeclarator(id.unqualifiedid().Identifier().getText(),
parameters, returnType, throwedType);
}
super.enterDeclaratorid(ctx);
}
private String getFunctionName(NoptrdeclaratorContext ctx) {
System.out.println(ctx.getText());
if (ctx.declaratorid()!=null) {
IdexpressionContext id = ctx.declaratorid().idexpression();
if (id.unqualifiedid()!=null) {
return id.unqualifiedid().Identifier().getText();
}
}
return "";
}
@Override
public void exitFunctiondefinition(FunctiondefinitionContext ctx) {
context.exitLastedEntity();

View File

@ -15,7 +15,7 @@ public class CppParameterParserTest {
CppFileParser parser = new CppFileParser(src,repo);
parser.parse();
repo.resolveAllBindings();
//assertEquals(4,repo.getEntity("FunctionParameters.function_with_parameters_same_type").getRelations().size());
assertEquals(4,repo.getEntity("FunctionParameters.function_with_parameters_same_type").getRelations().size());
}
}