-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ClavaWeaver] ClavaJoinPoints.unaryOp("*", $expr) now supports qualif…
…ied types
- Loading branch information
Showing
5 changed files
with
118 additions
and
83 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
179 changes: 102 additions & 77 deletions
179
ClavaWeaver/resources/clava/test/api/ClavaJoinPointsTest.js
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 |
---|---|---|
@@ -1,80 +1,105 @@ | ||
import clava.ClavaJoinPoints; | ||
import clava.ClavaNodes; // Test if alias loads correctly | ||
laraImport("clava.ClavaJoinPoints"); | ||
laraImport("clava.ClavaNodes"); // Test if alias loads correctly | ||
|
||
aspectdef ClavaJoinPointsTest | ||
var intType = ClavaJoinPoints.builtinType("int"); | ||
var doubleType = ClavaJoinPoints.builtinType("double"); | ||
var intExpr = ClavaJoinPoints.exprLiteral("a", intType); | ||
var intPointerType = ClavaJoinPoints.pointer(intType); | ||
var intPointerExpr = ClavaJoinPoints.exprLiteral("aPointer", intPointerType); | ||
|
||
var intType = ClavaJoinPoints.builtinType("int"); | ||
var doubleType = ClavaJoinPoints.builtinType("double"); | ||
var intExpr = ClavaJoinPoints.exprLiteral("a", intType); | ||
var intPointerType = ClavaJoinPoints.pointer(intType); | ||
var intPointerExpr = ClavaJoinPoints.exprLiteral("aPointer", intPointerType); | ||
// Type Literal of user defined type | ||
println("User literal type: " + ClavaJoinPoints.typeLiteral("xpto").code); | ||
|
||
// Type Literal of user defined type | ||
println("User literal type: " + ClavaJoinPoints.typeLiteral("xpto").code); | ||
|
||
// Stmt Literal | ||
println("Literal statement: " + ClavaJoinPoints.stmtLiteral("int a = 0;").code); | ||
|
||
// TypedefDecl | ||
var typedefDecl = ClavaJoinPoints.typedefDecl(ClavaJoinPoints.builtinType("int"), "custom_int"); | ||
println("Typedef decl: " + typedefDecl.code); | ||
|
||
// TypedefType | ||
println("Typedef type: " + ClavaJoinPoints.typedefType(typedefDecl).code); | ||
|
||
// Cast | ||
println("C-Style cast: " + ClavaJoinPoints.cStyleCast(doubleType, intExpr).code); | ||
|
||
// If Stmt | ||
println("Empty if:\n" + ClavaJoinPoints.ifStmt("a == 0").code); | ||
println("If with then:\n" + ClavaJoinPoints.ifStmt("a == 0", ClavaJoinPoints.stmtLiteral("a = 1;")).code); | ||
println("If with else:\n" + ClavaJoinPoints.ifStmt("a == 0", undefined, ClavaJoinPoints.stmtLiteral("a = 2;")).code); | ||
|
||
// For Stmt | ||
println("Empty for:\n" + ClavaJoinPoints.forStmt().code); | ||
println("Complete for:\n" + ClavaJoinPoints.forStmt("int i=0;", "i<10;", "i++;", "i = i+1;\ni = i - 1;").code); | ||
|
||
// Unary Operator | ||
var addressOfOp = ClavaJoinPoints.unaryOp("&", intExpr); | ||
println("AddressOf code: " + addressOfOp.code); | ||
println("AddressOf code type: " + addressOfOp.type.code); | ||
|
||
var derefOp = ClavaJoinPoints.unaryOp("*", intPointerExpr); | ||
println("Deref code: " + derefOp.code); | ||
println("Deref code type: " + derefOp.type.code); | ||
|
||
|
||
var type; | ||
type = ClavaJoinPoints.type("int"); | ||
println("Builtin type: " + type.joinPointType); | ||
type = ClavaJoinPoints.type("uint64_t"); | ||
println("Literal type: " + type.node.getClass()); | ||
var type2 = ClavaJoinPoints.type(type); | ||
println("Same type: " + (type === type2)); // They should be the same join point | ||
type2 = ClavaJoinPoints.type(ClavaJoinPoints.varDeclNoInit("dummyVar", type)); | ||
println("Same type again: " + (type.code === type2.code)); // No longer the same join point, but the same node | ||
// Invalid input, only strings or jps | ||
try { | ||
ClavaJoinPoints.type([0 , 1]); | ||
println("fail 1"); | ||
} catch(e) { | ||
println("Rejected invalid input type"); | ||
} | ||
// Invalid input, jp must have type | ||
try { | ||
ClavaJoinPoints.type(ClavaJoinPoints.file("dummyFile")); | ||
println("fail 2"); | ||
} catch(e) { | ||
println("Rejected jp without type"); | ||
} | ||
|
||
// Varref | ||
var $varref = ClavaJoinPoints.varRef("varref_test", type); | ||
println("Varref code: " + $varref.code); | ||
println("Varref type: " + $varref.type.code); | ||
var $varref2 = ClavaJoinPoints.varRef(ClavaJoinPoints.varDeclNoInit("varref_test_2", type)); | ||
println("Varref2 code: " + $varref2.code); | ||
println("Varref2 type: " + $varref2.type.code); | ||
|
||
|
||
end | ||
// Stmt Literal | ||
println("Literal statement: " + ClavaJoinPoints.stmtLiteral("int a = 0;").code); | ||
|
||
// TypedefDecl | ||
var typedefDecl = ClavaJoinPoints.typedefDecl( | ||
ClavaJoinPoints.builtinType("int"), | ||
"custom_int" | ||
); | ||
println("Typedef decl: " + typedefDecl.code); | ||
|
||
// TypedefType | ||
println("Typedef type: " + ClavaJoinPoints.typedefType(typedefDecl).code); | ||
|
||
// Cast | ||
println( | ||
"C-Style cast: " + ClavaJoinPoints.cStyleCast(doubleType, intExpr).code | ||
); | ||
|
||
// If Stmt | ||
println("Empty if:\n" + ClavaJoinPoints.ifStmt("a == 0").code); | ||
println( | ||
"If with then:\n" + | ||
ClavaJoinPoints.ifStmt("a == 0", ClavaJoinPoints.stmtLiteral("a = 1;")).code | ||
); | ||
println( | ||
"If with else:\n" + | ||
ClavaJoinPoints.ifStmt( | ||
"a == 0", | ||
undefined, | ||
ClavaJoinPoints.stmtLiteral("a = 2;") | ||
).code | ||
); | ||
|
||
// For Stmt | ||
println("Empty for:\n" + ClavaJoinPoints.forStmt().code); | ||
println( | ||
"Complete for:\n" + | ||
ClavaJoinPoints.forStmt("int i=0;", "i<10;", "i++;", "i = i+1;\ni = i - 1;") | ||
.code | ||
); | ||
|
||
// Unary Operator | ||
var addressOfOp = ClavaJoinPoints.unaryOp("&", intExpr); | ||
println("AddressOf code: " + addressOfOp.code); | ||
println("AddressOf code type: " + addressOfOp.type.code); | ||
|
||
var derefOp = ClavaJoinPoints.unaryOp("*", intPointerExpr); | ||
println("Deref code: " + derefOp.code); | ||
println("Deref code type: " + derefOp.type.code); | ||
|
||
const xConstPointerDecl = Query.search("function", "constPointer") | ||
.search("vardecl", "x") | ||
.first(); | ||
const xConstPointerRef = ClavaJoinPoints.varRef(xConstPointerDecl); | ||
|
||
// Deref of qualified pointer | ||
const derefQualified = ClavaJoinPoints.unaryOp("*", xConstPointerRef); | ||
println("Deref code: " + derefQualified.code); | ||
println("Deref code type: " + derefQualified.type.code); | ||
|
||
var type; | ||
type = ClavaJoinPoints.type("int"); | ||
println("Builtin type: " + type.joinPointType); | ||
type = ClavaJoinPoints.type("uint64_t"); | ||
println("Literal type: " + type.node.getClass()); | ||
var type2 = ClavaJoinPoints.type(type); | ||
println("Same type: " + (type === type2)); // They should be the same join point | ||
type2 = ClavaJoinPoints.type(ClavaJoinPoints.varDeclNoInit("dummyVar", type)); | ||
println("Same type again: " + (type.code === type2.code)); // No longer the same join point, but the same node | ||
// Invalid input, only strings or jps | ||
try { | ||
ClavaJoinPoints.type([0, 1]); | ||
println("fail 1"); | ||
} catch (e) { | ||
println("Rejected invalid input type"); | ||
} | ||
// Invalid input, jp must have type | ||
try { | ||
ClavaJoinPoints.type(ClavaJoinPoints.file("dummyFile")); | ||
println("fail 2"); | ||
} catch (e) { | ||
println("Rejected jp without type"); | ||
} | ||
|
||
// Varref | ||
var $varref = ClavaJoinPoints.varRef("varref_test", type); | ||
println("Varref code: " + $varref.code); | ||
println("Varref type: " + $varref.type.code); | ||
var $varref2 = ClavaJoinPoints.varRef( | ||
ClavaJoinPoints.varDeclNoInit("varref_test_2", type) | ||
); | ||
println("Varref2 code: " + $varref2.code); | ||
println("Varref2 type: " + $varref2.type.code); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,10 @@ int main() { | |
|
||
return 0; | ||
|
||
} | ||
} | ||
|
||
void constPointer() { | ||
int a = 10; | ||
int const * const x = &a; | ||
} | ||
|
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