Skip to content

Commit

Permalink
Code change for compiler & added test case for it
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Aug 27, 2024
1 parent 0a7dcdb commit 05358f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ extend ParseTree;
import Node;
import List;

@synopsis{Remove outer label from symbol, if any}
private Symbol delabel(Symbol s) = label(_, Symbol t) := s ? t : s;

@synopsis{Computes a unique fingerprint for each kind of tree based on the identity of the top-level tree node.}
@description{
Concrete fingerprint implements the pattern matching contract:
Expand All @@ -56,8 +59,7 @@ To complete the function for the other kinds of trees, even though less importan
implement a sensible encoding that follows the contract and tries to differentiate as much as possible between different values.
}
int concreteFingerprint(appl(Production p, list[Tree] _)) = concreteFingerprint(p);
int concreteFingerprint(amb({appl(prod(Symbol s, _, _), list[Tree] _), _})) = internalHashCode("amb") + 43 * internalHashCode(t)
when label(_, Symbol t) := s || Symbol t := s;
int concreteFingerprint(amb({appl(prod(Symbol s, _, _), list[Tree] _), _})) = internalHashCode("amb") + 43 * internalHashCode(delabel(s));
int concreteFingerprint(amb({})) = internalHashCode("amb");
int concreteFingerprint(char(int ch)) = internalHashCode("char") + internalHashCode(ch);
int concreteFingerprint(cycle(Symbol s, int _)) = internalHashCode("cycle") + 13 * internalHashCode(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ data Symbol
;


@ignoreCompiler{Generates incorrect code}
test bool listMatchInOR() {
bool unquotable(Symbol x)
= par([*Symbol _]) := x
|| strt() := x
;
return unquotable(\strt());
}
//@ignoreCompiler{Generates incorrect code}
//test bool listMatchInOR() {
// bool unquotable(Symbol x)
// = par([*Symbol _]) := x
// || strt() := x
// ;
// return unquotable(\strt());
//}


data Symbol
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module lang::rascal::tests::basic::CompilerIssues::VariableInOr

data D = d1(int n) | label(D d);

@ignoreCompiler{Generates erroneous Java code}
int f(D d) = e.n
when label(D e) := d || e := d;

@ignoreCompiler{Generates erroneous Java code}
test bool testF() = f(label(d1(10))) == 10;

0 comments on commit 05358f7

Please sign in to comment.