150 likes | 235 Views
Generating a Generator Jeff Gray University of Alabama at Birmingham Department of Computer and Information Sciences gray (at) cis.uab.edu http://www.gray-area.org. GPCE Young Researchers Workshop October 5, 2002 Pittsburgh, PA.
E N D
Generating a GeneratorJeff GrayUniversity of Alabama at BirminghamDepartment of Computer and Information Sciencesgray (at) cis.uab.eduhttp://www.gray-area.org GPCE Young Researchers Workshop October 5, 2002 Pittsburgh, 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 Multiple Levels of Hierarchy Change Maintenance??? A 4 Replicated Structures 3 B F 1 2 c d e 3' B B 4 1' 2' 1'' 2'' c d e c d e Context Sensitive
3 B Models Specification Aspects 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); } B 2 1 c e d c e d Constrained Models Design-Space Exploration and Pruning Aspect XML Strategies (C++) Parser Parser Domain-Specific Strategies 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); }
New Focus: How to generate these… (Generating a Generator) The Metaweaver Framework Specification Aspects XML Parser Strategies (C++) Aspect Parser XML (Model Hierarchy) Strategies Strategy Code Generator 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); }
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 #IMPLIEDkind NMTOKEN #REQUIRED role NMTOKEN #IMPLIED> <!ELEMENT atom (name, (regnode|constraint|attribute)*)> <!ATTLIST atom id ID #IMPLIED kind NMTOKEN #REQUIRED role NMTOKEN #IMPLIED> <!ELEMENT attribute (value, regnode*)> <!ATTLIST attributekind NMTOKEN #REQUIRED>
Subset of XMLParser Methods Implementation details associated with using underlying MSXML Tool-specific details tied to GME nodeType XMLParser::addAtom(nodeType self, CComBSTRkind, CComBSTRrole, CComBSTRname){ return addNode(self, "atom", kind, role, name);} nodeType XMLParser::findModel(nodeType aNode, CComBSTRname){ 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;}
XML Parser Generator Variability with Respect to Modeling Tools:Generating the XML Parser Aspect XML Strategies (C++) Parser Parser Specification Aspects <!ELEMENT model (name, (constraint|attribute|model|atom|reference|set connection)*)> <!ATTLIST model id ID #IMPLIED kind NMTOKEN #REQUIRED role NMTOKEN #IMPLIED> <!ELEMENT atom (name, (regnode|constraint|attribute)*)> <!ATTLIST atom id ID #IMPLIED kind NMTOKEN #REQUIRED role NMTOKEN #IMPLIED> <!ELEMENT attribute (value, regnode*)> <!ATTLIST attribute kind NMTOKEN #REQUIRED> XML DTD (tool-specific)
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 <!ELEMENT model (name, (constraint|attribute|model|atom|reference|set connection)*)> <!ATTLIST model id ID #IMPLIED kind NMTOKEN #REQUIRED role NMTOKEN #IMPLIED> <!ELEMENT atom (name, (regnode|constraint|attribute)*)> <!ATTLIST atom id ID #IMPLIED kind NMTOKEN #REQUIRED role NMTOKEN #IMPLIED> <!ELEMENT attribute (value, regnode*)> <!ATTLIST attribute kind NMTOKEN #REQUIRED> Meta-Generator Strategy Code Generator 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
GME <?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 Domain-Specific Weaver Specification Aspects 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); } Process of Using a Weaver
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(…);