All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.joern.c2cpg.astcreation.AstNodeBuilder.scala Maven / Gradle / Ivy

There is a newer version: 4.0.131
Show newest version
package io.joern.c2cpg.astcreation

import io.shiftleft.codepropertygraph.generated.nodes.*
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement
import org.eclipse.cdt.core.dom.ast.IASTNode
import org.eclipse.cdt.internal.core.model.ASTStringUtil

trait AstNodeBuilder { this: AstCreator =>

  protected def newCommentNode(node: IASTNode, code: String, filename: String): NewComment = {
    NewComment().code(code).filename(filename).lineNumber(line(node)).columnNumber(column(node))
  }

  protected def newNamespaceBlockNode(
    node: IASTNode,
    name: String,
    fullName: String,
    code: String,
    filename: String
  ): NewNamespaceBlock = {
    NewNamespaceBlock()
      .code(code)
      .lineNumber(line(node))
      .columnNumber(column(node))
      .filename(filename)
      .name(name)
      .fullName(fullName)
  }

  protected def newJumpTargetNode(node: IASTNode): NewJumpTarget = {
    val codeString = code(node)
    val name = node match {
      case label: IASTLabelStatement          => ASTStringUtil.getSimpleName(label.getName)
      case _ if codeString.startsWith("case") => "case"
      case _                                  => "default"
    }
    NewJumpTarget()
      .parserTypeName(node.getClass.getSimpleName)
      .name(name)
      .code(codeString)
      .lineNumber(line(node))
      .columnNumber(column(node))
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy