Skip to content

Commit

Permalink
[swiftsrc2cpg] Small cleanups (#4130)
Browse files Browse the repository at this point in the history
max-leuthaeuser authored Feb 6, 2024
1 parent 0af055b commit 334989f
Showing 16 changed files with 97 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ class SwiftSrc2Cpg extends X2CpgFrontend[Config] {
withNewEmptyCpg(config.outputPath, config) { (cpg, config) =>
File.usingTemporaryDirectory("swiftsrc2cpgOut") { tmpDir =>
val astGenResult = new AstGenRunner(config).execute(tmpDir)
val hash = HashUtil.sha256(astGenResult.parsedFiles.map { case (_, file) => File(file).path })
val hash = HashUtil.sha256(astGenResult.parsedFiles.map(file => File(file).path))

val astCreationPass = new AstCreationPass(cpg, astGenResult, config, report)(config.schemaValidation)
astCreationPass.createAndApply()
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
val elseAst = astForNode(guardStmt.body)
setOrderExplicitly(elseAst, 3)

val ifAst = controlStructureAst(ifNode, Some(conditionAst), Seq(thenAst, elseAst))
val ifAst = controlStructureAst(ifNode, Option(conditionAst), Seq(thenAst, elseAst))
val resultingAsts = astsForBlockElements(elementsBeforeGuard) :+ ifAst
setArgumentIndices(resultingAsts)
resultingAsts
Original file line number Diff line number Diff line change
@@ -64,9 +64,9 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
case d: ClassDeclSyntax => code(d.name)
case d: EnumDeclSyntax => code(d.name)
case d: ExtensionDeclSyntax => code(d.extendedType)
case d: FunctionDeclSyntax => d.signature.returnClause.map(c => code(c.`type`)).getOrElse(Defines.Any)
case d: InitializerDeclSyntax => d.signature.returnClause.map(c => code(c.`type`)).getOrElse(Defines.Any)
case d: MacroDeclSyntax => d.signature.returnClause.map(c => code(c.`type`)).getOrElse(Defines.Any)
case d: FunctionDeclSyntax => d.signature.returnClause.fold(Defines.Any)(c => code(c.`type`))
case d: InitializerDeclSyntax => d.signature.returnClause.fold(Defines.Any)(c => code(c.`type`))
case d: MacroDeclSyntax => d.signature.returnClause.fold(Defines.Any)(c => code(c.`type`))
case d: MacroExpansionDeclSyntax => code(d.macroName)
case d: ProtocolDeclSyntax => code(d.name)
case d: StructDeclSyntax => code(d.name)
@@ -191,7 +191,7 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
case Some(constructor: InitializerDeclSyntax) =>
val result = astForFunctionLike(constructor, methodBlockContent = constructorContent)
diffGraph.addEdge(result.method, NewModifier().modifierType(ModifierTypes.CONSTRUCTOR), EdgeTypes.AST)
Some(result)
Option(result)
case _ if constructorBlock.root.isDefined =>
constructorBlock.root.foreach { r =>
constructorContent.foreach { c =>
@@ -201,7 +201,7 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
}
None
case _ =>
Some(createFakeConstructor(node, methodBlockContent = constructorContent))
Option(createFakeConstructor(node, methodBlockContent = constructorContent))
}

private def isClassMethodOrUninitializedMember(node: DeclSyntax): Boolean =
@@ -688,28 +688,28 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {

val (signature, returnType) = node match {
case f: FunctionDeclSyntax =>
val returnType = f.signature.returnClause.map(c => code(c.`type`)).getOrElse(Defines.Any)
val returnType = f.signature.returnClause.fold(Defines.Any)(c => code(c.`type`))
registerType(returnType)
(s"$returnType $methodFullName ${code(f.signature.parameterClause)}", returnType)
case a: AccessorDeclSyntax =>
val returnType = Defines.Any
(s"$returnType $methodFullName ${a.parameters.map(code).getOrElse("()")}", returnType)
(s"$returnType $methodFullName ${a.parameters.fold("()")(code)}", returnType)
case i: InitializerDeclSyntax =>
val returnType = methodAstParentStack.head.properties("FULL_NAME").toString
(s"$returnType $methodFullName ${i.signature.parameterClause.parameters.children.map(code)}", returnType)
case _: DeinitializerDeclSyntax =>
val returnType = Defines.Any
(s"$returnType $methodFullName ()", returnType)
case c: ClosureExprSyntax =>
val returnType = c.signature.flatMap(_.returnClause).map(r => code(r.`type`)).getOrElse(Defines.Any)
val returnType = c.signature.flatMap(_.returnClause).fold(Defines.Any)(r => code(r.`type`))
val paramClauseCode =
c.signature.flatMap(_.parameterClause).map(code).getOrElse("").stripPrefix("(").stripSuffix(")")
c.signature.flatMap(_.parameterClause).fold("")(code).stripPrefix("(").stripSuffix(")")
registerType(returnType)
(s"$returnType $methodFullName ($paramClauseCode)", returnType)
}

val codeString = code(node)
val methodNode_ = methodNode(node, methodName, codeString, methodFullName, Some(signature), filename)
val methodNode_ = methodNode(node, methodName, codeString, methodFullName, Option(signature), filename)
val block = blockNode(node, "<empty>", Defines.Any)
methodAstParentStack.push(methodNode_)
scope.pushNewMethodScope(methodFullName, methodName, block, capturingRefNode)
@@ -736,7 +736,7 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
case a: AccessorDeclSyntax => a.body
case i: InitializerDeclSyntax => i.body
case d: DeinitializerDeclSyntax => d.body
case c: ClosureExprSyntax => Some(c.statements)
case c: ClosureExprSyntax => Option(c.statements)
}

val bodyStmtAsts = body match {
@@ -811,16 +811,16 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
ifIfConfigClauses match {
case Nil => notHandledYet(node)
case ifIfConfigClause :: Nil if ifConfigDeclConditionIsSatisfied(ifIfConfigClause) =>
ifIfConfigClause.elements.map(astForNode).getOrElse(Ast())
ifIfConfigClause.elements.fold(Ast())(astForNode)
case _ :: Nil =>
val firstElseIfSatisfied = elseIfIfConfigClauses.find(ifConfigDeclConditionIsSatisfied)
firstElseIfSatisfied match {
case Some(elseIfIfConfigClause) =>
elseIfIfConfigClause.elements.map(astForNode).getOrElse(Ast())
elseIfIfConfigClause.elements.fold(Ast())(astForNode)
case None =>
elseIfConfigClauses match {
case Nil => Ast()
case elseIfConfigClause :: Nil => elseIfConfigClause.elements.map(astForNode).getOrElse(Ast())
case elseIfConfigClause :: Nil => elseIfConfigClause.elements.fold(Ast())(astForNode)
case _ => notHandledYet(node)
}
}
@@ -832,8 +832,8 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
val importPath = node.path.children.map(c => code(c.name))
val (name, groupName) = importPath match {
case Nil => (None, None)
case elem :: Nil => (Some(elem), Some(elem))
case _ => (importPath.lastOption, Some(importPath.slice(0, importPath.size - 1).mkString(".")))
case elem :: Nil => (Option(elem), Option(elem))
case _ => (importPath.lastOption, Option(importPath.slice(0, importPath.size - 1).mkString(".")))
}
if (name.isEmpty && groupName.isEmpty) {
Ast()
@@ -887,7 +887,7 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
notHandledYet(wildcard)
generateUnusedVariableName(usedVariableNames, "wildcard")
}
val typeFullName = binding.typeAnnotation.map(t => code(t.`type`)).getOrElse(Defines.Any)
val typeFullName = binding.typeAnnotation.fold(Defines.Any)(t => code(t.`type`))
val nLocalNode = localNode(binding, name, name, typeFullName).order(0)
scope.addVariable(name, nLocalNode, scopeType)
diffGraph.addEdge(localAstParentStack.head, nLocalNode, EdgeTypes.AST)
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
val args = clauses.map(x => astForNodeWithFunctionReference(x))

val ast = callAst(initCallNode, args)
if (elements.length > MAX_INITIALIZERS) {
if (elements.sizeIs > MAX_INITIALIZERS) {
val placeholder =
literalNode(node, "<too-many-initializers>", Defines.Any).argumentIndex(MAX_INITIALIZERS)
ast.withChild(Ast(placeholder)).withArgEdge(initCallNode, placeholder)
@@ -208,7 +208,7 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
case Some(value) => astForNode(value)
case None => Ast()
}
controlStructureAst(ifNode, Some(conditionAst), Seq(thenAst, elseAst))
controlStructureAst(ifNode, Option(conditionAst), Seq(thenAst, elseAst))
}

private def astForInOutExprSyntax(node: InOutExprSyntax): Ast = notHandledYet(node)
Original file line number Diff line number Diff line change
@@ -16,38 +16,34 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
this: AstCreator =>

private def astForBreakStmtSyntax(node: BreakStmtSyntax): Ast = {
val labelAst = node.label
.map(l =>
val labelCode = code(l)
Ast(
NewJumpLabel()
.parserTypeName(node.toString)
.name(labelCode)
.code(labelCode)
.lineNumber(line(node))
.columnNumber(column(node))
.order(1)
)
val labelAst = node.label.fold(Ast())(l =>
val labelCode = code(l)
Ast(
NewJumpLabel()
.parserTypeName(node.toString)
.name(labelCode)
.code(labelCode)
.lineNumber(line(node))
.columnNumber(column(node))
.order(1)
)
.getOrElse(Ast())
)
Ast(controlStructureNode(node, ControlStructureTypes.BREAK, code(node))).withChild(labelAst)
}

private def astForContinueStmtSyntax(node: ContinueStmtSyntax): Ast = {
val labelAst = node.label
.map(l =>
val labelCode = code(l)
Ast(
NewJumpLabel()
.parserTypeName(node.toString)
.name(labelCode)
.code(labelCode)
.lineNumber(line(node))
.columnNumber(column(node))
.order(1)
)
val labelAst = node.label.fold(Ast())(l =>
val labelCode = code(l)
Ast(
NewJumpLabel()
.parserTypeName(node.toString)
.name(labelCode)
.code(labelCode)
.lineNumber(line(node))
.columnNumber(column(node))
.order(1)
)
.getOrElse(Ast())
)
Ast(controlStructureNode(node, ControlStructureTypes.CONTINUE, code(node))).withChild(labelAst)
}

@@ -79,10 +75,10 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {

private def extractLoopVariableNodeInfo(binding: ValueBindingPatternSyntax): Option[PatternSyntax] = {
binding.pattern match {
case id: IdentifierPatternSyntax => Some(id)
case expr: ExpressionPatternSyntax => Some(expr)
case tuple: TuplePatternSyntax => Some(tuple)
case _: WildcardPatternSyntax | _: MissingPatternSyntax => Some(binding.pattern)
case id: IdentifierPatternSyntax => Option(id)
case expr: ExpressionPatternSyntax => Option(expr)
case tuple: TuplePatternSyntax => Option(tuple)
case _: WildcardPatternSyntax | _: MissingPatternSyntax => Option(binding.pattern)
case _ => None
}
}
@@ -564,7 +560,7 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
val bodyAst = astForNode(node.body)
setOrderExplicitly(conditionAst, 1)
setOrderExplicitly(bodyAst, 2)
controlStructureAst(doNode, Some(conditionAst), Seq(bodyAst), placeConditionLast = true)
controlStructureAst(doNode, Option(conditionAst), Seq(bodyAst), placeConditionLast = true)
}

private def astForReturnStmtSyntax(node: ReturnStmtSyntax): Ast = {
@@ -588,7 +584,13 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
val bodyAst = astForNode(node.body)
setOrderExplicitly(conditionAst, 1)
setOrderExplicitly(bodyAst, 2)
whileAst(Some(conditionAst), Seq(bodyAst), code = Some(code), lineNumber = line(node), columnNumber = column(node))
whileAst(
Option(conditionAst),
Seq(bodyAst),
code = Option(code),
lineNumber = line(node),
columnNumber = column(node)
)
}

private def astForYieldStmtSyntax(node: YieldStmtSyntax): Ast = notHandledYet(node)
Original file line number Diff line number Diff line change
@@ -65,8 +65,8 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this:
private def astForClosureParameterClauseSyntax(node: ClosureParameterClauseSyntax): Ast = notHandledYet(node)

private def astForClosureParameterSyntax(node: ClosureParameterSyntax): Ast = {
val name = node.secondName.map(code).getOrElse(code(node.firstName))
val tpe = node.`type`.map(code).getOrElse(Defines.Any)
val name = node.secondName.fold(code(node.firstName))(code)
val tpe = node.`type`.fold(Defines.Any)(code)
registerType(tpe)
val parameterNode =
parameterInNode(
@@ -124,11 +124,11 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this:

private def astForDeclModifierSyntax(node: DeclModifierSyntax): Ast = {
val modifierType = code(node.name) match {
case "final" => Some(ModifierTypes.FINAL)
case "private" | "fileprivate" => Some(ModifierTypes.PRIVATE)
case "internal" => Some(ModifierTypes.INTERNAL)
case "public" | "open" | "package" => Some(ModifierTypes.PUBLIC)
case "static" => Some(ModifierTypes.STATIC)
case "final" => Option(ModifierTypes.FINAL)
case "private" | "fileprivate" => Option(ModifierTypes.PRIVATE)
case "internal" => Option(ModifierTypes.INTERNAL)
case "public" | "open" | "package" => Option(ModifierTypes.PUBLIC)
case "static" => Option(ModifierTypes.STATIC)
case _ => None
}
modifierType.fold(Ast())(m => Ast(NewModifier().modifierType(m).order(0)))
@@ -175,7 +175,7 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this:
// TODO: handle modifiers
// TODO: handle ellipsis
// TODO: handle defaultValue
val name = node.secondName.map(code).getOrElse(code(node.firstName))
val name = node.secondName.fold(code(node.firstName))(code)
val tpe = code(node.`type`)
registerType(tpe)
val parameterNode =
@@ -269,7 +269,7 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this:
notHandledYet(wildcard)
generateUnusedVariableName(usedVariableNames, "wildcard")
}
val typeFullName = node.typeAnnotation.map(t => code(t.`type`)).getOrElse(Defines.Any)
val typeFullName = node.typeAnnotation.fold(Defines.Any)(t => code(t.`type`))
val nLocalNode = localNode(node, name, name, typeFullName).order(0)
scope.addVariable(name, nLocalNode, scopeType)
diffGraph.addEdge(localAstParentStack.head, nLocalNode, EdgeTypes.AST)
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ trait AstNodeBuilder(implicit withSchemaValidation: ValidationMode) { this: AstC
val fullName =
if (dispatchType == DispatchTypes.STATIC_DISPATCH) name
else x2cpg.Defines.DynamicCallUnknownFullName
callNode(node, code, name, fullName, dispatchType, None, Some(Defines.Any))
callNode(node, code, name, fullName, dispatchType, None, Option(Defines.Any))
}

private def createCallNode(
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package io.joern.swiftsrc2cpg.datastructures

import io.joern.x2cpg.datastructures.Global
import io.joern.x2cpg.Ast
import io.shiftleft.codepropertygraph.generated.nodes.NewBlock
import io.shiftleft.codepropertygraph.generated.nodes.NewTypeDecl

import java.util.concurrent.ConcurrentHashMap
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ object SwiftJsonParser {

case class ParseResult(filename: String, fullPath: String, ast: SwiftNode, fileContent: String)

def readFile(rootPath: Path, file: Path): ParseResult = {
def readFile(file: Path): ParseResult = {
val jsonContent = IOUtils.readEntireFile(file)
val json = ujson.read(jsonContent)
val filename = json("relativeFilePath").str
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import io.joern.swiftsrc2cpg.datastructures.SwiftGlobal
import io.joern.swiftsrc2cpg.parser.SwiftJsonParser
import io.joern.swiftsrc2cpg.utils.AstGenRunner.AstGenRunnerResult
import io.joern.x2cpg.ValidationMode
import io.joern.x2cpg.datastructures.Global
import io.joern.x2cpg.utils.{Report, TimeUtils}
import io.shiftleft.codepropertygraph.Cpg
import io.shiftleft.passes.ConcurrentWriterCpgPass
@@ -19,29 +18,27 @@ import scala.jdk.CollectionConverters.*

class AstCreationPass(cpg: Cpg, astGenRunnerResult: AstGenRunnerResult, config: Config, report: Report = new Report())(
implicit withSchemaValidation: ValidationMode
) extends ConcurrentWriterCpgPass[(String, String)](cpg) {
) extends ConcurrentWriterCpgPass[String](cpg) {

private val logger: Logger = LoggerFactory.getLogger(classOf[AstCreationPass])

private val global = new SwiftGlobal()

def typesSeen(): List[String] = global.usedTypes.keys().asScala.filterNot(_ == Defines.Any).toList

override def generateParts(): Array[(String, String)] = astGenRunnerResult.parsedFiles.toArray
override def generateParts(): Array[String] = astGenRunnerResult.parsedFiles.toArray

override def finish(): Unit = {
astGenRunnerResult.skippedFiles.foreach { skippedFile =>
val (_, fileName) = skippedFile
val filePath = Paths.get(fileName)
val fileLOC = IOUtils.readLinesInFile(filePath).size
report.addReportInfo(fileName, fileLOC)
val filePath = Paths.get(skippedFile)
val fileLOC = IOUtils.readLinesInFile(filePath).size
report.addReportInfo(skippedFile, fileLOC)
}
}

override def runOnPart(diffGraph: DiffGraphBuilder, input: (String, String)): Unit = {
val (rootPath, jsonFilename) = input
override def runOnPart(diffGraph: DiffGraphBuilder, input: String): Unit = {
val ((gotCpg, filename), duration) = TimeUtils.time {
val parseResult = SwiftJsonParser.readFile(Paths.get(rootPath), Paths.get(jsonFilename))
val parseResult = SwiftJsonParser.readFile(Paths.get(input))
val fileLOC = IOUtils.readLinesInFile(Paths.get(parseResult.fullPath)).size
report.addReportInfo(parseResult.filename, fileLOC, parsed = true)
Try {
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@ class DependenciesPass(cpg: Cpg) extends CpgPass(cpg) {
val version = versionRange.code.replaceAll("[\"']", "")
val dep = NewDependency().name(name).version(version)
diffGraph.addNode(dep)
case call =>
logger.warn(s"Unknown dependency specification: '${call.mkString(", ")}'")
case callArg =>
logger.warn(s"Unknown dependency specification: '${callArg.mkString(", ")}'")
}
}

Original file line number Diff line number Diff line change
@@ -59,8 +59,8 @@ private class RecoverForSwiftFile(cpg: Cpg, cu: File, builder: DiffGraphBuilder,
builder.setNodeProperty(x, PropertyNames.TYPE_FULL_NAME, resolvedTypeHints.head)
case x @ (_: Identifier | _: Local | _: MethodParameterIn) =>
symbolTable.put(x, x.getKnownTypes)
case x: Call => symbolTable.put(x, (x.methodFullName +: x.dynamicTypeHintFullName).toSet)
case _ =>
case call: Call => symbolTable.put(call, (call.methodFullName +: call.dynamicTypeHintFullName).toSet)
case _ =>
}

override protected def prepopulateSymbolTable(): Unit = {
@@ -108,11 +108,13 @@ private class RecoverForSwiftFile(cpg: Cpg, cu: File, builder: DiffGraphBuilder,
val constructorPaths = if (c.methodFullName.endsWith(".alloc")) {
def newChildren = c.inAssignment.astSiblings.isCall.nameExact("<operator>.new").astChildren
val possibleImportIdentifier = newChildren.isIdentifier.headOption match {
case Some(i) => symbolTable.get(i)
case None => Set.empty[String]
case Some(id) => symbolTable.get(id)
case None => Set.empty[String]
}
lazy val possibleConstructorPointer =
newChildren.astChildren.isFieldIdentifier.map(f => CallAlias(f.canonicalName, Some("this"))).headOption match {
newChildren.astChildren.isFieldIdentifier
.map(f => CallAlias(f.canonicalName, Option("this")))
.headOption match {
case Some(fi) => symbolTable.get(fi)
case None => Set.empty[String]
}
@@ -128,10 +130,10 @@ private class RecoverForSwiftFile(cpg: Cpg, cu: File, builder: DiffGraphBuilder,
operation match {
case "<operator>.new" =>
c.astChildren.l match {
case ::(fa: Call, ::(i: Identifier, _)) if fa.name == Operators.fieldAccess =>
case ::(fa: Call, ::(id: Identifier, _)) if fa.name == Operators.fieldAccess =>
symbolTable.append(
c,
visitIdentifierAssignedToFieldLoad(i, fa.asInstanceOf[FieldAccess]).map(t =>
visitIdentifierAssignedToFieldLoad(id, fa.asInstanceOf[FieldAccess]).map(t =>
s"$t$pathSep$ConstructorMethodName"
)
)
Original file line number Diff line number Diff line change
@@ -15,15 +15,12 @@ object AstGenRunner {

private val logger = LoggerFactory.getLogger(getClass)

case class AstGenRunnerResult(
parsedFiles: List[(String, String)] = List.empty,
skippedFiles: List[(String, String)] = List.empty
)
case class AstGenRunnerResult(parsedFiles: List[String] = List.empty, skippedFiles: List[String] = List.empty)

// full path to the SwiftAstGen binary from the env var SWIFTASTGEN_BIN
private val AstGenBin: Option[String] = scala.util.Properties.envOrNone("SWIFTASTGEN_BIN").flatMap {
case path if File(path).isDirectory => Some((File(path) / "SwiftAstGen").pathAsString)
case path if File(path).exists => Some(File(path).pathAsString)
case path if File(path).isDirectory => Option((File(path) / "SwiftAstGen").pathAsString)
case path if File(path).exists => Option(File(path).pathAsString)
case _ => None
}

@@ -140,7 +137,7 @@ class AstGenRunner(config: Config) {
case Success(result) =>
val parsed = filterFiles(SourceFiles.determine(out.toString(), Set(".json")), out)
val skipped = skippedFiles(result.toList)
AstGenRunnerResult(parsed.map((in.toString(), _)), skipped.map((in.toString(), _)))
AstGenRunnerResult(parsed, skipped)
case Failure(f) =>
logger.error("\t- running SwiftAstGen failed!", f)
AstGenRunnerResult()
Original file line number Diff line number Diff line change
@@ -53,9 +53,7 @@ class CodeDumperTest extends SwiftSrc2CpgSuite {
val code = cpg.call.name("foo").dumpRaw.mkString("\n")
code should (
startWith("func")
and include regex (".*" + "let x: Int = foo" + ".*" + Pattern.quote(
CodeDumper.arrow(Option("my_func")).toString
) + ".*")
and include regex s".*let x: Int = foo.*${Pattern.quote(CodeDumper.arrow(Option("my_func")).toString)}.*"
and endWith("}")
)
}
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@ class ExpressionTests extends AbstractPassTest {
trueCase.code shouldBe "b"
falseCase.code shouldBe "c"
}
call.lineNumber shouldBe Some(1)
call.columnNumber shouldBe Some(1)
call.lineNumber shouldBe Option(1)
call.columnNumber shouldBe Option(1)
}
}

@@ -30,10 +30,10 @@ class ExpressionTests extends AbstractPassTest {
trueCase.code shouldBe "b"
falseCase.code shouldBe "c ? d : e"
falseCase shouldBe nestedCall
inside(falseCase.argument.l) { case List(cond, trueCase, falseCase) =>
cond.code shouldBe "c"
trueCase.code shouldBe "d"
falseCase.code shouldBe "e"
inside(falseCase.argument.l) { case List(condArg, trueCaseArg, falseCaseArg) =>
condArg.code shouldBe "c"
trueCaseArg.code shouldBe "d"
falseCaseArg.code shouldBe "e"
}
}
}
@@ -167,8 +167,8 @@ class ExpressionTests extends AbstractPassTest {
}
controlStruct.whenTrue.code.l shouldBe List("0")
controlStruct.whenFalse.code.l shouldBe List("1")
controlStruct.lineNumber shouldBe Some(3)
controlStruct.columnNumber shouldBe Some(10)
controlStruct.lineNumber shouldBe Option(3)
controlStruct.columnNumber shouldBe Option(10)
}
}

Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ import versionsort.VersionHelper

import java.net.URL
import java.nio.file.Paths
import scala.collection.mutable
import scala.collection.mutable.HashMap
import scala.util.{Failure, Success, Try}

object AstGenRunner {

0 comments on commit 334989f

Please sign in to comment.