Generating a Generator Jeff Gray University of Alabama at Birmingham Department of Computer and...
Transcript of Generating a Generator Jeff Gray University of Alabama at Birmingham Department of Computer and...
Generating a Generator
Jeff GrayUniversity of Alabama at Birmingham
Department of Computer and Information Sciences
gray (at) cis.uab.eduhttp://www.gray-area.org
GPCE Young Researchers WorkshopOctober 5, 2002Pittsburgh, PA
This work is supported by the DARPA IXO, under the Program Composition for Embedded Systems (PCES) program,
Background
Aspect-Oriented Domain Modeling
Model-Integrated Computing (MIC) with theGeneric Modeling Environment (GME)
Meta-modeling Environment
Domain-specific Modeling Environment
Difficulties in Managing Constraints in Models
A
B
c d e1 2
3
B
c d e1'' 2'' 4
F
B
c d e1' 2'
3'
4
Multiple Levelsof Hierarchy
ReplicatedStructures
ContextSensitive
ChangeMaintenance???
Domain-SpecificStrategies
Strategies (C++)
XML
Parser
Aspect
Parser
strategy ApplyConstraint(constraintName : string, expression : string)
{
addAtom("OCLConstraint", "Constraint", constraintName).addAttribute("Expression", expression);
}
strategy RemoveConstraint(constraintName : string)
{
findAtom(constraintName).removeChild();
}
strategy ReplaceConstraint(constraintName : string, expression : string)
{
RemoveConstraint(constraintName);
ApplyConstraint(constraintName, expression);
}
SpecificationAspects
Models
B
c d e
constraint FOOB2
{
// apply a specific constraint to “B2” only
in Structural models("ProcessingCompound")->
select(p | p.name() == "B2")->PowerStrategy(1, 100);
}
constraint FOOBStar
{
// apply a specific constraint to all nodes beginning with “B” - use wildcard
in Structural models("ProcessingCompound")->
select(p | p.name() == "B*")->PowerStrategy(1, 100);
}
ConstrainedModels
B
c d e1
3
2
Design-SpaceExploration and
Pruning
The Metaweaver Framework
Strategy Code
Generator
Strategies (C++)
Strategies
Specification
Aspects
strategy ApplyConstraint(constraintName : string, expression : string)
{
addAtom("OCLConstraint", "Constraint", constraintName).addAttribute("Expression", expression);
}
strategy RemoveConstraint(constraintName : string)
{
findAtom(constraintName).removeChild();
}
strategy ReplaceConstraint(constraintName : string, expression : string)
{
RemoveConstraint(constraintName);
ApplyConstraint(constraintName, expression);
}
XML
(Model Hierarchy)
New Focus:How to generate these…(Generating a Generator)
Extending the Framework
Previous implementation (strength) Provides variability, through domain-specific
strategies, among different modeling domains in the GME (tool specific)
Future implementation (address weakness) Provide variability such that new weavers can be
instantiated to support other tools (e.g., Rose) Provide variability to support different aspect
modeling languages other than ECL (not covered in this talk)
Subset of GME DTD
<!ELEMENT model (name, (constraint|attribute|model|atom|reference|set connection)*)>
<!ATTLIST model id ID #IMPLIED
kind NMTOKEN #REQUIREDrole NMTOKEN #IMPLIED>
<!ELEMENT atom (name, (regnode|constraint|attribute)*)>
<!ATTLIST atomid ID #IMPLIED
kind NMTOKEN #REQUIRED roleNMTOKEN #IMPLIED>
<!ELEMENT attribute (value, regnode*)>
<!ATTLIST attributekind NMTOKEN #REQUIRED>
Subset of XMLParser Methods
nodeType XMLParser::addAtom(nodeType self, CComBSTR kind, CComBSTR role, CComBSTR name){ return addNode(self, "atom", kind, role, name);}
nodeType XMLParser::findModel(nodeType aNode, CComBSTR name){ CComBSTR bstrFind(L"./model[name=\""); bstrFind.Append(name); bstrFind.Append("\"]"); return submitXPath(aNode, bstrFind);}
CComBSTR XMLParser::id(nodeType aNode){ CComBSTR res; CComPtr<IXMLDOMNode> attr = XMLParser::findAttribute (aNode, "id"); XMLParser::getStr(attr, res); return res;}
Implementation details associated with using underlying MSXMLTool-specific details tied to GME
Variability with Respect to Modeling Tools:Generating the XML Parser
Strategies (C++)
XMLParser
Generator
Specification Aspects
XML
Parser Parser
Aspect
XML DTD (tool-specific)
<!ELEMENT model (name, (constraint|attribute|model|atom|reference|set connection)*)><!ATTLIST model id
ID#IMPLIED
kindNMTOKEN#REQUIRED
roleNMTOKEN#IMPLIED>
<!ELEMENT atom (name, (regnode|constraint|attribute)*)><!ATTLIST atom
idID
#IMPLIED kind
NMTOKEN#REQUIRED role
NMTOKEN#IMPLIED>
<!ELEMENT attribute (value, regnode*)><!ATTLIST attribute
kindNMTOKEN#REQUIRED>
Code Generator for findModel(within StratGen)
void Generator::GenerateFindModel() {
static findModelCounter = 0;
genOut << indentStr << "nodeType aModelFind" << findModelCounter << " = XMLParser::findModel(" << lastVariable << ", ";
lastVariable.Format("%s%d", "aModelFind", findModelCounter++);
}
Variability with Respect to Modeling Tools:Generating Portions of StratGen
Meta-GeneratorStrategy
Code Generator
<!ELEMENT model (name, (constraint|attribute|model|atom|reference|set connection)*)><!ATTLIST model id
ID#IMPLIED
kindNMTOKEN#REQUIRED
roleNMTOKEN#IMPLIED>
<!ELEMENT atom (name, (regnode|constraint|attribute)*)><!ATTLIST atom
idID
#IMPLIED kind
NMTOKEN#REQUIRED role
NMTOKEN#IMPLIED>
<!ELEMENT attribute (value, regnode*)><!ATTLIST attribute
kindNMTOKEN#REQUIRED>
XML DTD (tool-specific)
Conclusion
There are three possible degrees of variability with the metaweaver framework Variability with respect to modeling domains
(previous focus) Variability with respect to modeling tools
(future focus – topic of this position paper) Variability with respect to aspect modeling languages
(future focus – not covered here) Providing variability among modeling tools can be
provided by generating a StratGen generator that is specific to a particular modeling tool
Process of Using a Weaver
GME
Domain-Specific
Weaver
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE project SYSTEM "mga.dtd">
<project guid="{00000000-0000-0000-0000-000000000000}" cdate="Thu Nov 30 14:15:40 2000" mdate="Thu Nov 30 14:15:40 2000" metaguid="{00000000-0000-0000-0000-000000000000}" metaname="PCES"><name>bit1</name><comment></comment><author></author><folder id="id-006a-00000001" kind="RootFolder"><name>bit1</name><folder id="id-006a-00000002" kind="Structural"><name>Structural</name><model id="id-0065-00000001" kind="ProcessingCompound"><name>ProcessingCompound</name><attribute kind="Description" status="meta"><value></value></attribute><atom id="id-0066-00000007" kind="Attribute" role="Attrib"><name>GatesPerBit</name><regnode name="PartRegs"><value></value><regnode name="StructuralAspect"><value></value><regnode name="Position" isopaque="yes"><value>37,153</value></regnode></regnode></regnode><attribute kind="Value" status="meta"><value></value></attribute></atom><atom id="id-0066-00000006" kind="Attribute" role="Attrib"><name>NomBits</name><regnode name="PartRegs"><value></value><regnode name="StructuralAspect"><value></value><regnode name="Position" isopaque="yes"><value>205,76</value></regnode></regnode></regnode><attribute kind="Value" status="meta"><value></value></attribute></atom><atom id="id-0066-00000005" kind="Attribute" role="Attrib"><name>MaxBits</name><regnode name="PartRegs"><value></value><regnode name="StructuralAspect"><value></value><regnode name="Position" isopaque="yes"><value>128,76</value></regnode></regnode></regnode>
Enhanced
FOO.XML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE project SYSTEM "mga.dtd">
<project guid="{00000000-0000-0000-0000-000000000000}" cdate="Thu Nov 30 14:15:40 2000" mdate="Thu Nov 30 14:15:40 2000" metaguid="{00000000-0000-0000-0000-000000000000}" metaname="PCES"><name>bit1</name><comment></comment><author></author><folder id="id-006a-00000001" kind="RootFolder"><name>bit1</name><folder id="id-006a-00000002" kind="Structural"><name>Structural</name><model id="id-0065-00000001" kind="ProcessingCompound"><name>ProcessingCompound</name><attribute kind="Description" status="meta"><value></value></attribute><atom id="id-0066-00000007" kind="Attribute" role="Attrib"><name>GatesPerBit</name><regnode name="PartRegs"><value></value><regnode name="StructuralAspect"><value></value><regnode name="Position" isopaque="yes"><value>37,153</value></regnode></regnode></regnode><attribute kind="Value" status="meta"><value></value></attribute></atom><atom id="id-0066-00000006" kind="Attribute" role="Attrib"><name>NomBits</name><regnode name="PartRegs"><value></value><regnode name="StructuralAspect"><value></value><regnode name="Position" isopaque="yes"><value>205,76</value></regnode></regnode></regnode><attribute kind="Value" status="meta"><value></value></attribute></atom><atom id="id-0066-00000005" kind="Attribute" role="Attrib"><name>MaxBits</name><regnode name="PartRegs"><value></value><regnode name="StructuralAspect"><value></value><regnode name="Position" isopaque="yes"><value>128,76</value></regnode></regnode></regnode>
FOO.XML
constraint FOOB2
{
// apply a specific constraint to “B2” only
in Structural models("ProcessingCompound")->
select(p | p.name() == "B2")->PowerStrategy(1, 100);
}
constraint FOOBStar
{
// apply a specific constraint to all nodes beginning with “B” - use wildcard
in Structural models("ProcessingCompound")->
select(p | p.name() == "B*")->PowerStrategy(1, 100);
}
Specification Aspects
Code Generation Example
CComPtr<IXMLDOMNodeList> models0 = XMLParser::models(components, ""); nodeTypeVector selectVec1 = XMLParser::ConvertDomList(models0); nodeTypeVector selectVecTrue1 = new std::vector<nodeType>; vector<nodeType>::iterator itrSelect1; for(itrSelect1 = selectVec1->begin(); itrSelect1 != selectVec1->end(); itrSelect1++) { nodeType selectNode1 = (*itrSelect1); nodeType c; c = selectNode1; CComBSTR id0 = XMLParser::id(c);
ClData varforward1(id0); ClData varforward2(referredID); bool varforward3 = varforward1 == varforward2; if(varforward3) selectVecTrue1->push_back(*itrSelect1); }
vector<nodeType>::iterator itrCollCall1; for(itrCollCall1 = selectVecTrue1->begin(); itrCollCall1 != selectVecTrue1->end(); itrCollCall1++) eagerLazy::apply(…);