-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: <CPP> add basic function name support
- Loading branch information
Showing
2 changed files
with
40 additions
and
12 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
chapi-ast-cpp/src/main/kotlin/chapi/ast/cppast/CPPFullIdentListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,41 @@ | ||
package chapi.ast.cppast | ||
|
||
import chapi.ast.antlr.CPPBaseListener | ||
import chapi.ast.antlr.CPPParser | ||
import chapi.domain.core.CodeContainer | ||
import chapi.domain.core.CodeDataStruct | ||
import chapi.domain.core.CodeFunction | ||
|
||
class CPPFullIdentListener(fileName: String) : CPPBaseListener() { | ||
private var codeContainer: CodeContainer = CodeContainer(FullName = fileName) | ||
private var defaultNode = CodeDataStruct() | ||
|
||
override fun enterFunctiondefinition(ctx: CPPParser.FunctiondefinitionContext?) { | ||
val context = ctx!! | ||
val firstPtrDecl = context.declarator().ptrdeclarator() | ||
if (firstPtrDecl != null) { | ||
if (firstPtrDecl.noptrdeclarator() != null) { | ||
tryFunctionBuild(firstPtrDecl) | ||
} | ||
} | ||
} | ||
|
||
private fun tryFunctionBuild(firstPtrDecl: CPPParser.PtrdeclaratorContext) { | ||
val parametersandqualifiers = firstPtrDecl.noptrdeclarator().parametersandqualifiers() | ||
if (parametersandqualifiers != null) { | ||
val codeFunction = CodeFunction() | ||
|
||
val functionName = firstPtrDecl.noptrdeclarator().noptrdeclarator().text | ||
codeFunction.Name = functionName | ||
defaultNode.Functions += codeFunction | ||
} | ||
} | ||
|
||
fun getNodeInfo(): CodeContainer { | ||
if (defaultNode.Functions.isNotEmpty()) { | ||
codeContainer.DataStructures += defaultNode | ||
} | ||
|
||
return codeContainer | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters