Skip to content

Commit

Permalink
Simplified hash computations
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Jul 21, 2024
1 parent 895f988 commit 07608fe
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/org/rascalmpl/core/library/CheckTestSources.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PathConfig manualTestConfig= pathConfig(bin=|project://rascal-core/target/test-c
resources = |project://rascal-core/target/generated-test-resources2|
);

void main() = checkTestSources(manualTestConfig);
void main() = checkTestSources([], manualTestConfig);

// if cmdLineArgs contains "all", then all files in the rascal project are used (~400 files)
// otherwise only standard library and test files (~200 files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void collect(current:(Variant) `<Name name> ( <{TypeArg ","}* arguments> <Keywor
declaredFieldNames += fieldName;
fieldType = ta.\type;
dt = defType([fieldType], makeFieldType(fieldName, fieldType));
dt.md5 = md5Hash("<currentModuleName><adtName><name><consArity><i><fieldType> <fieldName><removeLayout("<current>")>");
dt.md5 = md5Hash("<currentModuleName><adtName><name><unparseNoLayout(current)>");
c.define(fieldName, fieldId(), ta.name, dt);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void collect(current: (KeywordFormal) `<Type kwType> <Name name> = <Expression e
} catch TypeUnavailable(): {
dt = defType([kwType], makeFieldType(kwformalName, kwType));
}
dt.md5 = md5Hash("<current>");
dt.md5 = md5Hash(unparseNoLayout(current));
c.define(kwformalName, keywordFormalId(), current, dt);
c.calculate("keyword formal", current, [kwType, expression],
AType(Solver s){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void declareSyntax(SyntaxDefinition current, SyntaxRole syntaxRole, IdRole idRol

dt = defType(nonterminalType);
dt.vis = vis;
dt.md5 = md5Hash("<current is language ? current.\start : ""><adtName><syndefCounter><md5ContribSym(defined)>");
dt.md5 = md5Hash("<current is language ? current.\start : ""><adtName><syndefCounter><unparseNoLayout(defined)>");
syndefCounter += 1;

// Define the syntax symbol itself and all labelled alternatives as constructors
Expand All @@ -77,17 +77,6 @@ void declareSyntax(SyntaxDefinition current, SyntaxRole syntaxRole, IdRole idRol
}
}

// ---- ProdModifier ---------------------------------------------------------

str md5ContribProdMod(Tag \tag)
= "";

default str md5ContribProdMod(ProdModifier pm)
= "<pm>";

str md5ContribProdMods(ProdModifier* pms)
= "<for(pm <- pms){><md5ContribProdMod(pm)><}>";

// ---- Prod ------------------------------------------------------------------

AProduction getProd(AType adtType, Tree tree, Solver s){
Expand All @@ -101,9 +90,6 @@ void collect(current: (Prod) `: <Name referenced>`, Collector c){
c.fact(current, referenced);
}

str md5ContribProd((Prod) `: <Name referenced>`)
= "REF<referenced>";

void requireNonLayout(Tree current, AType u, str msg, Solver s){
if(isLayoutAType(u)) s.report(error(current, "Layout type %t not allowed %v", u, msg));
}
Expand Down Expand Up @@ -179,7 +165,7 @@ void collect(current: (Prod) `<ProdModifier* modifiers> <Name name> : <Sym* syms
//def = \start(sdef) := def ? sdef : unset(def, "alabel");
return acons(def, fields, [], alabel=unescape("<name>"));
} else throw "Unexpected type of production: <ptype>";
})[md5=md5Hash("<adt><md5ContribProd(current)>")]);
})[md5=md5Hash("<adt><unparseNoLayout(current)>")]);
beginUseTypeParameters(c,closed=true);
c.push(currentAlternative, <adt, "<name>", syms>);
collect(symbols, c);
Expand All @@ -190,9 +176,6 @@ void collect(current: (Prod) `<ProdModifier* modifiers> <Name name> : <Sym* syms
}
}

str md5ContribProd((Prod) `<ProdModifier* modifiers> <Name name> : <Sym* syms>`)
= "<md5ContribProdMods(modifiers)><unescape("<name>")>C<for(s <- syms){><md5ContribSym(s)><}>";

void collect(current: (Prod) `<ProdModifier* modifiers> <Sym* syms>`, Collector c){
symbols = [sym | sym <- syms];

Expand All @@ -212,10 +195,6 @@ void collect(current: (Prod) `<ProdModifier* modifiers> <Sym* syms>`, Collector
}
}

str md5ContribProd(p:(Prod) `<ProdModifier* modifiers> <Sym* syms>`){
return "<md5ContribProdMods(modifiers)><for(s <- syms){><md5ContribSym(s)><}>";
}

private AProduction associativity(AType nt, nothing(), AProduction p) = p;
private default AProduction associativity(AType nt, just(AAssociativity a), AProduction p) = associativity(nt, a, {p});

Expand Down Expand Up @@ -245,9 +224,6 @@ list[Prod] normalizeAlt((Prod) `<Prod lhs> | <Prod rhs>`)

default list[Prod] normalizeAlt(Prod p) = [p];

str md5ContribProd((Prod) `<Assoc ass> ( <Prod group> )`)
= "<ass>L<md5ContribProd(group)>R";

void collect(current: (Prod) `<Prod lhs> | <Prod rhs>`, Collector c){
if(<Tree adt, _, _, _> := c.top(currentAdt)){
alts = normalizeAlt(current);
Expand All @@ -261,14 +237,12 @@ void collect(current: (Prod) `<Prod lhs> | <Prod rhs>`, Collector c){
c.pop(inAlternative);
if(isEmpty(c.getStack(inAlternative))){
nalternatives += 1;
c.define("alternative-<nalternatives>", nonterminalId(), current, defType(current)[md5=md5ContribProd(current)]);
c.define("alternative-<nalternatives>", nonterminalId(), current, defType(current)[md5=md5Hash(unparseNoLayout(current))]);
}
} else {
throw "collect alt: currentAdt not found";
}
}
str md5ContribProd((Prod) `<Prod lhs> | <Prod rhs>`)
= "<md5ContribProd(lhs)>A<md5ContribProd(rhs)>";

void collect(current: (Prod) `<Prod lhs> \> <Prod rhs>`, Collector c){
if(<Tree adt, _, _, _> := c.top(currentAdt)){
Expand All @@ -281,11 +255,4 @@ void collect(current: (Prod) `<Prod lhs> \> <Prod rhs>`, Collector c){
} else {
throw "collect alt: currentAdt not found";
}
}

str md5ContribProd((Prod) `<Prod lhs> \> <Prod rhs>`)
= "<md5ContribProd(lhs)>R<md5ContribProd(rhs)>";

//default void collect(Prod current, Collector c){
// throw "collect Prod, missed case <current>";
//}
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,18 +536,16 @@ void collect(current:(Sym) `start [ <Nonterminal n> ]`, Collector c){
collect(n, c);
}

str md5ContribSym((Sym) `start [ <Nonterminal n> ]`)
= "S<n>";

str removeLayout(str s){
str unparseNoLayout(Tree t){
s = "<t>";
return "<for(int i <- [0..size(s)]){><s[i] in {" ", "\t", "\n"} ? "" : s[i]><}>";
}

void collect(current:(Sym) `<Sym symbol> <NonterminalLabel n>`, Collector c){
un = unescape("<n>");
md5Contrib = "";
if(!isEmpty(c.getStack(currentAlternative)) && <Tree adt, str cname, syms> := c.top(currentAlternative)){
md5Contrib += "<adt.defined><cname><removeLayout("<syms>")>";
md5Contrib += "<adt.defined><cname><unparseNoLayout(syms)>";
} else if(!isEmpty(c.getStack(currentAdt)) && <Tree adt, _, _, _> := c.top(currentAdt)){
md5Contrib += "<adt.defined>";
}
Expand All @@ -557,7 +555,7 @@ void collect(current:(Sym) `<Sym symbol> <NonterminalLabel n>`, Collector c){
AType(Solver s){
res = s.getType(symbol)[alabel=un];
return res;
})[md5=md5Hash("<md5Contrib><md5ContribSym(current)>")]);
})[md5=md5Hash("<md5Contrib><unparseNoLayout(current)>")]);

c.fact(current, n);
collect(symbol, c);
Expand All @@ -572,21 +570,13 @@ void collect(current:(Sym) `<Class cc>`, Collector c){
c.fact(current, cc2ranges(cc));
}

str md5ContribSym((Sym) `<Class cc>`)
= reduceToURIChars("<cc>");

void collect(current:(Sym) `<StringConstant l>`, Collector c){
c.fact(current, AType::alit(unescapeLiteral(l)));
}

str md5ContribSym((Sym) `<StringConstant l>`)
= reduceToURIChars("<l>");

void collect(current:(Sym) `<CaseInsensitiveStringConstant l>`, Collector c){
c.fact(current, AType::acilit(unescapeLiteral(l)));
}
str md5ContribSym((Sym) `<CaseInsensitiveStringConstant l>`)
= reduceToURIChars("<l>");

// ---- regular expressions

Expand Down Expand Up @@ -834,9 +824,6 @@ void collect(current:(Sym) `<Sym symbol> \\ <Sym match>`, Collector c){
str md5ContribSym((Sym) `<Sym symbol> \\ <Sym match>`)
= "<md5ContribSym(symbol)>NOTEQUAL<md5ContribSym(match)>";

default str md5ContribSym(Sym sym)
= reduceToURIChars("<sym>");

void collect(Sym current, Collector c){
throw "collect Sym, missed case <current>";
}
Expand Down

0 comments on commit 07608fe

Please sign in to comment.