Skip to content

Commit

Permalink
Fix/php usage imports (#54)
Browse files Browse the repository at this point in the history
* Adds column number

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>

* Adds column number

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>

---------

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
  • Loading branch information
prabhu authored Jan 9, 2024
1 parent c012de6 commit c354c13
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 85 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "chen"
ThisBuild / organization := "io.appthreat"
ThisBuild / version := "1.1.4"
ThisBuild / version := "1.1.5"
ThisBuild / scalaVersion := "3.3.1"

val cpgVersion = "1.4.22"
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"downloadUrl": "https://github.com/AppThreat/chen",
"issueTracker": "https://github.com/AppThreat/chen/issues",
"name": "chen",
"version": "1.1.4",
"version": "1.1.5",
"description": "Code Hierarchy Exploration Net (chen) is an advanced exploration toolkit for your application source code and its dependency hierarchy.",
"applicationCategory": "code-analysis",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set version = "1.1.4" %}
{% set version = "1.1.5" %}

package:
name: chen
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package io.appthreat.php2atom.parser

import io.appthreat.php2atom.astcreation.PhpBuiltins
import io.appthreat.php2atom.astcreation.AstCreator
import io.appthreat.php2atom.astcreation.AstCreator.TypeConstants
import io.appthreat.php2atom.parser.Domain.PhpAssignment.{AssignTypeMap, isAssignType}
import io.appthreat.php2atom.parser.Domain.PhpBinaryOp.{BinaryOpTypeMap, isBinaryOpType}
import io.appthreat.php2atom.parser.Domain.PhpCast.{CastTypeMap, isCastType}
import io.appthreat.php2atom.parser.Domain.PhpUnaryOp.{UnaryOpTypeMap, isUnaryOpType}
import io.appthreat.php2atom.parser.Domain.PhpUseType.{PhpUseType, getUseType}
import io.appthreat.x2cpg.Defines
import io.shiftleft.codepropertygraph.generated.{ModifierTypes, Operators}
import org.slf4j.LoggerFactory
import ujson.{Arr, Obj, Str, Value}

import scala.util.{Success, Try}
import io.appthreat.php2atom.astcreation.AstCreator

object Domain:

Expand Down Expand Up @@ -70,17 +68,23 @@ object Domain:
// Used for creating the default constructor.
val ConstructorMethodName = "__construct"

final case class PhpAttributes(lineNumber: Option[Integer], kind: Option[Int])
final case class PhpAttributes(
lineNumber: Option[Integer],
columnNumber: Option[Integer],
kind: Option[Int]
)
object PhpAttributes:
val Empty: PhpAttributes = PhpAttributes(None, None)
val Empty: PhpAttributes = PhpAttributes(None, None, None)

def apply(json: Value): PhpAttributes =
Try(json("attributes")) match
case Success(Obj(attributes)) =>
val startLine =
attributes.get("startLine").map(num => Integer.valueOf(num.num.toInt))
val startColumn =
attributes.get("startFilePos").map(num => Integer.valueOf(num.num.toInt))
val kind = attributes.get("kind").map(_.num.toInt)
PhpAttributes(startLine, kind)
PhpAttributes(startLine, startColumn, kind)

case Success(Arr(_)) =>
logger.debug(s"Found array attributes in $json")
Expand All @@ -89,6 +93,7 @@ object Domain:
case unhandled =>
logger.debug(s"Could not find attributes object in type $unhandled")
PhpAttributes.Empty
end PhpAttributes

object PhpModifiers:
private val ModifierMasks = List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ abstract class AstCreatorBase(filename: String)(implicit withSchemaValidation: V
Ast(controlStructureNode)
.withChildren(children)

def wrapMultipleInBlock(asts: Seq[Ast], lineNumber: Option[Integer]): Ast =
def wrapMultipleInBlock(
asts: Seq[Ast],
lineNumber: Option[Integer],
columnNumber: Option[Integer]
): Ast =
asts.toList match
case Nil => blockAst(NewBlock().lineNumber(lineNumber))
case Nil => blockAst(NewBlock().lineNumber(lineNumber).columnNumber(columnNumber))
case ast :: Nil => ast
case astList => blockAst(NewBlock().lineNumber(lineNumber), astList)
case astList =>
blockAst(NewBlock().lineNumber(lineNumber).columnNumber(columnNumber), astList)

def whileAst(
condition: Option[Ast],
Expand Down Expand Up @@ -208,9 +213,9 @@ abstract class AstCreatorBase(filename: String)(implicit withSchemaValidation: V
val lineNumber = forNode.lineNumber
Ast(forNode)
.withChildren(locals)
.withChild(wrapMultipleInBlock(initAsts, lineNumber))
.withChild(wrapMultipleInBlock(conditionAsts, lineNumber))
.withChild(wrapMultipleInBlock(updateAsts, lineNumber))
.withChild(wrapMultipleInBlock(initAsts, lineNumber, forNode.columnNumber))
.withChild(wrapMultipleInBlock(conditionAsts, lineNumber, forNode.columnNumber))
.withChild(wrapMultipleInBlock(updateAsts, lineNumber, forNode.columnNumber))
.withChildren(bodyAsts)
.withConditionEdges(forNode, conditionAsts.flatMap(_.root).toList)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "appthreat-chen"
version = "1.1.4"
version = "1.1.5"
description = "Code Hierarchy Exploration Net (chen)"
authors = ["Team AppThreat <cloud@appthreat.com>"]
license = "Apache-2.0"
Expand Down

0 comments on commit c354c13

Please sign in to comment.