Skip to content

Commit

Permalink
feat: <python> add basic function call support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 24, 2020
1 parent 210ff80 commit f74ffcc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Expand Up @@ -126,16 +126,23 @@ open class PythonAstBaseListener : PythonParserBaseListener() {

private fun buildAtomExpr(exprCtx: PythonParser.ExprContext) {
var funcCalls : Array<CodeCall> = arrayOf()
val localVarName = exprCtx.atom().text
val atomName = exprCtx.atom().text
for (trailerContext in exprCtx.trailer()) {
var caller = trailerContext.text
if (trailerContext.name() != null) {
caller = trailerContext.name().text
if (trailerContext.DOT() != null) {
var caller = ""
if (trailerContext.name() != null) {
caller = trailerContext.name().text
}
funcCalls += CodeCall(
NodeName = atomName,
FunctionName = caller
)
} else {
funcCalls += CodeCall(
NodeName = "",
FunctionName = atomName
)
}
funcCalls += CodeCall(
NodeName = localVarName,
FunctionName = caller
)
}

currentFunction.FunctionCalls = funcCalls
Expand Down
Expand Up @@ -18,4 +18,18 @@ def build():
assertEquals(firstFunc.FunctionCalls[1].FunctionName, "setAge")
assertEquals(firstFunc.FunctionCalls[2].FunctionName, "setSSN")
}

@Test
internal fun shouldPrintFunCall() {
val code = """
async def show(str):
print(str)
"""

val codeFile = PythonAnalyser().analysis(code, "")
val firstFunc = codeFile.DataStructures[0].Functions[0]
assertEquals(firstFunc.FunctionCalls.size, 1)
assertEquals(firstFunc.FunctionCalls[0].FunctionName, "print")
assertEquals(firstFunc.FunctionCalls[0].NodeName, "")
}
}

0 comments on commit f74ffcc

Please sign in to comment.