Changeset 9 for trunk/t3d/src/org
- Timestamp:
- 06/15/10 13:27:53 (15 years ago)
- Location:
- trunk/t3d/src/org/etsi/t3d
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/t3d/src/org/etsi/t3d/DependencyPrinter.java
r7 r9 4 4 import java.io.FileOutputStream; 5 5 import java.io.PrintStream; 6 import java.util.ArrayList; 7 import java.util.LinkedList; 6 8 9 import org.etsi.t3d.visitor.VisitorCommonFunctions; 10 11 import de.ugoe.cs.swe.trex.core.analyzer.rfparser.ASTUtil; 7 12 import de.ugoe.cs.swe.trex.core.analyzer.rfparser.LocationAST; 13 import de.ugoe.cs.swe.trex.core.analyzer.rfparser.TTCN3ParserTokenTypes; 14 import de.ugoe.cs.swe.trex.core.analyzer.rfparser.symboltable.EnumSymbol; 15 import de.ugoe.cs.swe.trex.core.analyzer.rfparser.symboltable.Symbol; 8 16 9 17 public class DependencyPrinter { … … 15 23 16 24 } 25 //TODO: unify 26 27 /** 28 * Extracts identifiers related to a module definition identifier within the 29 * corresponding module definition subtree 30 * TODO: filter out predefined functions 31 * @param moduleDefinitionIdentifierNode - A module definition identifier node 32 * @return - A list of referenced identifier nodes, excluding the identifier 33 * nodes of the module definition itself; if node is not of type Identifier 34 * an empty list is returned instead 35 */ 36 //TODO: this may need to be moved for reuse 37 private static LinkedList<LocationAST> getRelatedIdentifierNodes( 38 LocationAST identifierNode) { 39 LinkedList<LocationAST> identifierNodes = new LinkedList<LocationAST>(); 40 if (identifierNode.getType() != TTCN3ParserTokenTypes.Identifier) { 41 return identifierNodes; 42 } 43 LocationAST moduleDefinitionNode = LocationAST.resolveParentsUntilType(identifierNode, 44 TTCN3ParserTokenTypes.ModuleDefinition); 45 46 LocationAST typeNode = LocationAST.getModuleDefinitionTypeNode(moduleDefinitionNode); 47 if (typeNode.getType() == TTCN3ParserTokenTypes.ModuleParDef 48 && typeNode.getFirstChild().getType() == TTCN3ParserTokenTypes.MultitypedModuleParList) { 49 LocationAST sibling = identifierNode.getNextSibling(); 50 if (sibling != null 51 && sibling.getType() != TTCN3ParserTokenTypes.Identifier) { 52 identifierNodes.addAll(ASTUtil.findTypeNodes(sibling, 53 TTCN3ParserTokenTypes.Identifier)); 54 55 } 56 LocationAST moduleParNode = LocationAST.resolveParentsUntilType(identifierNode, 57 TTCN3ParserTokenTypes.ModulePar); 58 LocationAST moduleParTypeNode = moduleParNode.getFirstChild(); 59 identifierNodes.addAll(ASTUtil.findTypeNodes(moduleParTypeNode, 60 TTCN3ParserTokenTypes.Identifier)); 61 62 } else { 63 identifierNodes = ASTUtil.findTypeNodes(moduleDefinitionNode, 64 TTCN3ParserTokenTypes.Identifier); 65 ArrayList<LocationAST> moduleDefinitionIdentifierNodes = LocationAST.getModuleDefinitionIdentifiersList(moduleDefinitionNode); 66 identifierNodes.removeAll(moduleDefinitionIdentifierNodes); 67 } 68 // TODO: exclude predefined functions 69 return identifierNodes; 70 } 71 72 /** 73 * Transforms a list of <LocationAST> identifier nodes into a list of <String> reference IDs 74 * @param identifierNodes - the list of identifier nodes 75 * @return - A list of reference IDs 76 */ 77 private LinkedList<String> getReferenceIds(LinkedList<LocationAST> identifierNodes){ 78 LinkedList<String> referencedIds = new LinkedList<String>(); 79 80 for (LocationAST identifierNode : identifierNodes) { 81 LocationAST declarationNode = VisitorCommonFunctions.getDeclarationNodeFromIdentifier(identifierNode.getFirstChild()); 82 if (declarationNode != null) { 83 String id = VisitorCommonFunctions.getIdFromIdentifier(declarationNode); 84 // TODO: move predefined filtering up 85 if (!id.equals("#") && !id.startsWith("trexPredefined")) { 86 Symbol symbol = identifierNode.getFirstChild().getSymbol(); 87 if (symbol instanceof EnumSymbol) { 88 //TODO: need to add handling in documentation and imports generators too probably 89 declarationNode = symbol.getSurroundingScope().getScopeSymbol().getDeclarationNode(); 90 id = VisitorCommonFunctions.getIdFromIdentifier(declarationNode); 91 } 92 if (VisitorCommonFunctions.isValidCrossReference(declarationNode)) { 93 if (!referencedIds.contains(id)) { 94 referencedIds.add(id); 95 } 96 } 97 } 98 } else { 99 referencedIds.add("unresolvedReference---" 100 + VisitorCommonFunctions.getName(identifierNode.getFirstChild())); 101 } 102 } 103 return referencedIds; 104 } 105 106 107 private String getDependecies(LocationAST identifierNode) { 108 //TODO: this should be a part of the printer 109 LinkedList<String> referenceIds = getReferenceIds(getRelatedIdentifierNodes(identifierNode)); 110 //sanitize list for slipped-through enumerated values 111 referenceIds.remove(VisitorCommonFunctions.getIdFromIdentifier(identifierNode)); 112 String refs = "\n\t\t<reflist>"; 113 for (String id : referenceIds) 114 refs += "\n\t\t\t<ref id=\"" + id + "\"/>"; 115 refs += "\n\t\t</reflist>"; 116 return refs; 117 } 17 118 18 public void newElement(String name, String id, int type, int line, 19 String module, String dependencies) { 20 writeStream("\n\t<element id=\"" 21 + id 22 + "\" name=\"" 23 + name 24 + "\" type=\"" 25 + LocationAST.getTTCN3ParserTokenTypeTypePrettyName(type) 26 + "\" line=\"" 27 + line 28 + "\" module=\"" 29 + module 30 + "\" file=\"" 31 + currentTTCN3File.substring(currentTTCN3File.lastIndexOf("/") + 1) 32 + "\">"); 33 writeStream(dependencies); 34 writeStream("\n\t</element>\n"); 119 private String getElementList(LocationAST node){ 120 //TODO: this should be a part of the printer 121 String elementList = "\n\t\t<elementlist>"; 122 LinkedList <LocationAST> moduleDefinitionsList = ASTUtil.findTypeNodes(LocationAST.resolveParentsUntilType(node, TTCN3ParserTokenTypes.ModuleDefinition).getFirstChild(), TTCN3ParserTokenTypes.ModuleDefinition); 123 for(LocationAST moduleDefinitionNode : moduleDefinitionsList){ 124 ArrayList<LocationAST> identifiersList = LocationAST.getModuleDefinitionIdentifiersList(moduleDefinitionNode); 125 for(LocationAST identifierNode : identifiersList) 126 elementList += "\n\t\t\t<ref id=\"" + VisitorCommonFunctions.getIdFromIdentifier(identifierNode) + "\"/>"; 127 } 128 return elementList + "\n\t\t</elementlist>"; 35 129 } 36 130 37 public void newGroup(String name, String id, int type, int line, String module, 38 String elementList) { 39 writeStream("\n\t<element id=\"" 40 + id 41 + "\" name=\"" 42 + name 43 + "\" type=\"" 44 + LocationAST.getTTCN3ParserTokenTypeTypePrettyName(type) 45 + "\" line=\"" 46 + line 47 + "\" module=\"" 48 + module 49 + "\" file=\"" 50 + currentTTCN3File.substring(currentTTCN3File.lastIndexOf("/") + 1) 51 + "\">"); 52 writeStream(elementList); 53 writeStream("\n\t</element>\n"); 131 132 public void newElement(LocationAST node) { 133 ArrayList<LocationAST> identifiersList = LocationAST.getModuleDefinitionIdentifiersList(node); 134 LocationAST typeNode = LocationAST.getModuleDefinitionTypeNode(node); 135 //TODO: refine further 136 for (LocationAST identifierNode : identifiersList) { 137 writeStream("\n\t<element id=\"" 138 + VisitorCommonFunctions.getIdFromIdentifier(identifierNode.getFirstChild()) 139 + "\" name=\"" 140 + VisitorCommonFunctions.getName(identifierNode) 141 + "\" type=\"" 142 + LocationAST.getTTCN3ParserTokenTypeTypePrettyName(typeNode.getType()) 143 + "\" line=\"" 144 + identifierNode.getLine() 145 + "\" module=\"" 146 + VisitorCommonFunctions.getModuleName(identifierNode) 147 + "\" file=\"" 148 + currentTTCN3File.substring(currentTTCN3File.lastIndexOf("/") + 1) 149 + "\">"); 150 151 if (typeNode.getType()==TTCN3ParserTokenTypes.GroupDef) { 152 writeStream(getElementList(identifierNode)); 153 }else { 154 writeStream(getDependecies(identifierNode)); 155 } 156 writeStream("\n\t</element>\n"); 157 } 54 158 } 55 159 56 160 public void setXMLPath(String xmlpath){ 57 161 FileOutputStream file; -
trunk/t3d/src/org/etsi/t3d/visitor/DependencyVisitor.java
r7 r9 28 28 } 29 29 30 31 /**32 * Extracts identifiers related to a module definition identifier within the33 * corresponding module definition subtree34 * TODO: filter out predefined functions35 * @param moduleDefinitionIdentifierNode - A module definition identifier node36 * @return - A list of referenced identifier nodes, excluding the identifier37 * nodes of the module definition itself; if node is not of type Identifier38 * an empty list is returned instead39 */40 //TODO: this may need to be moved for reuse41 private static LinkedList<LocationAST> getRelatedIdentifierNodes(42 LocationAST identifierNode) {43 LinkedList<LocationAST> identifierNodes = new LinkedList<LocationAST>();44 if (identifierNode.getType() != TTCN3ParserTokenTypes.Identifier) {45 return identifierNodes;46 }47 LocationAST moduleDefinitionNode = LocationAST.resolveParentsUntilType(identifierNode,48 TTCN3ParserTokenTypes.ModuleDefinition);49 50 LocationAST typeNode = LocationAST.getModuleDefinitionTypeNode(moduleDefinitionNode);51 if (typeNode.getType() == TTCN3ParserTokenTypes.ModuleParDef52 && typeNode.getFirstChild().getType() == TTCN3ParserTokenTypes.MultitypedModuleParList) {53 LocationAST sibling = identifierNode.getNextSibling();54 if (sibling != null55 && sibling.getType() != TTCN3ParserTokenTypes.Identifier) {56 identifierNodes.addAll(ASTUtil.findTypeNodes(sibling,57 TTCN3ParserTokenTypes.Identifier));58 59 }60 LocationAST moduleParNode = LocationAST.resolveParentsUntilType(identifierNode,61 TTCN3ParserTokenTypes.ModulePar);62 LocationAST moduleParTypeNode = moduleParNode.getFirstChild();63 identifierNodes.addAll(ASTUtil.findTypeNodes(moduleParTypeNode,64 TTCN3ParserTokenTypes.Identifier));65 66 } else {67 identifierNodes = ASTUtil.findTypeNodes(moduleDefinitionNode,68 TTCN3ParserTokenTypes.Identifier);69 ArrayList<LocationAST> moduleDefinitionIdentifierNodes = LocationAST.getModuleDefinitionIdentifiersList(moduleDefinitionNode);70 identifierNodes.removeAll(moduleDefinitionIdentifierNodes);71 }72 // TODO: exclude predefined functions73 return identifierNodes;74 }75 76 77 30 /** 78 31 * Extracts referenced identifiers from within a module definition subtree … … 93 46 } 94 47 95 96 /**97 * Transforms a list of <LocationAST> identifier nodes into a list of <String> reference IDs98 * @param identifierNodes - the list of identifier nodes99 * @return - A list of reference IDs100 */101 private LinkedList<String> getReferenceIds(LinkedList<LocationAST> identifierNodes){102 LinkedList<String> referencedIds = new LinkedList<String>();103 104 for (LocationAST identifierNode : identifierNodes) {105 LocationAST declarationNode = VisitorCommonFunctions.getDeclarationNodeFromIdentifier(identifierNode.getFirstChild());106 if (declarationNode != null) {107 String id = VisitorCommonFunctions.getIdFromIdentifier(declarationNode);108 // TODO: move predefined filtering up109 if (!id.equals("#") && !id.startsWith("trexPredefined")) {110 Symbol symbol = identifierNode.getFirstChild().getSymbol();111 if (symbol instanceof EnumSymbol) {112 //TODO: need to add handling in documentation and imports generators too probably113 declarationNode = symbol.getSurroundingScope().getScopeSymbol().getDeclarationNode();114 id = VisitorCommonFunctions.getIdFromIdentifier(declarationNode);115 }116 if (VisitorCommonFunctions.isValidCrossReference(declarationNode)) {117 if (!referencedIds.contains(id)) {118 referencedIds.add(id);119 }120 }121 }122 } else {123 referencedIds.add("unresolvedReference---"124 + VisitorCommonFunctions.getName(identifierNode.getFirstChild()));125 }126 }127 return referencedIds;128 }129 130 131 private String getDependecies(LocationAST identifierNode) {132 //TODO: this should be a part of the printer133 LinkedList<String> referenceIds = getReferenceIds(getRelatedIdentifierNodes(identifierNode));134 //sanitize list for slipped-through enumerated values135 referenceIds.remove(VisitorCommonFunctions.getIdFromIdentifier(identifierNode));136 String refs = "\n\t\t<reflist>";137 for (String id : referenceIds)138 refs += "\n\t\t\t<ref id=\"" + id + "\"/>";139 refs += "\n\t\t</reflist>";140 return refs;141 }142 143 private String getElementList(LocationAST node){144 //TODO: this should be a part of the printer145 String elementList = "\n\t\t<elementlist>";146 LinkedList <LocationAST> moduleDefinitionsList = ASTUtil.findTypeNodes(LocationAST.resolveParentsUntilType(node, TTCN3ParserTokenTypes.ModuleDefinition).getFirstChild(), TTCN3ParserTokenTypes.ModuleDefinition);147 for(LocationAST moduleDefinitionNode : moduleDefinitionsList){148 ArrayList<LocationAST> identifiersList = LocationAST.getModuleDefinitionIdentifiersList(moduleDefinitionNode);149 for(LocationAST identifierNode : identifiersList)150 elementList += "\n\t\t\t<ref id=\"" + VisitorCommonFunctions.getIdFromIdentifier(identifierNode) + "\"/>";151 }152 return elementList + "\n\t\t</elementlist>";153 }154 155 48 public ContinueStatus visitModuleDefinition(LocationAST node) throws TTCN3BehaviorException { 156 ArrayList<LocationAST> identifiersList = LocationAST.getModuleDefinitionIdentifiersList(node); 157 LocationAST typeNode = LocationAST.getModuleDefinitionTypeNode(node); 158 159 for (LocationAST identifierNode : identifiersList) { 160 if (typeNode.getType()==TTCN3ParserTokenTypes.GroupDef) { 161 dependencyPrinter.newGroup(VisitorCommonFunctions.getName(identifierNode), 162 VisitorCommonFunctions.getIdFromIdentifier(identifierNode.getFirstChild()), 163 typeNode.getType(), 164 identifierNode.getLine(), 165 VisitorCommonFunctions.getModuleName(identifierNode), 166 getElementList(identifierNode)); 167 }else { 168 dependencyPrinter.newElement(VisitorCommonFunctions.getName(identifierNode), 169 VisitorCommonFunctions.getIdFromIdentifier(identifierNode.getFirstChild()), 170 typeNode.getType(), 171 identifierNode.getLine(), 172 VisitorCommonFunctions.getModuleName(identifierNode), 173 getDependecies(identifierNode)); 174 } 175 } 176 49 dependencyPrinter.newElement(node); 177 50 return ContinueStatus.getInstance(true,true); 178 51 }
Note: See TracChangeset
for help on using the changeset viewer.