Skip to content

Commit

Permalink
refactor: redesign for code #24
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 6, 2024
1 parent a0e592f commit 12fe87f
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions chapi-ast-c/src/main/kotlin/chapi/ast/cast/CFullIdentListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ open class CFullIdentListener(fileName: String) : CAstBaseListener() {
}

ctx?.structDeclarationList()?.structDeclaration()?.let {
val structDecl = it
val specifierQualifierList = structDecl.specifierQualifierList()
if (specifierQualifierList != null) {
val key = specifierQualifierList.typeSpecifier().text
val qualifierList = specifierQualifierList.specifierQualifierList()
it.specifierQualifierList()?.let { qualifierList ->
val field = CodeField(
TypeType = key,
TypeValue = qualifierList?.text ?: ""
TypeType = qualifierList.typeSpecifier().text,
TypeValue = qualifierList.specifierQualifierList()?.text ?: ""
)

currentDataStruct.Fields += field
Expand All @@ -52,10 +48,7 @@ open class CFullIdentListener(fileName: String) : CAstBaseListener() {
}

is CParser.IdentifierDirectDeclaratorContext -> {
val directDeclarator = ctx as CParser.IdentifierDirectDeclaratorContext
if (directDeclarator.Identifier().text != null) {
currentFunction.Name = directDeclarator.Identifier().text
}
currentFunction.Name = ctx.Identifier().text
}

is CParser.DeclaratorDirectDeclaratorContext -> {}
Expand Down Expand Up @@ -84,6 +77,7 @@ open class CFullIdentListener(fileName: String) : CAstBaseListener() {
is CParser.IdentifierDirectDeclaratorContext -> {
directDeclarator.Identifier().text
}

else -> null
}
}
Expand Down Expand Up @@ -131,7 +125,7 @@ open class CFullIdentListener(fileName: String) : CAstBaseListener() {

if (currentFunction.Parameters.isEmpty()) return

// handle for pointer
// handle for a pointer
val firstParameter = currentFunction.Parameters[0]
if (firstParameter.TypeType.endsWith('*')) {
val pointerIndex = firstParameter.TypeType.length - 1
Expand Down

0 comments on commit 12fe87f

Please sign in to comment.