Skip to content
Snippets Groups Projects
Commit 70a3951d authored by Emma Söderberg's avatar Emma Söderberg
Browse files

Update incremental handler generation to include handlers for equations...

Update incremental handler generation to include handlers for equations overloading syn lazy attributes. Tested in incremental/param/super_01.
parent 48149aed
No related branches found
No related tags found
No related merge requests found
...@@ -661,6 +661,7 @@ aspect JragCodeGen { ...@@ -661,6 +661,7 @@ aspect JragCodeGen {
} }
syn boolean AttrDecl.isParameterized() = getNumParameter() != 0; syn boolean AttrDecl.isParameterized() = getNumParameter() != 0;
syn boolean SynEq.isParameterized() = decl().isParameterized();
/** /**
* Generate code to test if two attribute values differ based on the type of the attribute. * Generate code to test if two attribute values differ based on the type of the attribute.
......
...@@ -82,7 +82,19 @@ aspect IncrementalDDG { ...@@ -82,7 +82,19 @@ aspect IncrementalDDG {
if (hasRewriteAttribute()) { if (hasRewriteAttribute()) {
tt.expand("ASTDecl.createRewriteAttributeHandler", out); tt.expand("ASTDecl.createRewriteAttributeHandler", out);
} }
// Collect attributes. // Attribute declaration handlers.
for (AttrDecl attr : gatherIncrementalHandlersForAttrDecls()) {
attr.templateContext().expand("AttrDecl.createAttributeHandler", out);
}
// Attribute equation handlers.
for (SynEq eq : gatherIncrementalHandlersForSynEqs()) {
eq.templateContext().expand("SynEq.createEquationHandler", out);
}
}
}
public ArrayList<AttrDecl> ASTDecl.gatherIncrementalHandlersForAttrDecls() {
// Collect lazy attribute declarations.
ArrayList<AttrDecl> decls = new ArrayList<AttrDecl>(); ArrayList<AttrDecl> decls = new ArrayList<AttrDecl>();
for (AttrDecl attr : synDecls()) { for (AttrDecl attr : synDecls()) {
if (attr.isMemoized()) { if (attr.isMemoized()) {
...@@ -97,12 +109,20 @@ aspect IncrementalDDG { ...@@ -97,12 +109,20 @@ aspect IncrementalDDG {
for (CollDecl decl : collDecls()) { for (CollDecl decl : collDecls()) {
decls.add(decl); decls.add(decl);
} }
// Attribute code. return decls;
for (AttrDecl attr : decls) {
attr.templateContext().expand("AttrDecl.createAttributeHandler", out);
} }
public ArrayList<SynEq> ASTDecl.gatherIncrementalHandlersForSynEqs() {
// Collect eq for lazy syn attributes where eq is defined on a subtype.
ArrayList<SynEq> eqs = new ArrayList<SynEq>();
for (SynEq eq : getSynEqList()) {
AttrDecl decl = eq.decl();
if (decl.isMemoized() && !decl.hostClass().equals(eq.hostClass())) {
eqs.add(eq);
} }
} }
return eqs;
}
/** /**
* Initialize child handlers. * Initialize child handlers.
...@@ -182,22 +202,14 @@ aspect IncrementalDDG { ...@@ -182,22 +202,14 @@ aspect IncrementalDDG {
public String ASTDecl.emitCopyAttributeHandlersString() { public String ASTDecl.emitCopyAttributeHandlersString() {
StringBuilder res = new StringBuilder(); StringBuilder res = new StringBuilder();
if (config().incrementalLevelParam() || config().incrementalLevelAttr()) { if (config().incrementalLevelParam() || config().incrementalLevelAttr()) {
// Collect attributes. // Copy attribute declaration handlers.
ArrayList<AttrDecl> decls = new ArrayList<AttrDecl>(); for (AttrDecl attr : gatherIncrementalHandlersForAttrDecls()) {
for (AttrDecl attr : synDecls()) {
if (attr != null && attr.isMemoized()) {
decls.add(attr);
}
}
for (AttrDecl attr : getInhDeclList()) {
if (attr != null && attr.isMemoized()) {
decls.add(attr);
}
}
// Attribute code.
for (AttrDecl attr : decls) {
res.append(attr.templateContext().expand("AttrDecl.copyAttributeHandler")); res.append(attr.templateContext().expand("AttrDecl.copyAttributeHandler"));
} }
// Copy syn attribute equation handlers.
for (SynEq eq : gatherIncrementalHandlersForSynEqs()) {
res.append(eq.templateContext().expand("SynEq.copyAttributeHandler"));
}
} }
return res.toString(); return res.toString();
} }
......
...@@ -477,6 +477,21 @@ $if (IncrementalLevelAttr) ...@@ -477,6 +477,21 @@ $if (IncrementalLevelAttr)
$endif $endif
]] ]]
# Create DDG node for lazy attribute equations.
SynEq.createEquationHandler = [[
$if (IncrementalLevelParam)
$if (#isParameterized)
protected java.util.Map #hostClass.#(signature)_handler = new java.util.HashMap(4);
$else
protected $DDGNodeName #hostClass.#(signature)_handler;
$endif
$endif
$if (IncrementalLevelAttr)
protected $DDGNodeName #hostClass.#(signature)_handler;
$endif
]]
# Initialize DDG node for children # Initialize DDG node for children
ASTDecl.incrementalInitChildHandlers = [[ ASTDecl.incrementalInitChildHandlers = [[
$if (IncrementalLevelParam) $if (IncrementalLevelParam)
......
...@@ -105,3 +105,23 @@ $if (IncrementalLevelAttr) ...@@ -105,3 +105,23 @@ $if (IncrementalLevelAttr)
} }
$endif $endif
]] ]]
# Copy attribute equation DDG node
SynEq.copyAttributeHandler = [[
$if (IncrementalLevelParam)
$if (#isParameterized)
if (#(signature)_handler != null) {
copy.#(signature)_handler = new java.util.HashMap(4);
}
$else
if (#(signature)_handler != null) {
copy.#(signature)_handler = $DDGNodeName.createAttrHandler(#(signature)_handler, copy);
}
$endif
$endif
$if (IncrementalLevelAttr)
if (#(signature)_handler != null) {
copy.#(signature)_handler = new $DDGNodeName(#(signature)_handler, copy);
}
$endif
]]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment