Skip to content

Commit

Permalink
upgrade deps - scala3 (#288)
Browse files Browse the repository at this point in the history
* upgrade deps - scala3

* Fixed tests.

---------

Co-authored-by: Max Leuthäuser <[email protected]>
  • Loading branch information
mpollmeier and max-leuthaeuser authored Jul 5, 2023
1 parent bffcbea commit c5c18e5
Show file tree
Hide file tree
Showing 15 changed files with 2,885 additions and 5,078 deletions.
75 changes: 5 additions & 70 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val cpgVersion = "1.3.598"
val joernVersion = "1.1.1607"
val cpgVersion = "1.4.6"
val joernVersion = "2.0.1"

val gitCommitString = SettingKey[String]("gitSha")

Expand All @@ -16,74 +16,9 @@ Global / excludeLintKeys += Fast / configuration
Global / excludeLintKeys += gitCommitString

lazy val commonSettings = Seq(
scalaVersion := "2.13.10",
crossScalaVersions := Seq("2.13.10", "3.3.0"),
organization := "io.shiftleft",
scalacOptions ++= Seq(
) ++ (
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq("-Xtarget:8")
case _ =>
Seq(
// Emit warning and location for usages of deprecated APIs.
"-deprecation",
"-encoding",
// Specify character encoding used by source files:
"utf-8",
// Explain type errors in more detail:
"-explaintypes",
// Emit warning and location for usages of features that should be imported explicitly:
"-feature",
// Allow higher-kinded types:
"-language:higherKinds",
// Allow definition of implicit functions called views:
"-language:implicitConversions",
// Enable additional warnings where generated code depends on assumptions:
"-unchecked",
// Wrap field accessors to throw an exception on uninitialized access:
"-Xcheckinit",
// Fail the compilation if there are any warnings:
"-Xfatal-warnings",
// Warn if an argument list is modified to match the receiver:
"-Xlint:adapted-args",
// Evaluation of a constant arithmetic expression results in an error:
"-Xlint:constant",
// Selecting member of DelayedInit:
"-Xlint:delayedinit-select",
// A Scaladoc comment appears to be detached from its element:
"-Xlint:doc-detached",
// Warn about inaccessible types in method signatures:
"-Xlint:inaccessible",
// Warn when a type argument is inferred to be `Any`:
"-Xlint:infer-any",
// A string literal appears to be missing an interpolator id:
"-Xlint:missing-interpolator",
// Option.apply used implicit view:
"-Xlint:option-implicit",
// Class or object defined in package object:
"-Xlint:package-object-classes",
// Parameterized overloaded implicit methods are not visible as view bounds:
"-Xlint:poly-implicit-overload",
// A private field (or class parameter) shadows a superclass field:
"-Xlint:private-shadow",
// Pattern sequence wildcard must align with sequence component:
"-Xlint:stars-align",
// A local type parameter shadows a type already in scope:
"-Xlint:type-parameter-shadow",
// Warn when dead code is identified:
"-Ywarn-dead-code",
// Warn when more than one implicit parameter section is defined:
"-Ywarn-extra-implicit",
// Warn when nullary methods return Unit:
"-Xlint:nullary-unit",
// Warn when numerics are widened:
"-Ywarn-numeric-widen",
// Warn if an implicit parameter is unused:
"-Ywarn-unused:implicits"
)
}
),
scalaVersion := "3.3.0",
organization := "io.shiftleft",
scalacOptions ++= Seq("-Xtarget:8"),
resolvers ++= Seq(
Resolver.mavenLocal,
"Atlassian Maven Repository" at "https://maven.atlassian.com/repository/public"
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.8.2
sbt.version=1.9.1
61 changes: 26 additions & 35 deletions src/main/scala/io/shiftleft/js2cpg/astcreation/AstCreator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
val fileNode = astNodeBuilder.createFileNode(fileName)

val namespaceBlock =
astNodeBuilder.createNamespaceBlockNode(fileName + ":" + Defines.GLOBAL_NAMESPACE)
astNodeBuilder.createNamespaceBlockNode(fileName + ":" + Defines.GlobalNamespace)

astEdgeBuilder.addAstEdge(namespaceBlock, fileNode)
namespaceBlock
Expand Down Expand Up @@ -198,9 +198,9 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
case "this" =>
dynamicInstanceTypeStack.headOption
case "console" =>
Some(Defines.CONSOLE.label)
Some(Defines.Console)
case "Math" =>
Some(Defines.MATH.label)
Some(Defines.Math)
case _ =>
None
}
Expand Down Expand Up @@ -232,7 +232,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
val paramId = createIdentifierNode(name, param)
scope.addVariableReference(name, paramId)

val localParamLocal = astNodeBuilder.createLocalNode(paramName, Defines.ANY.label)
val localParamLocal = astNodeBuilder.createLocalNode(paramName, Defines.Any)
addLocalToAst(localParamLocal)
scope.addVariable(paramName, localParamLocal, MethodScope)
val keyId = astNodeBuilder.createFieldIdentifierNode(paramName, param)
Expand Down Expand Up @@ -272,7 +272,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
case None =>
val paramName = name
val localParamId = createIdentifierNode(paramName, parameter)
val localParamLocal = astNodeBuilder.createLocalNode(paramName, Defines.ANY.label)
val localParamLocal = astNodeBuilder.createLocalNode(paramName, Defines.Any)
addLocalToAst(localParamLocal)
scope.addVariable(paramName, localParamLocal, MethodScope)

Expand Down Expand Up @@ -432,13 +432,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
val astParentFullName = parentNodeId.properties("FULL_NAME").toString

val functionTypeDeclId =
astNodeBuilder.createTypeDeclNode(
methodName,
methodFullName,
astParentType,
astParentFullName,
Some(Defines.ANY.label)
)
astNodeBuilder.createTypeDeclNode(methodName, methodFullName, astParentType, astParentFullName, Some(Defines.Any))
addTypeDeclToAst(functionTypeDeclId)

// Problem for https://github.com/ShiftLeftSecurity/codescience/issues/3626 here.
Expand Down Expand Up @@ -735,12 +729,12 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
case null =>
// If the for condition is empty, this ensures that there is always a condition (true) present.
val testNodeId =
astNodeBuilder.createLiteralNode("true", astNodeBuilder.lineAndColumn(forNode), Some(Defines.BOOLEAN.label))
astNodeBuilder.createLiteralNode("true", astNodeBuilder.lineAndColumn(forNode), Some(Defines.Boolean))
testNodeId
case testNode if testNode.getExpression == null =>
// If the for condition is empty, this ensures that there is always a condition (true) present.
val testNodeId =
astNodeBuilder.createLiteralNode("true", astNodeBuilder.lineAndColumn(forNode), Some(Defines.BOOLEAN.label))
astNodeBuilder.createLiteralNode("true", astNodeBuilder.lineAndColumn(forNode), Some(Defines.Boolean))
testNodeId
// The test of a forNode can be a JoinPredecessorExpression which does not wrap any expression.
// This only happens for "for (x in y)" style loops.
Expand Down Expand Up @@ -786,7 +780,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
// _iterator assignment:
val iteratorName =
PassHelpers.generateUnusedVariableName(usedVariableNames, usedIdentNodes, "_iterator")
val iteratorLocalId = astNodeBuilder.createLocalNode(iteratorName, Defines.ANY.label)
val iteratorLocalId = astNodeBuilder.createLocalNode(iteratorName, Defines.Any)
addLocalToAst(iteratorLocalId)

val iteratorId = createIdentifierNode(iteratorName, forNode)
Expand Down Expand Up @@ -853,14 +847,14 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
// _result:
val resultName =
PassHelpers.generateUnusedVariableName(usedVariableNames, usedIdentNodes, "_result")
val resultLocalId = astNodeBuilder.createLocalNode(resultName, Defines.ANY.label)
val resultLocalId = astNodeBuilder.createLocalNode(resultName, Defines.Any)
addLocalToAst(resultLocalId)
val resultId = createIdentifierNode(resultName, forNode)
astEdgeBuilder.addAstEdge(resultId, blockId, blockOrder)

// loop variable:
val loopVariableName = forNode.getInit.toString()
val loopVariableLocalId = astNodeBuilder.createLocalNode(loopVariableName, Defines.ANY.label)
val loopVariableLocalId = astNodeBuilder.createLocalNode(loopVariableName, Defines.Any)
addLocalToAst(loopVariableLocalId)
val loopVariableId = createIdentifierNode(loopVariableName, forNode)
astEdgeBuilder.addAstEdge(loopVariableId, blockId, blockOrder)
Expand Down Expand Up @@ -1068,7 +1062,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:

val tmpName =
PassHelpers.generateUnusedVariableName(usedVariableNames, usedIdentNodes, "_tmp")
val localTmpId = astNodeBuilder.createLocalNode(tmpName, Defines.ANY.label)
val localTmpId = astNodeBuilder.createLocalNode(tmpName, Defines.Any)
addLocalToAst(localTmpId)

val tmpArrayId = createIdentifierNode(tmpName, arrayLiteralNode)
Expand Down Expand Up @@ -1139,13 +1133,13 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
// For boolean nodes we here enforce that we get a "true" or "false".
// This is required because source.getCode(literalNode) can be an empty string
// for constructs like: for(;;)
(bool.getString, Some(Defines.BOOLEAN.label))
(bool.getString, Some(Defines.Boolean))
case string if literalNode.isString =>
// Some string values are artificially created and thus source.getCode() would
// result in misleading code fields.
("\"" + string.getString + "\"", Some(Defines.STRING.label))
("\"" + string.getString + "\"", Some(Defines.String))
case _ if literalNode.getValue == null =>
("null", Some(Defines.NULL.label))
("null", Some(Defines.Null))
case obj =>
(obj.getString, None)
}
Expand Down Expand Up @@ -1217,7 +1211,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
val indexId = astNodeBuilder.createLiteralNode(
parameterNode.getIndex.toString,
astNodeBuilder.lineAndColumn(parameterNode),
Some(Defines.NUMBER.label)
Some(Defines.Number)
)

