-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rubysrc2cpg: refactored pseudo-variables' AST (#2814)
* Refactored astForPseudoVariableIdentifier * AST Unit-tests for pseudoVariableIdentifiers * scalafmt * Removed TODOs * scalafmt
- Loading branch information
1 parent
a23fa59
commit 98b032a
Showing
5 changed files
with
181 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...rubysrc2cpg/src/main/scala/io/joern/rubysrc2cpg/astcreation/AstForPrimitivesCreator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.joern.rubysrc2cpg.astcreation | ||
|
||
import io.joern.rubysrc2cpg.parser.RubyParser | ||
import io.joern.rubysrc2cpg.passes.Defines | ||
import io.joern.x2cpg.Ast | ||
|
||
trait AstForPrimitivesCreator { this: AstCreator => | ||
|
||
protected def astForNilLiteral(ctx: RubyParser.NilPseudoVariableIdentifierContext): Ast = | ||
Ast(literalNode(ctx, ctx.getText, Defines.NilClass)) | ||
|
||
protected def astForTrueLiteral(ctx: RubyParser.TruePseudoVariableIdentifierContext): Ast = | ||
Ast(literalNode(ctx, ctx.getText, Defines.TrueClass)) | ||
|
||
protected def astForFalseLiteral(ctx: RubyParser.FalsePseudoVariableIdentifierContext): Ast = | ||
Ast(literalNode(ctx, ctx.getText, Defines.FalseClass)) | ||
|
||
protected def astForSelfPseudoIdentifier(ctx: RubyParser.SelfPseudoVariableIdentifierContext): Ast = | ||
Ast(createIdentifierWithScope(ctx, ctx.getText, ctx.getText, Defines.Object)) | ||
|
||
protected def astForFilePseudoIdentifier(ctx: RubyParser.FilePseudoVariableIdentifierContext): Ast = | ||
Ast(createIdentifierWithScope(ctx, ctx.getText, ctx.getText, Defines.String)) | ||
|
||
protected def astForLinePseudoIdentifier(ctx: RubyParser.LinePseudoVariableIdentifierContext): Ast = | ||
Ast(createIdentifierWithScope(ctx, ctx.getText, ctx.getText, Defines.Integer)) | ||
|
||
protected def astForEncodingPseudoIdentifier(ctx: RubyParser.EncodingPseudoVariableIdentifierContext): Ast = | ||
Ast(createIdentifierWithScope(ctx, ctx.getText, ctx.getText, Defines.Encoding)) | ||
} |
27 changes: 27 additions & 0 deletions
27
joern-cli/frontends/rubysrc2cpg/src/main/scala/io/joern/rubysrc2cpg/passes/Defines.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.joern.rubysrc2cpg.passes | ||
|
||
object Defines { | ||
val Any: String = "ANY" | ||
val Object: String = "Object" | ||
|
||
val NilClass: String = "NilClass" | ||
val TrueClass: String = "TrueClass" | ||
val FalseClass: String = "FalseClass" | ||
|
||
val Numeric: String = "Numeric" | ||
val Integer: String = "Integer" | ||
val Float: String = "Float" | ||
|
||
val String: String = "String" | ||
val Symbol: String = "Symbol" | ||
|
||
val Array: String = "Array" | ||
val Hash: String = "Hash" | ||
|
||
val Encoding: String = "Encoding" | ||
|
||
// TODO: The following shall be moved out eventually. | ||
val ModifierRedo: String = "redo" | ||
val ModifierRetry: String = "retry" | ||
var ModifierNext: String = "next" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters