Skip to content

Commit

Permalink
Using expression builders
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Nov 22, 2022
1 parent 6a63668 commit 76f95a7
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 237 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ logs
*.so
*.log

gradle.properties
Empty file modified configure_frontends.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ class ExpressionHandler(lang: CXXLanguageFrontend) :
}

return newMemberExpression(
ctx.fieldName.toString(),
base,
UnknownType.getUnknownType(language),
ctx.fieldName.toString(),
if (ctx.isPointerDereference) "->" else ".",
ctx.rawSignature
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ private DeclarationStatement handleVariableDeclarationExpr(Expression expr) {
MemberExpression memberExpression =
newMemberExpression(
this,
fieldAccessExpr.getName().getIdentifier(),
base,
fieldType,
fieldAccessExpr.getName().getIdentifier(),
".", // there is only "." in java
fieldAccessExpr.toString());
"." // there is only "." in java
);
memberExpression.setStaticAccess(true);
return memberExpression;
}
Expand All @@ -395,12 +395,7 @@ private DeclarationStatement handleVariableDeclarationExpr(Expression expr) {
}

return newMemberExpression(
this,
base,
fieldType,
fieldAccessExpr.getName().getIdentifier(),
".",
fieldAccessExpr.toString());
this, fieldAccessExpr.getName().getIdentifier(), base, fieldType, ".");
}

private Literal handleLiteralExpression(Expression expr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import de.fraunhofer.aisec.cpg.graph.types.UnknownType
@JvmOverloads
fun <T> MetadataProvider.newLiteral(
value: T,
type: Type?,
type: Type? = UnknownType.getUnknownType(),
code: String? = null,
rawNode: Any? = null,
): Literal<T> {
Expand Down Expand Up @@ -114,7 +114,7 @@ fun MetadataProvider.newUnaryOperator(
@JvmOverloads
fun MetadataProvider.newNewExpression(
code: String? = null,
type: Type?,
type: Type? = UnknownType.getUnknownType(),
rawNode: Any? = null
): NewExpression {
val node = NewExpression()
Expand Down Expand Up @@ -179,8 +179,8 @@ fun MetadataProvider.newConditionalExpression(
*/
@JvmOverloads
fun MetadataProvider.newKeyValueExpression(
key: Expression?,
value: Expression?,
key: Expression? = null,
value: Expression? = null,
code: String? = null,
rawNode: Any? = null
): KeyValueExpression {
Expand Down Expand Up @@ -238,10 +238,10 @@ fun MetadataProvider.newCompoundStatementExpression(
*/
@JvmOverloads
fun MetadataProvider.newCallExpression(
callee: Expression?,
fqn: String?,
callee: Expression? = null,
fqn: String? = null,
code: String? = null,
template: Boolean,
template: Boolean = false,
rawNode: Any? = null
): CallExpression {
val node = CallExpression()
Expand Down Expand Up @@ -288,10 +288,10 @@ fun MetadataProvider.newMemberCallExpression(
fqn: String?,
base: Expression?,
member: Node?,
operatorCode: String?,
operatorCode: String? = ".",
code: String? = null,
rawNode: Any? = null
): CallExpression {
): MemberCallExpression {
val node = MemberCallExpression()
node.applyMetadata(this, rawNode, code)

Expand All @@ -313,10 +313,10 @@ fun MetadataProvider.newMemberCallExpression(
*/
@JvmOverloads
fun MetadataProvider.newMemberExpression(
base: Expression,
memberType: Type?,
name: String?,
operatorCode: String?,
base: Expression,
memberType: Type? = UnknownType.getUnknownType(),
operatorCode: String? = ".",
code: String? = null,
rawNode: Any? = null
): MemberExpression {
Expand Down
12 changes: 10 additions & 2 deletions cpg-language-go/src/main/golang/basic_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,21 @@ func NewString(s string) *jnigi.ObjectRef {
return o
}

func NewBoolean(b bool) *jnigi.ObjectRef {
// TODO: Use Boolean.valueOf
o, err := env.NewObject("java/lang/Boolean", b)
if err != nil {
log.Fatal(err)
}

return o
}

func NewInteger(i int) *jnigi.ObjectRef {
// TODO: Use Integer.valueOf
o, err := env.NewObject("java/lang/Integer", i)
if err != nil {
log.Fatal(err)

}

return o
Expand All @@ -57,7 +66,6 @@ func NewDouble(d float64) *jnigi.ObjectRef {
o, err := env.NewObject("java/lang/Double", d)
if err != nil {
log.Fatal(err)

}

return o
Expand Down
4 changes: 4 additions & 0 deletions cpg-language-go/src/main/golang/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (e *Expression) GetClassName() string {
return "de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression"
}

func (e *Expression) Cast(className string) *jnigi.ObjectRef {
return (*jnigi.ObjectRef)(e).Cast(className)
}

func (e *Expression) IsArray() bool {
return false
}
Expand Down

0 comments on commit 76f95a7

Please sign in to comment.