val accessId =
Expand Down Expand Up @@ -1287,7 +1281,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
val (_, methodFullName) = calcMethodNameAndFullName(functionNode)
(methodFullName, varNode.toString())
} else {
(Defines.ANY.label, "")
(Defines.Any, "")
}

val varId = astNodeBuilder.createLocalNode(varNode.getName.getName, typeFullName)
Expand Down Expand Up @@ -1367,7 +1361,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
scope.pushNewBlockScope(blockId)
localAstParentStack.push(blockId)

val localId = astNodeBuilder.createLocalNode(localTmpName, Defines.ANY.label)
val localId = astNodeBuilder.createLocalNode(localTmpName, Defines.Any)
addLocalToAst(localId)

val tmpId = createIdentifierNode(localTmpName, rhs)
Expand Down Expand Up @@ -1404,7 +1398,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
val indexId = astNodeBuilder.createLiteralNode(
index.toString,
astNodeBuilder.lineAndColumn(identNode),
Some(Defines.NUMBER.label)
Some(Defines.Number)
)
val accessId =
astNodeBuilder.createIndexAccessNode(fieldAccessTmpId, indexId, astNodeBuilder.lineAndColumn(identNode))
Expand Down Expand Up @@ -1449,7 +1443,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
val indexId = astNodeBuilder.createLiteralNode(
index.toString,
astNodeBuilder.lineAndColumn(binaryNode),
Some(Defines.NUMBER.label)
Some(Defines.Number)
)

val accessId =
Expand All @@ -1473,7 +1467,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
val indexId = astNodeBuilder.createLiteralNode(
index.toString,
astNodeBuilder.lineAndColumn(binaryNode),
Some(Defines.NUMBER.label)
Some(Defines.Number)
)

val accessId =
Expand Down Expand Up @@ -1616,7 +1610,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:

val tmpAllocName =
PassHelpers.generateUnusedVariableName(usedVariableNames, usedIdentNodes, "_tmp")
val localTmpAllocId = astNodeBuilder.createLocalNode(tmpAllocName, Defines.ANY.label)
val localTmpAllocId = astNodeBuilder.createLocalNode(tmpAllocName, Defines.Any)
addLocalToAst(localTmpAllocId)

val tmpAllocId1 = createIdentifierNode(tmpAllocName, unaryNode)
Expand Down Expand Up @@ -1830,7 +1824,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:

val tmpName =
PassHelpers.generateUnusedVariableName(usedVariableNames, usedIdentNodes, "_tmp")
val localId = astNodeBuilder.createLocalNode(tmpName, Defines.ANY.label)
val localId = astNodeBuilder.createLocalNode(tmpName, Defines.Any)
addLocalToAst(localId)

objectNode.getElements.forEach {
Expand Down Expand Up @@ -1912,11 +1906,8 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
.updateWith(closureBindingIdProperty) {
case None =>
val methodScopeNodeId = methodScope.scopeNode
val localId = astNodeBuilder.createLocalNode(
origin.variableName,
Defines.ANY.label,
Some(closureBindingIdProperty)
)
val localId =
astNodeBuilder.createLocalNode(origin.variableName, Defines.Any, Some(closureBindingIdProperty))
astEdgeBuilder.addAstEdge(localId, methodScopeNodeId, 0)
val closureBindingId =
astNodeBuilder.createClosureBindingNode(closureBindingIdProperty, origin.variableName)
Expand Down Expand Up @@ -1952,7 +1943,7 @@ class AstCreator(diffGraph: DiffGraphBuilder, source: JsSource, usedIdentNodes:
variableName: String
): (NewNode, ScopeType) = {
val varId =
astNodeBuilder.createLocalNode(variableName, Defines.ANY.label)
astNodeBuilder.createLocalNode(variableName, Defines.Any)
astEdgeBuilder.addAstEdge(varId, methodScopeNodeId, 0)
(varId, MethodScope)
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/scala/io/shiftleft/js2cpg/astcreation/AstNodeBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AstNodeBuilder(
.lineNumber(line)
.columnNumber(column)
.order(orderTracker.order)
.typeFullName(Defines.ANY.label)
.typeFullName(Defines.Any)

diffGraph.addNode(param)
orderTracker.inc()
Expand Down Expand Up @@ -113,7 +113,7 @@ class AstNodeBuilder(
.lineNumber(lineColumn.line)
.columnNumber(lineColumn.column)
.code(shortenCode(code))
.typeFullName(Defines.ANY.label)
.typeFullName(Defines.Any)

diffGraph.addNode(unknown)
unknown
Expand Down Expand Up @@ -152,7 +152,7 @@ class AstNodeBuilder(
.code(shortenCode(name))
.lineNumber(line)
.columnNumber(column)
.typeFullName(Defines.ANY.label)
.typeFullName(Defines.Any)
.dynamicTypeHintFullName(dynamicTypeOption.toList)
diffGraph.addNode(identifier)
identifier
Expand Down Expand Up @@ -205,7 +205,7 @@ class AstNodeBuilder(
.signature("")
.lineNumber(line)
.columnNumber(column)
.typeFullName(Defines.ANY.label)
.typeFullName(Defines.Any)

diffGraph.addNode(call)
call
Expand Down Expand Up @@ -278,7 +278,7 @@ class AstNodeBuilder(
val column = lineAndColumn.column
val literal = NewLiteral()
.code(shortenCode(code))
.typeFullName(Defines.ANY.label)
.typeFullName(Defines.Any)
.lineNumber(line)
.columnNumber(column)
.dynamicTypeHintFullName(dynamicTypeOption.toList)
Expand Down Expand Up @@ -328,7 +328,7 @@ class AstNodeBuilder(
.dispatchType(dispatchType)
.lineNumber(line)
.columnNumber(column)
.typeFullName(Defines.ANY.label)
.typeFullName(Defines.Any)

diffGraph.addNode(call)
call
Expand All @@ -343,7 +343,7 @@ class AstNodeBuilder(

def createNamespaceBlockNode(fullName: String): NewNamespaceBlock = {
val namespaceBlock = NewNamespaceBlock()
.name(Defines.GLOBAL_NAMESPACE)
.name(Defines.GlobalNamespace)
.fullName(fullName)
.filename(source.filePath)
.order(1)
Expand Down Expand Up @@ -423,7 +423,7 @@ class AstNodeBuilder(
shortenCode(customCode.getOrElse(sanitizeCode(node)))
}
val block = NewBlock()
.typeFullName(Defines.ANY.label)
.typeFullName(Defines.Any)
.code(code)
.lineNumber(line)
.columnNumber(column)
Expand All @@ -439,7 +439,7 @@ class AstNodeBuilder(
val ret = NewMethodReturn()
.code(shortenCode(code))
.evaluationStrategy(EvaluationStrategies.BY_VALUE)
.typeFullName(Defines.ANY.label)
.typeFullName(Defines.Any)
.lineNumber(line)
.columnNumber(column)
diffGraph.addNode(ret)
Expand Down Expand Up @@ -484,7 +484,7 @@ class AstNodeBuilder(
val member = NewMember()
.code(shortenCode(source.getString(node)))
.name(name)
.typeFullName(Defines.ANY.label)
.typeFullName(Defines.Any)
.dynamicTypeHintFullName(dynamicTypeOption.toList)
diffGraph.addNode(member)
member
Expand Down
Loading

0 comments on commit c5c18e5

Please sign in to comment.