Changeset 193
- Timestamp:
- 10/19/09 18:13:56 (5 weeks ago)
- Location:
- trunk/cpp_analysis/src/xtc/lang/c4
- Files:
-
- 7 modified
-
C4.java (modified) (2 diffs)
-
C4Core.rats (modified) (1 diff)
-
C4Extractor.java (modified) (6 diffs)
-
C4MacrosManager.java (modified) (16 diffs)
-
C4State.java (modified) (1 diff)
-
CPPAnalyzer.java (modified) (143 diffs)
-
Makefile (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/cpp_analysis/src/xtc/lang/c4/C4.java
r183 r193 72 72 .word("extract", "optionExtract", 73 73 false, "Extract everything related to one configuration option") 74 .word("featureName", "optionFeatureName", 75 false, "The name of the feature that is going to be extracted") 74 76 .bool("DBResults", "dbResults", 75 77 false, "Store the Results of the analysis into a DB") … … 117 119 if(runtime.hasValue("optionExtract")) { 118 120 tmp.setExtract(runtime.getString("optionExtract")); 121 } 122 123 if(runtime.hasValue("optionFeatureName")) { 124 tmp.setFeatureName(runtime.getString("optionFeatureName")); 119 125 } 120 126 -
trunk/cpp_analysis/src/xtc/lang/c4/C4Core.rats
r186 r193 470 470 generic DirectDeclarator := 471 471 <NewFunction> DirectDeclarator void:"(":Symbol 472 PushScope ParameterTypeList473 void:")":Symbol ParameterContext472 {yyState.setInFunctionDecl();} PushScope ParameterTypeList 473 {yyState.unsetInFunctionDecl();} void:")":Symbol ParameterContext 474 474 @FunctionDeclarator 475 475 / <OldFunction> DirectDeclarator void:"(":Symbol -
trunk/cpp_analysis/src/xtc/lang/c4/C4Extractor.java
r131 r193 30 30 31 31 32 /** The Debug extraction Flag **/ 33 private boolean DBG_EXTRACT = false; 34 /** The feature to create **/ 35 private String featureName; 36 37 /** The Configuration option to extract **/ 38 private String configOption; 39 /** The list of nodes marked as to be extracted by the CPP Analyzer **/ 40 private ArrayList<C4Extractable> toExtract; 41 42 /** The original Tree before any extraction **/ 43 private Node tree; 44 /** The new Tree with everything extracted **/ 45 private Node newTree; 46 /** The name of the top level file to be extracted **/ 47 /** We do not extract anything from the included header files **/ 48 private String topLevel; 49 50 /** The collection of functionDefinitions extracted from the analysis 51 */ 52 private Map<String, GNode> functionDefinitions; 53 54 /** The collection of functionDefinitions after all the modification 55 * populated during the extraction process 56 */ 57 private Map<String, GNode> modifiedFunctionDefinitions; 58 59 private Node father; 60 61 public C4Extractor(String featureName, String optExtract, ArrayList<C4Extractable> toExtract, Node unit, String fileName, Map<String, GNode> functionDefinitions ) { 62 this.featureName = featureName; 63 configOption = optExtract; 64 this.toExtract = toExtract; 65 tree = unit; 66 topLevel = fileName; 67 this.functionDefinitions = functionDefinitions; 68 modifiedFunctionDefinitions = new HashMap<String, GNode> (); 69 } 70 71 32 72 static Node build(Formatting n, HashMap<Integer, Object> newChildren) { 33 73 Formatting result = null ; … … 65 105 } 66 106 67 68 /** The Debug extraction Flag **/69 private boolean DBG_EXTRACT = false;70 /** The Configuration option to extract **/71 private String configOption;72 /** The list of nodes marked as to be extracted by the CPP Analyzer **/73 private ArrayList<GNode> nodesToExtract;74 /** The original Tree before any extraction **/75 private Node tree;76 /** The new Tree with everything extracted **/77 private Node newTree;78 /** The name of the top level file to be extracted **/79 /** We do not extract anything from the included header files **/80 String topLevel;81 82 private Node father;83 84 public C4Extractor(String optExtract, ArrayList<GNode> toExtract, Node unit, String fileName ) {85 configOption = optExtract;86 nodesToExtract = toExtract;87 tree = unit;88 topLevel = fileName;89 90 }91 92 107 private Node extractVisitor(Node n) { 93 108 //Node modified = GNode.create((GNode)n); … … 111 126 Node child = (Node) n.get(i); 112 127 113 if( nodesToExtract.contains(child)) {128 if(isToBeExtracted(child)) { 114 129 if(DBG_EXTRACT) 115 130 System.out.println("We are going to remove child number : " + index); … … 164 179 165 180 if(n instanceof GNode) { 166 167 181 modified = GNode.create(name, newChildren.size()); 168 182 … … 172 186 modified.add(k, newChildren.get(bigK)); 173 187 } 188 189 if (name == "FunctionDefinition") { 190 //We look for the name of this function 191 if (functionDefinitions.containsValue(n)) { 192 for (String funcName: functionDefinitions.keySet()) { 193 if(functionDefinitions.get(funcName) == n) { 194 modifiedFunctionDefinitions.put(funcName, (GNode)modified); 195 } 196 } 197 } 198 } 199 174 200 } 175 201 else if( (n instanceof Formatting)) { … … 231 257 fne.printStackTrace(); 232 258 } 233 } 234 259 260 //Weaving 261 weave(newTree); 262 263 264 } 265 266 267 268 private ArrayList<C4Extractable> lookupToWeave(String funcName) { 269 ArrayList<C4Extractable> toWeave = new ArrayList<C4Extractable>(); 270 271 for(C4Extractable item : toExtract) { 272 if(item.getFuncName().equals(funcName)) { 273 toWeave.add(item); 274 } 275 } 276 return toWeave; 277 } 278 279 280 private void weave(Node newTree) { 281 Printer console = new Printer(new BufferedWriter(new OutputStreamWriter(System.out))); 282 new ParseTreePrinter(console).dispatch(tree); 283 System.out.println("\n\nABeforeEXTRACTION"); 284 console.format(newTree, false).pln().flush(); 285 286 287 new Visitor() { 288 public void visitFunctionDefinition(GNode n ) { 289 if (modifiedFunctionDefinitions.containsValue(n)) { 290 for (String funcName: modifiedFunctionDefinitions.keySet()) { 291 if(modifiedFunctionDefinitions.get(funcName) == n) { 292 ArrayList<C4Extractable> toWeave = lookupToWeave(funcName); 293 n.getGeneric(5).add(0,blockWrapping(toWeave)); 294 } 295 } 296 } 297 298 } 299 300 public void visit(Node n) { 301 for(int i=0; i < n.size(); i++) { 302 if(n.get(i) instanceof Node) { 303 dispatch(n.getNode(i)); 304 } 305 } 306 } 307 308 }.dispatch(newTree); 309 310 311 312 System.out.println("AFTER WEAVING PRINTER\n\n"); 313 new C4ParseTreePrinter(console).dispatch(newTree); 314 console.flush(); 315 System.out.println("\n#######\n"); 316 317 318 } 319 320 private boolean isToBeExtracted(Node n) { 321 for(C4Extractable toBeExtracted : toExtract) { 322 if(toBeExtracted.getGNodeToExtract() == n) { 323 return true; 324 } 325 } 326 327 return false; 328 } 329 330 private Node blockWrapping(ArrayList<C4Extractable> toWeave) { 331 GNode tmpGNodeBefore = GNode.create("RawFeatureBefore"); 332 GNode tmpGNodeAfter = GNode.create("RawFeatureAfter"); 333 334 for(C4Extractable item: toWeave) { 335 336 if(item.getKind().equals("before")) 337 tmpGNodeBefore.add(item.getGNodeToExtract()); 338 else if(item.getKind().equals("after")) 339 tmpGNodeAfter.add(item.getGNodeToExtract()); 340 341 } 342 343 GNode featureBlock = GNode.create("FeatureBlockStatement"); 344 345 if(tmpGNodeBefore.size() > 0) { 346 Formatting roundBefore = Formatting.round1(new Token("_before_" + featureName + " { \n\t"), tmpGNodeBefore,new Token("\n }\n")); 347 featureBlock.add(roundBefore); 348 } 349 if(tmpGNodeAfter.size() > 0) { 350 Formatting roundAfter = Formatting.round1(new Token("_after_" + featureName + " { \n\t"), tmpGNodeAfter,new Token("\n }\n")); 351 featureBlock.add(roundAfter); 352 } 353 354 return featureBlock; 355 356 } 235 357 } -
trunk/cpp_analysis/src/xtc/lang/c4/C4MacrosManager.java
r183 r193 16 16 17 17 /** A map of the object Macros **/ 18 private Map<String, Object> objectMacros;18 private Map<String, Node> objectMacros; 19 19 20 20 /** A map of the function Macros **/ 21 private Map<String, Object> functionMacros;21 private Map<String, Node> functionMacros; 22 22 23 23 /** A map of the various definition of removed Macros **/ 24 private Map<String, ArrayList<Object>> removedMacros; 24 /** Contains the complete story associated with this particular Macro **/ 25 private Map<String, ArrayList<Node>> oldDefinitionsMacros; 26 27 /** A map of the current definition of each macro defined **/ 28 private Map<String, Node> currentDefinitionMacros; 29 private Map<String, Integer> currentDefinitionIndex; 25 30 26 31 /** To remove all the macros defined in the previous branch...*/ 27 32 private ArrayList<ArrayList <String>> branchMacros; 28 private ArrayList<Map<String, Object>> branchMacrosFunction;29 private ArrayList<Map<String, Object>> branchMacrosObject;30 private Map<String, Object> lastBranchMacrosObject;31 private Map<String, Object> lastBranchMacrosFunction;33 private ArrayList<Map<String, Node>> branchMacrosFunction; 34 private ArrayList<Map<String, Node>> branchMacrosObject; 35 private Map<String, Node> lastBranchMacrosObject; 36 private Map<String, Node> lastBranchMacrosFunction; 32 37 private ArrayList<String> lastBranchMacros; 33 38 private ArrayList<String> macro_keyword_global; … … 40 45 41 46 public C4MacrosManager() { 42 this. removedMacros = new HashMap<String, ArrayList<Object>>();43 44 this.objectMacros = new HashMap<String, Object>();45 this.functionMacros = new HashMap<String, Object>();46 this.branchMacrosFunction = new ArrayList<Map<String, Object>>();47 this.branchMacrosObject = new ArrayList<Map<String, Object>>();47 this.oldDefinitionsMacros = new HashMap<String, ArrayList<Node>>(); 48 49 this.objectMacros = new HashMap<String, Node>(); 50 this.functionMacros = new HashMap<String, Node>(); 51 this.branchMacrosFunction = new ArrayList<Map<String, Node>>(); 52 this.branchMacrosObject = new ArrayList<Map<String, Node>>(); 48 53 this.branchMacros = new ArrayList<ArrayList<String>>(); 49 54 this.lastBranchMacros = new ArrayList<String>(); … … 75 80 String name = null; 76 81 82 77 83 if (objMacro.size() > 1) { 78 84 value = objMacro.getGeneric(1); … … 81 87 name = objMacro.getGeneric(0).getString(0); 82 88 } 83 89 90 91 if(!oldDefinitionsMacros.containsKey(name)) { 92 oldDefinitionsMacros.put(name, new ArrayList<Node>()); 93 } 94 95 oldDefinitionsMacros.get(name).add(value); 96 84 97 if ( this.lastBranchMacrosObject != null ) { 85 98 this.lastBranchMacrosObject.put(name,value); … … 100 113 */ 101 114 protected void addFunctionMacro(GNode funcMacro) { 102 115 String name = funcMacro.getString(0); 116 Node value = funcMacro; 117 118 if(!oldDefinitionsMacros.containsKey(name)) { 119 oldDefinitionsMacros.put(name, new ArrayList<Node>()); 120 } 121 122 oldDefinitionsMacros.get(name).add(value); 123 103 124 if( this.lastBranchMacrosFunction != null) { 104 this.lastBranchMacrosFunction.put(funcMacro.getString(0),funcMacro); 125 this.lastBranchMacrosFunction.put(name, value); 126 105 127 if( DBG_MM ) 106 128 System.out.println("@FM Putting Last " + funcMacro.getString(0) ); 107 129 } 108 130 else { 109 this.functionMacros.put(funcMacro.getString(0), funcMacro); 131 this.functionMacros.put(name, value); 132 110 133 if( DBG_MM ) 111 134 System.out.println("@FM Putting Functions " + funcMacro.getString(0) ); … … 135 158 136 159 if(null == lastBranchMacrosFunction) 137 lastBranchMacrosFunction = new HashMap<String, Object>();160 lastBranchMacrosFunction = new HashMap<String, Node>(); 138 161 else { 139 HashMap<String, Object> tmp = new HashMap<String, Object>();162 HashMap<String, Node> tmp = new HashMap<String, Node>(); 140 163 tmp.putAll(lastBranchMacrosFunction); 141 164 lastBranchMacrosFunction = tmp; … … 154 177 //TODO GETTING RID OF ALL THESE LAST BRANCHES AND BRANCHES AND NESTING 155 178 if(null == lastBranchMacrosObject) 156 lastBranchMacrosObject = new HashMap<String, Object>();179 lastBranchMacrosObject = new HashMap<String, Node>(); 157 180 else { 158 HashMap<String, Object> tmp = new HashMap<String, Object>();181 HashMap<String, Node> tmp = new HashMap<String, Node>(); 159 182 tmp.putAll(lastBranchMacrosObject); 160 183 lastBranchMacrosObject = tmp; … … 222 245 223 246 if(branchMacrosFunction.size()> 0 && branchMacrosObject.size()> 0) { 224 Map<String, Object> lastBranchMacrosFlushed;247 Map<String, Node> lastBranchMacrosFlushed; 225 248 226 249 lastBranchMacrosFlushed = branchMacrosObject.get(branchMacrosObject.size()-1); … … 317 340 return false; 318 341 if(om.getGeneric(0).getName().equals("ObjectMacroValueSupported")){ 319 if(om.getGeneric(0).get(0) instanceof GNode) { 342 if(om.getGeneric(0).get(0) instanceof Node) 343 if(om.getGeneric(0).getNode(0).strip() instanceof GNode) { 320 344 GNode potentialPrimaryId = om.getGeneric(0).getGeneric(0); 321 345 if(potentialPrimaryId.getName().equals("PrimaryIdentifier")) { … … 346 370 public void removeMacro(String macroName) { 347 371 if(isMacro(macroName)) { 348 if(!removedMacros.containsKey(macroName)) 349 removedMacros.put(macroName, new ArrayList<Object>()); 350 351 if(functionMacros.containsKey(macroName)) { 352 removedMacros.get(macroName).add(functionMacros.get(macroName)); 353 functionMacros.remove(macroName); 372 373 if(!oldDefinitionsMacros.containsKey(macroName)) 374 oldDefinitionsMacros.put(macroName, new ArrayList<Node>()); 375 376 if(isFunctionMacro(macroName)) { 377 if(lastBranchMacrosFunction != null) { 378 if(lastBranchMacrosFunction.containsKey(macroName)) { 379 //oldDefinitionsMacros.get(macroName).add(lastBranchMacrosFunction .get(macroName)); 380 lastBranchMacrosFunction.remove(macroName); 381 } 382 } 383 else if(functionMacros.containsKey(macroName)) { 384 //oldDefinitionsMacros.get(macroName).add(functionMacros.get(macroName)); 385 functionMacros.remove(macroName); 386 } 387 388 } else if(isObjectMacro(macroName)) { 389 if(lastBranchMacrosObject != null) { 390 if(lastBranchMacrosObject.containsKey(macroName)) { 391 //oldDefinitionsMacros.get(macroName).add(lastBranchMacrosObject .get(macroName)); 392 lastBranchMacrosObject.remove(macroName); 393 } 394 395 } 396 else if(objectMacros.containsKey(macroName)) { 397 //oldDefinitionsMacros.get(macroName).add(objectMacros.get(macroName)); 398 objectMacros.remove(macroName); 399 } 400 354 401 } 355 else if(objectMacros.containsKey(macroName)) {356 removedMacros.get(macroName).add(objectMacros.get(macroName));357 objectMacros.remove(macroName);358 }359 402 } 360 403 } … … 364 407 * Gets the map of the removed macros, removed by undef 365 408 */ 366 public Map<String, ArrayList< Object>> getRemovedMacros() {367 return removedMacros;409 public Map<String, ArrayList<Node>> getRemovedMacros() { 410 return oldDefinitionsMacros; 368 411 } 369 412 … … 407 450 isfuncMacro = (functionMacros.containsKey(macroName) || lastBranchMacrosFunction.containsKey(macroName)); 408 451 else isfuncMacro = (functionMacros.containsKey(macroName) ); 409 if( DBG_MM ) 452 453 if( DBG_MM ) 410 454 System.out.println("IS FUNCTION MACRO " + macroName + " ? " + isfuncMacro); 411 455 return isfuncMacro; … … 428 472 macroNode = getMacro(lastBranchMacrosFunction, macroName); 429 473 } 430 } 431 if(functionMacros.containsKey(macroName)) { 474 } else if(functionMacros.containsKey(macroName)) { 432 475 macroNode = getMacro(functionMacros, macroName); 433 476 } … … 437 480 macroNode = getMacro(lastBranchMacrosObject, macroName); 438 481 } 439 } 440 441 if(objectMacros.containsKey(macroName)) { 482 } else if(objectMacros.containsKey(macroName)) { 442 483 macroNode = getMacro(objectMacros, macroName); 443 484 } … … 452 493 * @return The node associated with the macroName 453 494 */ 454 public Node getMacro(Map<String, Object> macrosMap, String macroName) {455 return (Node)macrosMap.get(macroName);495 public Node getMacro(Map<String, Node> macrosMap, String macroName) { 496 return macrosMap.get(macroName); 456 497 } 457 498 … … 479 520 System.out.println('\t' + functionMacro); 480 521 } 522 523 524 public void updateDefine(String macroName) { 525 if(!currentDefinitionIndex.containsKey(macroName)){ 526 currentDefinitionIndex.put(macroName, 0); 527 } else { 528 currentDefinitionIndex.put(macroName, currentDefinitionIndex.get(macroName) + 1); 529 } 530 531 currentDefinitionMacros.put(macroName, oldDefinitionsMacros.get(macroName).get(0)); 532 } 533 534 public void undef(String macroName) { 535 //The macro that we undef is not defined 536 currentDefinitionMacros.put(macroName, null); 537 538 } 539 540 481 541 } -
trunk/cpp_analysis/src/xtc/lang/c4/C4State.java
r183 r193 1023 1023 1024 1024 if(inMacroFlag) { 1025 1025 1026 //We're in a Macro... The parameters could be types... 1026 1027 //TODO improve the parsing, to actually check whether all can be types... -
trunk/cpp_analysis/src/xtc/lang/c4/CPPAnalyzer.java
r183 r193 64 64 65 65 /** The debug level. */ 66 private static final int DEBUG = 1;66 private static final int DEBUG = 0; 67 67 68 68 /** The overall initializer list. */ … … 201 201 // Clear the saved states. We are starting with the overall 202 202 // type. 203 if (0 != states.size()) {203 if (0 != states.size()) { 204 204 final State state = states.get(0); 205 205 base = state.base; … … 390 390 391 391 try { 392 393 for (VariableT member : base.toStructOrUnion().getMembers()) {392 393 for (VariableT member : base.toStructOrUnion().getMembers()) { 394 394 if (member.hasName()) { 395 395 index++; … … 411 411 412 412 } catch (NullPointerException e) { 413 e.printStackTrace();414 return false;413 e.printStackTrace(); 414 return false; 415 415 } 416 416 … … 739 739 try { 740 740 Node n = (Node) o; 741 dispatch(n);741 dispatch(n); 742 742 } catch (ClassCastException cce) { 743 cce.printStackTrace();743 cce.printStackTrace(); 744 744 continue; 745 745 } … … 1113 1113 .bigIntValue(); 1114 1114 } catch (IllegalStateException x) { 1115 x.printStackTrace();1116 widthValue = BigInteger.ZERO;1115 x.printStackTrace(); 1116 widthValue = BigInteger.ZERO; 1117 1117 } 1118 1118 … … 1293 1293 } else { 1294 1294 String tag = null; 1295 try {1296 tag = n.getString(1);1297 } catch (Exception e) {1298 tag = null;1299 }1300 1301 String name;1295 try { 1296 tag = n.getString(1); 1297 } catch (Exception e) { 1298 tag = null; 1299 } 1300 1301 String name; 1302 1302 if (null == tag) { 1303 1303 tag = table.freshName("tag"); … … 1310 1310 1311 1311 if (!t.isEnum()) { 1312 reportPreviousTag(t);1313 1312 type = ErrorT.TYPE; 1314 1313 return; 1315 1314 1316 1315 } else if (null != t.toTagged().getMembers()) { 1317 reportPreviousTag(t);1318 1316 type = ErrorT.TYPE; 1319 1317 return; … … 1364 1362 lastValue = value; 1365 1363 } catch (IllegalStateException x) { 1366 x.printStackTrace();1367 value = lastValue.add(BigInteger.ONE);1364 x.printStackTrace(); 1365 value = lastValue.add(BigInteger.ONE); 1368 1366 lastValue = value; 1369 1367 } … … 1457 1455 1458 1456 if (!t.isEnum()) { 1459 reportPreviousTag(t);1460 1457 type = ErrorT.TYPE; 1461 1458 return; … … 1623 1620 multipleTypes(); 1624 1621 } else { 1625 1626 String tag = null;1627 try {1628 tag = n.getString(1);1629 } catch (Exception e) {1630 tag = null;1631 }1622 1623 String tag = null; 1624 try { 1625 tag = n.getString(1); 1626 } catch (Exception e) { 1627 tag = null; 1628 } 1632 1629 String name; 1633 1630 if (null == tag) { … … 1641 1638 1642 1639 if (!t.isStruct()) { 1643 reportPreviousTag(t);1644 1640 type = ErrorT.TYPE; 1645 1641 return; 1646 1642 1647 1643 } else if (null != t.toTagged().getMembers()) { 1648 reportPreviousTag(t);1649 1644 type = ErrorT.TYPE; 1650 1645 return; … … 1708 1703 1709 1704 if (!t.isStruct()) { 1710 reportPreviousTag(t);1711 1705 type = ErrorT.TYPE; 1712 1706 return; … … 1752 1746 final String name = n.getString(0); 1753 1747 final Type value = (Type) table.current().lookup(name); 1754 if ((null != value) && value.isAlias()) {1748 if ((null != value) && value.isAlias()) { 1755 1749 type = value; 1756 1750 } else { … … 1789 1783 multipleTypes(); 1790 1784 } else { 1791 1792 String tag = null;1793 try{1794 tag = n.getString(1);1795 } catch(NullPointerException e) {1796 tag = null;1797 }1798 1799 String name;1785 1786 String tag = null; 1787 try{ 1788 tag = n.getString(1); 1789 } catch(NullPointerException e) { 1790 tag = null; 1791 } 1792 1793 String name; 1800 1794 if (null == tag) { 1801 1795 tag = table.freshName("tag"); … … 1808 1802 1809 1803 if (!t.isUnion()) { 1810 reportPreviousTag(t);1811 1804 type = ErrorT.TYPE; 1812 1805 return; 1813 1806 1814 1807 } else if (null != t.toTagged().getMembers()) { 1815 reportPreviousTag(t);1816 1808 type = ErrorT.TYPE; 1817 1809 return; … … 1846 1838 // defined attribute to protected against nested redefinition. 1847 1839 type.addAttribute(Constants.ATT_DEFINED); 1848 List<VariableT> members = processMembers(n.getGeneric(2), false);1840 List<VariableT> members = processMembers(n.getGeneric(2), false); 1849 1841 type.toUnion().setMembers(members); 1850 1842 type.removeAttribute(Constants.ATT_DEFINED); … … 1871 1863 1872 1864 if (!t.isUnion()) { 1873 reportPreviousTag(t);1874 1865 type = ErrorT.TYPE; 1875 1866 return; … … 2110 2101 /** The flag to know whether we are in a left-Hand Side context */ 2111 2102 private boolean leftHandSide; 2112 2103 2113 2104 /** The flag to know whether we are in a Right-Hand Side context */ 2114 2105 private boolean rightHandSide; 2115 2106 2107 /** The flag to know whether we are in a Right-Hand Side context */ 2108 private boolean insideTest; 2109 2116 2110 /** The flag to know whether we are in a leftHandSide context */ 2117 2111 private boolean unaryModifier; 2118 2112 2113 /** The name of the function Definition currently visited */ 2114 private String functionDefinitionName; 2119 2115 /** 2120 2116 * A stack containing the nesting for all the conditions. … … 2169 2165 private String extract; 2170 2166 2167 /** String representing the configuration Option to remove **/ 2168 private String featureName = "anonymous"; 2169 2170 2171 2171 /** Flag to tell whether the location referencing configuration options 2172 2172 * should be logged or not … … 2174 2174 private boolean logLocation; 2175 2175 2176 /** List of the nodes to be extracted, to avoid retraversing to extract **/ 2177 private ArrayList<GNode> toExtract; 2176 /** List of the nodes to be extracted, to avoid retraversing to extract 2177 * Each element of the ArrayList is a Triple with the name of the function 2178 * definition from which to extract, the Node to extract and the string before or after 2179 * string **/ 2180 2181 private ArrayList<C4Extractable> toExtract; 2178 2182 2179 2183 /** List of the header file currently visited … … 2200 2204 public void setExtract(String extract) { 2201 2205 this.extract = extract; 2206 } 2207 2208 /** Sets the name of the feature to create **/ 2209 public void setFeatureName(String featureName) { 2210 if(featureName != null) 2211 this.featureName = featureName; 2202 2212 } 2203 2213 … … 2374 2384 2375 2385 public void visit(Node n) { 2376 table.enter(n);2386 table.enter(n); 2377 2387 for (Object o : n) { 2378 2388 if (o instanceof Node) dispatch((Node)o); … … 2603 2613 //Extraction 2604 2614 if(null != extract && atTopLevelFile()) { 2605 C4Extractor tmpExtractor = new C4Extractor( extract, toExtract, unit, fileName);2615 C4Extractor tmpExtractor = new C4Extractor(featureName, extract, toExtract, unit, fileName, functionDefinitions); 2606 2616 tmpExtractor.extract(); 2607 2617 } … … 2645 2655 2646 2656 public void visit(Node n) { 2647 table.enter(n);2657 table.enter(n); 2648 2658 for (Object o : n) { 2649 2659 if (o instanceof Node) dispatch((Node)o); … … 2793 2803 || type.resolve().isFunction() != previous.resolve() 2794 2804 .isFunction()) { 2795 //runtime.error("'" + name2796 // + "' redeclared as different kind of symbol", decl);2797 reportPrevious(name, previous);2798 2805 return ErrorT.TYPE; 2799 2806 } … … 2812 2819 2813 2820 if (composite.isError()) { 2814 if (previous.hasAttribute(Constants.ATT_BUILTIN)2815 && previous.resolve().isFunction()) {2816 // runtime.error("conflicting types for built-in function '" +2817 // name + "'",2818 // decl);2819 } else {2820 // runtime.error("conflicting types for '" + name + "'", decl);2821 reportPrevious(name, previous);2822 }2823 2821 return ErrorT.TYPE; 2824 2825 2822 } else if (!c().hasSameQualifiers(type, previous)) { 2826 // runtime.error("conflicting type qualifiers for '" + name + "'",2827 // decl);2828 reportPrevious(name, previous);2829 2823 return ErrorT.TYPE; 2830 2824 } … … 2845 2839 final Scope current = table.current(); 2846 2840 table.setScope(table.root()); 2847 table.enter(EXTERN_SCOPE);2841 table.enter(EXTERN_SCOPE); 2848 2842 scope = table.current(); 2849 2843 table.setScope(current); … … 3047 3041 value = size.getConstant().bigIntValue(); 3048 3042 } catch (IllegalStateException x) { 3049 x.printStackTrace();3050 final GNode id = getDeclaredId(decl);3043 x.printStackTrace(); 3044 final GNode id = getDeclaredId(decl); 3051 3045 if (null == id) { 3052 3046 // runtime.warning("can't compute size of array", … … 3245 3239 // Enter a temporary scope so that variable length arrays can 3246 3240 // reference previously declared parameters. 3247 table.enter(TMP_SCOPE);3241 table.enter(TMP_SCOPE); 3248 3242 3249 3243 // A new-style parameter type list. … … 3329 3323 3330 3324 // Exit the temporary scope and delete it again. 3331 table.exit();3325 table.exit(); 3332 3326 3333 3327 table.delete(TMP_SCOPE); … … 3365 3359 } 3366 3360 3367 private ArrayList<String> mergeMarked(Stack<ArrayList<String>> markedStack) {3368 //We merge the various in the markedConfigOptionStack3361 private ArrayList<String> mergeMarked(Stack<ArrayList<String>> markedStack) { 3362 //We merge the various in the markedConfigOptionStack 3369 3363 ArrayList<String> result = new ArrayList<String>(); 3370 for(ArrayList<String> marked: markedConfigOptionsStack) {3371 result.addAll(marked);3372 }3373 return result;3374 }3375 3376 3377 public ArrayList<String> pushMarkedConfigOptions(GNode ifSection) {3378 ArrayList<String> merged;3379 ArrayList<String> newlyMarked = markConfigOptions(ifSection);3380 markedConfigOptionsStack.push(newlyMarked);3381 merged = mergeMarked(markedConfigOptionsStack);3382 return merged;3383 }3384 3385 public ArrayList<String> popMarkedConfigOptions() {3386 ArrayList<String> merged;3387 markedConfigOptionsStack.pop();3388 merged = mergeMarked(markedConfigOptionsStack);3389 3390 return merged;3391 }3364 for(ArrayList<String> marked: markedConfigOptionsStack) { 3365 result.addAll(marked); 3366 } 3367 return result; 3368 } 3369 3370 3371 public ArrayList<String> pushMarkedConfigOptions(GNode ifSection) { 3372 ArrayList<String> merged; 3373 ArrayList<String> newlyMarked = markConfigOptions(ifSection); 3374 markedConfigOptionsStack.push(newlyMarked); 3375 merged = mergeMarked(markedConfigOptionsStack); 3376 return merged; 3377 } 3378 3379 public ArrayList<String> popMarkedConfigOptions() { 3380 ArrayList<String> merged; 3381 markedConfigOptionsStack.pop(); 3382 merged = mergeMarked(markedConfigOptionsStack); 3383 3384 return merged; 3385 } 3392 3386 /** 3393 3387 * Mark the config Options that define the parsed branch of an IfSection. … … 3409 3403 + elIfn.get(0)); 3410 3404 } 3411 3405 3412 3406 if (elIfn.getGeneric(1).getName() != "Unparsed") { 3413 3407 //This condition holds 3414 GNode tmp = elIfn.getGeneric(0);3415 new Visitor() {3416 3417 Stack <Boolean> negationContext = new Stack<Boolean>();3418 boolean tmpNegCont = false;3419 Boolean tmp = negationContext.push(new Boolean(false));3420 public void visitDefinedExpression(GNode n) {3421 if(configOptions.contains(n.getString(0)) && !tmpNegCont) {3422 //If this is a config option3423 tmpConfigOptions.add(n.getString(0));3424 }3425 }3426 3427 public void visitIfGroupNegationExpression(GNode n) {3428 //XOR3429 tmpNegCont = tmpNegCont ^ true;3430 negationContext.push(new Boolean(tmpNegCont));3431 //We dispatch the expression negated3432 dispatch(n.getGeneric(1));3433 tmpNegCont = negationContext.pop();3434 }3435 3436 public void visit(GNode n) {3437 for (int i = 0; i < n.size(); i++) {3438 if(n.get(i) instanceof Node){3439 if( n.getNode(i).strip() instanceof GNode)3440 dispatch(n.getGeneric(i));3441 }3442 }3443 }3444 3445 public void visitIfGroupExpression(GNode n) {3446 dispatch(n.getGeneric(0));3447 }3448 3449 }.dispatch(tmp);3408 GNode tmp = elIfn.getGeneric(0); 3409 new Visitor() { 3410 3411 Stack <Boolean> negationContext = new Stack<Boolean>(); 3412 boolean tmpNegCont = false; 3413 Boolean tmp = negationContext.push(new Boolean(false)); 3414 public void visitDefinedExpression(GNode n) { 3415 if(configOptions.contains(n.getString(0)) && !tmpNegCont) { 3416 //If this is a config option 3417 tmpConfigOptions.add(n.getString(0)); 3418 } 3419 } 3420 3421 public void visitIfGroupNegationExpression(GNode n) { 3422 //XOR 3423 tmpNegCont = tmpNegCont ^ true; 3424 negationContext.push(new Boolean(tmpNegCont)); 3425 //We dispatch the expression negated 3426 dispatch(n.getGeneric(1)); 3427 tmpNegCont = negationContext.pop(); 3428 } 3429 3430 public void visit(GNode n) { 3431 for (int i = 0; i < n.size(); i++) { 3432 if(n.get(i) instanceof Node){ 3433 if( n.getNode(i).strip() instanceof GNode) 3434 dispatch(n.getGeneric(i)); 3435 } 3436 } 3437 } 3438 3439 public void visitIfGroupExpression(GNode n) { 3440 dispatch(n.getGeneric(0)); 3441 } 3442 3443 }.dispatch(tmp); 3450 3444 } 3451 3445 } … … 3456 3450 + elsen.get(0)); 3457 3451 } 3458 if (elsen.getGeneric(0).getName() != "Unparsed") {3452 if (elsen.getGeneric(0).getName() != "Unparsed") { 3459 3453 //This condition holds. 3460 3454 //All the previously NDef configOptions are now defined 3461 tmpConfigOptions.clear();3455 tmpConfigOptions.clear(); 3462 3456 tmpConfigOptions.addAll(tmpNDefConfigOptions); 3463 3457 } … … 3474 3468 if (ifn.getGeneric(1).getName() != "Unparsed") { 3475 3469 //This condition holds 3476 GNode tmp = ifn.getGeneric(0);3477 new Visitor() {3478 3479 Stack <Boolean> negationContext = new Stack<Boolean>();3480 boolean tmpNegCont = false;3481 Boolean tmp = negationContext.push(new Boolean(false));3482 3483 public void visitDefinedExpression(GNode n) {3484 if(configOptions.contains(n.getString(0)) && !tmpNegCont) {3485 //If this is a config option3486 tmpConfigOptions.add(n.getString(0));3487 }3488 }3489 3490 public void visitIfGroupNegationExpression(GNode n) {3491 //XOR3492 tmpNegCont = tmpNegCont ^ true;3493 negationContext.push(new Boolean(tmpNegCont));3494 //We dispatch the expression negated3495 dispatch(n.getGeneric(1));3496 tmpNegCont = negationContext.pop();3497 }3498 3499 public void visit(GNode n) {3500 for (int i = 0; i < n.size(); i++) {3501 if(n.get(i) instanceof Node)3502 if( n.getNode(i).strip() instanceof GNode)3503 dispatch(n.getGeneric(i));3504 }3505 }3506 3507 public void visitIfGroupExpression(GNode n) {3508 dispatch(n.getGeneric(0));3509 }3510 3511 }.dispatch(tmp);3470 GNode tmp = ifn.getGeneric(0); 3471 new Visitor() { 3472 3473 Stack <Boolean> negationContext = new Stack<Boolean>(); 3474 boolean tmpNegCont = false; 3475 Boolean tmp = negationContext.push(new Boolean(false)); 3476 3477 public void visitDefinedExpression(GNode n) { 3478 if(configOptions.contains(n.getString(0)) && !tmpNegCont) { 3479 //If this is a config option 3480 tmpConfigOptions.add(n.getString(0)); 3481 } 3482 } 3483 3484 public void visitIfGroupNegationExpression(GNode n) { 3485 //XOR 3486 tmpNegCont = tmpNegCont ^ true; 3487 negationContext.push(new Boolean(tmpNegCont)); 3488 //We dispatch the expression negated 3489 dispatch(n.getGeneric(1)); 3490 tmpNegCont = negationContext.pop(); 3491 } 3492 3493 public void visit(GNode n) { 3494 for (int i = 0; i < n.size(); i++) { 3495 if(n.get(i) instanceof Node) 3496 if( n.getNode(i).strip() instanceof GNode) 3497 dispatch(n.getGeneric(i)); 3498 } 3499 } 3500 3501 public void visitIfGroupExpression(GNode n) { 3502 dispatch(n.getGeneric(0)); 3503 } 3504 3505 }.dispatch(tmp); 3512 3506 } 3513 3507 … … 3547 3541 3548 3542 }.dispatch(ifSection); 3549 3550 return markedConfigOptionsTMP;3543 3544 return markedConfigOptionsTMP; 3551 3545 3552 3546 } … … 3625 3619 condition 3626 3620 .add("Defined(" + ifDefn.getString(0) + ")"); 3627 3621 3628 3622 if (ifDefn.getGeneric(1).getName() != "Unparsed") 3629 3623 parsed = ifDefn.getGeneric(1); … … 3637 3631 condition.add("NotDefined(" + ifNDefn.getString(0) 3638 3632 + ")"); 3639 3633 3640 3634 3641 3635 if (ifNDefn.getGeneric(1).getName() != "Unparsed") … … 3647 3641 dispatch(ifSection.getGeneric(i)); 3648 3642 } 3649 3650 return new Pair<GNode, String>(parsed, condition.get(condition.size() -1 ));3643 3644 return new Pair<GNode, String>(parsed, condition.get(condition.size() -1 )); 3651 3645 } 3652 3646 }.dispatch(ifSection); 3653 3647 3654 3648 return parsedNodeAndCondition; 3655 3649 … … 3667 3661 ifsNode = new ArrayList<GNode>(); 3668 3662 loopsNode = new ArrayList<GNode>(); 3669 toExtract = new ArrayList< GNode>();3663 toExtract = new ArrayList<C4Extractable>(); 3670 3664 functionDefinitions = new HashMap<String, GNode>(); 3671 3665 markedConfigOptionsStack = new Stack<ArrayList<String>>(); … … 3708 3702 if(functionBody != null) { 3709 3703 index = functionBody.indexOf(node); 3704 3710 3705 if(index == (functionBody.size() - 2)){// at the end of a function 3711 3706 result = true; 3712 3707 } else if (index == -1) { // We have not found the object as is 3713 if(functionBody.get (functionBody.size() - 2) instanceof GNode) {3708 if(functionBody.getNode(functionBody.size() - 2 ).strip() instanceof GNode) { 3714 3709 GNode tmpGNode = functionBody.getGeneric(functionBody.size()- 2 ); 3715 3710 while(tmpGNode.size() == 1 || tmpGNode == node) { 3716 3711 3717 3712 if(tmpGNode == node) { 3718 3713 result = true; 3719 3714 } 3720 3715 3721 3716 if( tmpGNode.get(0) instanceof GNode){ 3722 tmpGNode = tmpGNode.getGeneric(0); 3723 } else { 3717 tmpGNode = tmpGNode.getGeneric(0); 3718 } else if (tmpGNode.get(0) instanceof Node) { 3719 if (tmpGNode.getNode(0).strip() instanceof GNode) 3720 tmpGNode = tmpGNode.getGeneric(0); 3721 else 3722 break; 3723 } 3724 else { 3724 3725 break; 3725 3726 } 3726 3727 } 3727 3728 } 3728 3729 3729 3730 3730 3731 } else if (functionBody.getGeneric(index+1).getName() == "ReturnStatement") { //just before a return … … 3732 3733 } 3733 3734 } 3734 3735 3735 3736 return result; 3736 3737 } … … 3911 3912 private HashMap<String, Boolean> isMovableAfterConditionally( 3912 3913 final GNode functionCall, String condFuncName, 3913 final GNode functionDefinition, final Node args ) {3914 final GNode functionDefinition, final Node args, final boolean inFuncBody) { 3914 3915 setCondMovable(true); 3915 3916 final GNode declarator = functionDefinition.getGeneric(2); … … 3936 3937 public void visit(GNode n) { 3937 3938 if (n.size() > 0) { 3938 if (n.get(0) instanceof GNode) 3939 dispatch((GNode) n.get(0)); 3939 for( int i = 0; i< n.size(); i++) { 3940 if (n.get(i) instanceof GNode){ 3941 dispatch(n.getGeneric(i)); 3942 } 3943 else if(n.get(i) instanceof Node) { 3944 if(n.getNode(i).strip() instanceof GNode) 3945 dispatch(n.getGeneric(i)); 3946 } 3947 } 3940 3948 } 3941 3949 } … … 3957 3965 if (n == functionCall) { 3958 3966 flag = true; 3959 new Visitor() {3967 new Visitor() { 3960 3968 public void visit(GNode n) { 3961 3969 final int size = n.size(); 3962 3970 for (int i = 0; i < size; i++) { 3963 if (n.get(i) instanceof GNode){3964 try {3965 dispatch((Node) n.get(i));3966 } catch(Exception e) {3967 System.out.println("Problem with this node "+ n.get(i));3968 e.printStackTrace();3969 }3970 }3971 }3971 if (n.get(i) instanceof GNode){ 3972 try { 3973 dispatch((Node) n.get(i)); 3974 } catch(Exception e) { 3975 System.out.println("Problem with this node "+ n.get(i)); 3976 e.printStackTrace(); 3977 } 3978 } 3979 } 3972 3980 } 3973 3981 … … 3983 3991 for (int i = 0; i < size; i++) { 3984 3992 if (n.get(i) instanceof Node) 3985 dispatch((Node) n.get(i)); 3993 if(n.getNode(i).strip() instanceof GNode) 3994 dispatch((Node) n.getGeneric(i)); 3986 3995 } 3987 3996 } … … 4001 4010 isMovableTmpMap.put( 4002 4011 "FunctionDefinition:" + n.getLocation(), 4003 new Boolean(isMovable ));4012 new Boolean(isMovable && inFuncBody)); 4004 4013 return isMovableTmpMap; 4005 4014 … … 4027 4036 // after this return 4028 4037 isMovableTmpMap.put("Return:" + n.getLocation(), 4029 new Boolean(isMovable ));4038 new Boolean(isMovable && inFuncBody)); 4030 4039 } 4031 4040 … … 4048 4057 @SuppressWarnings( { "unused", "unchecked" }) 4049 4058 private HashMap<String, Boolean> isMovableAfterFunctionMacroRef( 4050 final Node macroref, final ArrayList<String> idsInMacro ) {4059 final Node macroref, final ArrayList<String> idsInMacro, final boolean inFuncBody) { 4051 4060 HashMap<String, Boolean> result = null; 4052 4061 4053 4062 if (funcDef != null) { 4054 4055 4063 result = (HashMap<String, Boolean>) new Visitor() { 4056 4064 boolean isMovable = true; … … 4064 4072 for (int i = 0; i < n.size(); i++) { 4065 4073 if (n.get(i) instanceof GNode){ 4066 dispatch(n.getGeneric(i));4067 }4074 dispatch(n.getGeneric(i)); 4075 } 4068 4076 else if (n.get(i) != null) { 4069 if(n.get(i) instanceof Node)4070 dispatch((Node)n.get(i));4071 if(1 <= DEBUG)4077 if(n.get(i) instanceof Node) 4078 dispatch((Node)n.get(i)); 4079 if(1 <= DEBUG) 4072 4080 System.out.println("IsMovableAfterFunctionMacroRef " + n.get(i).getClass()); 4073 4081 } … … 4089 4097 4090 4098 public HashMap<String, Boolean> visitFunctionDefinition(GNode n) { 4091 dispatch(n.getGeneric(5));4092 4093 if(!flag)4094 System.out.println("NO FLAG SET Macro " + macroref + " LOC " + macroref.getLocation());4095 isMovableTmpMap.put("FunctionDefinition:" + n.getLocation(),4096 new Boolean(isMovable ));4099 dispatch(n.getGeneric(5)); 4100 4101 if(!flag) 4102 System.out.println("NO FLAG SET Macro " + macroref + " LOC " + macroref.getLocation()); 4103 isMovableTmpMap.put("FunctionDefinition:" + n.getLocation(), 4104 new Boolean(isMovable && inFuncBody)); 4097 4105 4098 4106 return isMovableTmpMap; … … 4109 4117 } 4110 4118 } 4111 4112 public void visitFunctionMacroCallStatement(GNode n) {4113 if(n == macroref) {4114 flag = true;4115 }4116 }4119 4120 public void visitFunctionMacroCallStatement(GNode n) { 4121 if(n == macroref) { 4122 flag = true; 4123 } 4124 } 4117 4125 4118 4126 public void visitMacroFunctionExpression(GNode n) { … … 4123 4131 4124 4132 public void visitMacroReference(GNode n) { 4125 if (n == macroref) {4133 if (n == macroref) { 4126 4134 flag = true; 4127 4135 } … … 4137 4145 isMovable = false; 4138 4146 } 4147 4139 4148 if (1 <= DEBUG) 4140 4149 System.out.println(" FLAG Section " + n.getString(0) … … 4150 4159 // this return 4151 4160 isMovableTmpMap.put("Return:" + n.getLocation(), new Boolean( 4152 isMovable ));4161 isMovable && inFuncBody)); 4153 4162 } 4154 4163 … … 4275 4284 4276 4285 new Visitor() { 4277 /* public void visit(Node n) {4278 4286 /* public void visit(Node n) { 4287 4279 4288 }*/ 4280 4289 public void visit(Node n) { 4281 final int size = n.size();4290 final int size = n.size(); 4282 4291 for (int i = 0; i < size; i++) { 4283 if(n.get(i) instanceof Node)4284 dispatch((Node) n.get(i));4285 }4292 if(n.get(i) instanceof Node) 4293 dispatch((Node) n.get(i)); 4294 } 4286 4295 } 4287 4296 4288 4297 public void visitPrimaryIdentifier(GNode n) { 4289 // Test for global variables in this function definition4298 // Test for global variables in this function definition 4290 4299 if (table.current().lookupScope(n.getString(0)) != null) { 4291 4300 if (table.current().lookupScope(n.getString(0)) … … 4298 4307 // Test for the parameters of the function 4299 4308 Scope callerScope = table.current(); 4300 table.enter(C4SymbolTable.toFunctionScopeName(functionName));4309 table.enter(C4SymbolTable.toFunctionScopeName(functionName)); 4301 4310 Scope funcScope = table.current(); 4302 4311 … … 5220 5229 } 5221 5230 5222 /* 5223 * if (parameters.size() == function.getParameters().size()) { 5224 * final int size = parameters.size(); for (int i = 0; i < size; 5225 * i++) { final Type t1 = (Type) table.current().lookupLocally( 5226 * (String) parameters.get(i)); final Type t2 = 5227 * function.getParameters().get(i); 5228 * 5229 * if (t1.hasError() || t2.hasError()) { // Ignore. } else if 5230 * (c().compose(t2, c().promoteArgument(t1), 5231 * pedantic).isError()) { // runtime.error("argument '" // + 5232 * t1.toVariable().getName() // + "' doesn't match prototype", 5233 * node); } else if (pedantic && !c().hasSameQualifiers(t2, t1)) 5234 * { // C99 6.7.5.3 15 // 5235 * runtime.error("type qualifiers of argument '" // + 5236 * t1.toVariable().getName() // + "' don't match prototype", 5237 * node); } } } 5238 */ 5231 5239 5232 } 5240 5233 … … 5437 5430 add(index.getConstant().bigIntValue()); 5438 5431 } catch (IllegalStateException x) { 5439 x.printStackTrace();5440 ref = new StaticReference(ptr1);5432 x.printStackTrace(); 5433 ref = new StaticReference(ptr1); 5441 5434 } 5442 5435 } else { … … 5453 5446 return ErrorT.TYPE; 5454 5447 } 5455 }5456 5457 /**5458 * Report a previous declaration or definition. If the specified5459 * type has a location, this method prints that location as a5460 * previous declaration or definition.5461 *5462 * @param name The name.5463 * @param type The type.5464 */5465 public void reportPrevious(String name, Type type) {5466 // If the type has a location, print the error message.5467 /*5468 if (type.hasLocation()) {5469 runtime.errConsole().loc(type).5470 p(": error: previous ");5471 if (type.hasAttribute(Constants.ATT_MACRO) ||5472 type.hasAttribute(Constants.ATT_DEFINED)) {5473 runtime.errConsole().p("definition");5474 } else {5475 runtime.errConsole().p("declaration");5476 }5477 runtime.errConsole().p(" of '").p(name).pln("' was here").flush();5478 }5479 */5480 }5481 5482 /**5483 * Report a previous declaration or definition of the specified5484 * tagged type. If the specified type has a location, this method5485 * prints that location as a previous declaration or definition.5486 *5487 * @param type The type.5488 */5489 public void reportPreviousTag(Type type) {5490 /*5491 final Tagged tag = type.toTagged();5492 5493 if (type.hasLocation()) {5494 runtime.errConsole().loc(type).5495 p(": error: previous ");5496 if (null != tag.getMembers()) {5497 runtime.errConsole().p("definition");5498 } else {5499 runtime.errConsole().p("declaration");5500 }5501 runtime.errConsole().p(" of '").p(tag.getName()).p("' was here").flush();5502 }5503 */5504 5448 } 5505 5449 … … 5522 5466 if (macroDefinition.getGeneric(1) != null) { // FunctionMacroParameters 5523 5467 if (macroDefinition.getGeneric(1).get(0) != null) { // CPPIdentifierList 5524 if ((macroDefinition.getGeneric(1).get(0) instanceof Node) && (macroDefinition.getGeneric(1).getGeneric(0) != null)) { 5525 for (int i = 0; i < macroDefinition.getGeneric(1).getGeneric( 5526 0).size(); i++) {// Functions Parameters 5527 if (macroDefinition.getGeneric(1).getGeneric(0).getName() 5528 .equals("CPPIdentifierList")) { 5529 try { 5530 formalParameters 5531 .add(macroDefinition 5532 .getGeneric(1).getGeneric(0).getString( 5533 i)); 5534 } catch (ClassCastException cce) { 5535 cce.printStackTrace(); 5536 formalParameters 5537 .add("Unsupported Parameter"); 5538 } 5539 } else if (macroDefinition.getGeneric(1).getGeneric(0) 5540 .getName() 5541 .equals("VariadicMacroParameters")) { 5542 for (int j = 0; j < macroDefinition.getGeneric(1) 5543 .getGeneric(0).size(); j++) 5544 if (macroDefinition.getGeneric(1).getGeneric(0) 5545 .get(j) instanceof String) { 5546 formalParameters 5547 .add((String) macroDefinition 5548 .getGeneric(1).getGeneric(0) 5549 .get(j)); 5550 } else if (macroDefinition.getGeneric(1) 5551 .getGeneric(0).get(j) instanceof GNode) { 5552 formalParameters 5553 .add((String) macroDefinition 5468 if (macroDefinition.getGeneric(1).get(0) instanceof Node) { 5469 if (macroDefinition.getGeneric(1).getNode(0).strip() != null) { 5470 //System.out.println("NULL AFTER STRIP " + macroDefinition.getGeneric(1).getNode(0)); 5471 //System.out.println("MACRODEF GET GEN 1" + macroDefinition.getGeneric(1)); 5472 //System.out.println("MACRODEF GET GEN 1STRIPPED " + macroDefinition.getGeneric(1).strip()); 5473 //System.out.println("MACRO GETGENERIC " + macroDefinition.getGeneric(1).size()); 5474 // System.exit(-1); 5475 5476 // else 5477 if (macroDefinition.getGeneric(1).getNode(0).strip().isGeneric()) { 5478 if (macroDefinition.getGeneric(1).getGeneric(0) != null) { 5479 for (int i = 0; i < macroDefinition.getGeneric(1).getGeneric( 5480 0).size(); i++) {// Functions Parameters 5481 5482 if (macroDefinition.getGeneric(1).getGeneric(0).getName() 5483 .equals("CPPIdentifierList")) { 5484 try { 5485 formalParameters 5486 .add(macroDefinition 5487 .getGeneric(1).getGeneric(0).getString( 5488 i)); 5489 } catch (ClassCastException cce) { 5490 cce.printStackTrace(); 5491 formalParameters 5492 .add("Unsupported Parameter"); 5493 } 5494 } else if (macroDefinition.getGeneric(1).getGeneric(0) 5495 .getName() 5496 .equals("VariadicMacroParameters")) { 5497 for (int j = 0; j < macroDefinition.getGeneric(1) 5498 .getGeneric(0).size(); j++) { 5499 if (macroDefinition.getGeneric(1).getGeneric(0) 5500 .get(j) instanceof String) { 5501 formalParameters 5502 .add(macroDefinition 5503 .getGeneric(1).getGeneric(0) 5504 .getString(j)); 5505 } else { 5506 /* 5507 if (macroDefinition.getGeneric(1) 5508 .getGeneric(0) instanceof Node) { 5509 if (macroDefinition.getGeneric(1).getGeneric(0) 5510 .get 5511 5512 }*/ 5513 5514 if (macroDefinition.getGeneric(1) 5515 .getGeneric(0).getNode(j).strip().isToken()) { 5516 formalParameters 5517 .add(macroDefinition 5518 .getGeneric(1).getGeneric(0) 5519 .getString(j)); 5520 5521 } else if (macroDefinition.getGeneric(1) 5522 .getGeneric(0).getNode(j).strip() instanceof GNode) { 5523 /* formalParameters 5524 .add((String) macroDefinition 5554 5525 .getGeneric(1).getGeneric(0) 5555 5526 .getGeneric(j).getString(0)); 5527 */ 5528 /* System.out.println(" HERE "+ macroDefinition.getGeneric(1) 5529 .getGeneric(0).getNode(j).get(0) + " " + (macroDefinition.getGeneric(1) 5530 .getGeneric(0).getNode(j).get(0) instanceof String));*/ 5531 if( macroDefinition.getGeneric(1).getGeneric(0).getGeneric(j).get(0) instanceof String) { 5532 formalParameters 5533 .add((String) macroDefinition 5534 .getGeneric(1).getGeneric(0) 5535 .getGeneric(j).getString(0)); 5536 5537 } else if( macroDefinition.getGeneric(1).getGeneric(0).getGeneric(j).get(0) instanceof Node) { 5538 //{ 5539 /*System.out.println(" THERE "+ macroDefinition.getGeneric(1) 5540 .getGeneric(0).getNode(j).get(0) + " " + (macroDefinition.getGeneric(1) 5541 .getGeneric(0).getNode(j).getNode(0).strip()));*/ 5542 5543 5544 if( macroDefinition.getGeneric(1).getGeneric(0).getGeneric(j).getNode(0).strip() != null) 5545 formalParameters 5546 .add((String) macroDefinition 5547 .getGeneric(1).getGeneric(0) 5548 .getGeneric(j).getString(0)); 5549 } 5550 5551 } 5552 } 5553 } 5554 } 5556 5555 } 5556 } 5557 } else { 5558 if(macroDefinition.getGeneric(1).getNode(0).strip().isToken()) { 5559 for (int i = 0; i < macroDefinition.getGeneric(1).size(); i++) { 5560 try { 5561 formalParameters.add(macroDefinition 5562 .getGeneric(1).getString(i)); 5563 } catch (ClassCastException cce) { 5564 cce.printStackTrace(); 5565 formalParameters.add("Unsupported Parmaeter"); 5566 } 5567 } 5568 5569 } 5570 //System.out.println("WEIRD " + macroDefinition.getGeneric(1).getNode(0)); 5571 //System.out.println("INSTANCE "+ macroDefinition.getGeneric(1).getNode(0).getLocation() + " " + macroDefinition.getGeneric(1).getNode(0).strip().isToken()); 5572 5557 5573 } 5558 5574 } … … 5563 5579 .getGeneric(1).getString(i)); 5564 5580 } catch (ClassCastException cce) { 5565 cce.printStackTrace();5566 formalParameters.add("Unsupported Parmaeter");5581 cce.printStackTrace(); 5582 formalParameters.add("Unsupported Parmaeter"); 5567 5583 } 5568 5584 } … … 5571 5587 } 5572 5588 } 5589 5573 5590 } 5574 5591 /** Retrieving the Actual Parameters */ … … 5579 5596 **/ 5580 5597 // TODO Follow parameters 5598 5581 5599 if ((parameters != null) && (formalParameters.size() > 0)) { 5582 5600 if (1 <= DEBUG) … … 5586 5604 5587 5605 for (int i = 0; i < parameters.size(); i++) { 5588 final int formal_index = i >= formalParameters.size() ? formalParameters5606 final int formal_index = i >= formalParameters.size() ? formalParameters 5589 5607 .size() - 1 5590 5608 : i; … … 5598 5616 public void visit(GNode n) { 5599 5617 for (int j = 0; j < n.size(); j++) { 5600 if (n.get(j) instanceof GNode) { 5601 dispatch(n.getGeneric(j)); 5618 if(n.get(j) instanceof Node) { 5619 if (n.getNode(j).strip() instanceof GNode) { 5620 dispatch(n.getGeneric(j)); 5621 } 5602 5622 } 5603 5623 } … … 5625 5645 * Parameters should not be modified too 5626 5646 */ 5647 //System.out.println("PARAMETER DICT " + parameterDict); 5627 5648 5628 5649 // Visitor to visit the macro Definition and store all the … … 5636 5657 public void visit(GNode n) { 5637 5658 for (int i = 0; i < n.size(); i++) { 5638 if (n.get(i) instanceof GNode) 5639 dispatch(n.getGeneric(i)); 5659 if (n.get(i) instanceof Node) 5660 if (n.getNode(i).strip() instanceof GNode) 5661 dispatch(n.getGeneric(i)); 5640 5662 } 5641 5663 } … … 5653 5675 public void visitMacroIdentifierConstant(GNode n) { 5654 5676 // This is a parameter.. 5655 5677 //System.out.println("LEFT " + leftHandinMacro + " unary " + unaryModinMacro 5678 // + "\n@@@ " + parameterDict.get(n.getString(0))); 5656 5679 if (leftHandinMacro || unaryModinMacro) { 5657 5680 // We retrieve the ids associated with the parameter 5658 5681 //TODO why this parameterDict index can be null ? 5659 if(parameterDict.get(n.get(0)) != null) 5660 idsInMacro.addAll(parameterDict.get(n.get(0))); 5682 if(parameterDict.get(n.getString(0)) != null) { 5683 //System.out.println("PARAMETER ADD ALL " + parameterDict.get(n.getString(0)) + "n.get(0) " + n.get(0) ); 5684 idsInMacro.addAll(parameterDict.get(n.getString(0))); 5685 } 5661 5686 } 5662 5687 … … 5666 5691 public void visitPostdecrementExpression(GNode n) { 5667 5692 unaryModinMacro = true; 5668 dispatch((Node) n.get (0));5693 dispatch((Node) n.getGeneric(0)); 5669 5694 unaryModinMacro = false; 5670 5695 } … … 5673 5698 public void visitPostincrementExpression(GNode n) { 5674 5699 unaryModinMacro = true; 5675 dispatch((Node) n.get (0));5700 dispatch((Node) n.getGeneric(0)); 5676 5701 unaryModinMacro = false; 5677 5702 … … 5681 5706 public void visitPredecrementExpression(GNode n) { 5682 5707 unaryModinMacro = true; 5683 dispatch((Node) n.get (0));5708 dispatch((Node) n.getGeneric(0)); 5684 5709 unaryModinMacro = false; 5685 5710 } … … 5688 5713 public void visitPreincrementExpression(GNode n) { 5689 5714 unaryModinMacro = true; 5690 dispatch((Node) n.get (0));5715 dispatch((Node) n.getGeneric(0)); 5691 5716 unaryModinMacro = false; 5692 5717 } … … 5695 5720 public void visitPrimaryIdentifier(GNode n) { 5696 5721 if (leftHandinMacro || unaryModinMacro) 5697 idsInMacro.add( (String) n.get(0));5722 idsInMacro.add(n.getString(0)); 5698 5723 } 5699 5724 5700 5725 @SuppressWarnings("unused") 5701 5726 public void visitCPPIdentifierList(GNode n) { 5702 for(int i=0; i < n.size(); i++) 5727 for(int i=0; i < n.size(); i++) { 5728 //System.out.println("ADDING " + n.getString(i)); 5703 5729 idsInMacro.add(n.getString(i)); 5730 } 5704 5731 } 5705 5732 5706 5733 @SuppressWarnings("unused") 5707 5734 public void visitAddressExpression(GNode n) { 5708 unaryModinMacro = true; 5735 unaryModinMacro = true; 5736 //System.out.println("seqlock ADDRESS EXPRESSION " + n ); 5709 5737 for (int i = 0; i < n.size(); i++) { 5710 if (n.get(i) instanceof GNode) 5711 dispatch(n.getGeneric(i)); 5738 if (n.get(i) instanceof Node) 5739 if (n.getNode(i).strip() instanceof GNode) 5740 dispatch(n.getGeneric(i)); 5712 5741 } 5713 5742 unaryModinMacro = false; … … 5716 5745 5717 5746 }.dispatch(macroDefinition); 5747 5748 //System.out.println("IDS IN MACRO " + idsInMacro ) ; 5718 5749 return idsInMacro; 5719 5750 } … … 5807 5838 } 5808 5839 } catch (NullPointerException e) { 5809 //e.printStackTrace();5810 return result;5840 //e.printStackTrace(); 5841 return result; 5811 5842 } 5812 5843 } … … 5918 5949 /** Visit the specified additive expression. */ 5919 5950 public Type visitAdditiveExpression(GNode n) { 5920 // C99 6.5.65951 // C99 6.5.6 5921 5952 final Node n1 = n.getGeneric(0); 5922 5953 final String op = n.getString(1); 5923 5954 final Node n2 = n.getGeneric(2); 5955 //We use the rightHandSide because we don't want to move a part of this kind 5956 //of expression 5957 //TODO add a stack 5958 rightHandSide = true; 5924 5959 final Type t1 = (Type) dispatch(n1); 5925 5960 final Type t2 = (Type) dispatch(n2); 5926 if (t1 != null && t2 != null) { 5961 rightHandSide = false; 5962 if (t1 != null && t2 != null) { 5927 5963 final Type r1 = c().pointerize(t1); 5928 5964 final Type r2 = c().pointerize(t2); … … 5991 6027 } catch (IllegalStateException x) { 5992 6028 // ref + ref 5993 x.printStackTrace();6029 x.printStackTrace(); 5994 6030 result = result.constant(new StaticReference( 5995 6031 result)); … … 6005 6041 : d1 - d2); 6006 6042 } catch (IllegalStateException x) { 6007 x.printStackTrace();6008 result = result6043 x.printStackTrace(); 6044 result = result 6009 6045 .constant(new StaticReference(result)); 6010 6046 } … … 6023 6059 .add(t2.getConstant().bigIntValue())); 6024 6060 } catch (IllegalStateException x) { 6025 x.printStackTrace();6026 result = result.constant(new StaticReference(6061 x.printStackTrace(); 6062 result = result.constant(new StaticReference( 6027 6063 result)); 6028 6064 } … … 6042 6078 .add(t1.getConstant().bigIntValue())); 6043 6079 } catch (IllegalStateException x) { 6044 x.printStackTrace();6045 result = result.constant(new StaticReference(6080 x.printStackTrace(); 6081 result = result.constant(new StaticReference( 6046 6082 result)); 6047 6083 } … … 6091 6127 .subtract(t2.getConstant().bigIntValue())); 6092 6128 } catch (IllegalStateException x) { 6093 //x.printStackTrace();6094 result = result6129 //x.printStackTrace(); 6130 result = result 6095 6131 .constant(new StaticReference(result)); 6096 6132 } … … 6189 6225 .bigIntValue())); 6190 6226 } catch (IllegalStateException x) { 6191 x.printStackTrace();6192 result = result.constant(new StaticReference(result));6227 x.printStackTrace(); 6228 result = result.constant(new StaticReference(result)); 6193 6229 } 6194 6230 } … … 6269 6305 final Type t2 = (Type) dispatch(n2); 6270 6306 rightHandSide = false; 6271 6272 6307 6308 6273 6309 if (t1 != null && t2 != null) { 6274 6310 Type result; … … 6337 6373 public Type visitBitwiseAndExpression(GNode n) { 6338 6374 // C99 6.5.10 6339 6375 6340 6376 final Node n1 = n.getGeneric(0); 6341 6377 final Node n2; 6342 if(n.size() >2) {6343 if(n.getGeneric(1) == null)6344 n2 = n.getGeneric(2);6345 else6346 n2 = null;6347 } else {6348 n2 = n.getGeneric(1);6349 }6378 if(n.size() >2) { 6379 if(n.getGeneric(1) == null) 6380 n2 = n.getGeneric(2); 6381 else 6382 n2 = null; 6383 } else { 6384 n2 = n.getGeneric(1); 6385 } 6350 6386 6351 6387 final Type t1 = (Type) dispatch(n1); … … 6368 6404 c().mask(t2.getConstant().bigIntValue(), result))); 6369 6405 } catch (IllegalStateException x) { 6370 x.printStackTrace();6371 result = result.constant(new StaticReference(result));6406 x.printStackTrace(); 6407 result = result.constant(new StaticReference(result)); 6372 6408 } 6373 6409 } … … 6419 6455 public Type visitBitwiseOrExpression(GNode n) { 6420 6456 // C99 6.5.12 6421 6457 6422 6458 final Node n1 = n.getGeneric(0); 6423 6459 final Node n2; 6424 if(n.size() > 2)6425 n2 = n.getGeneric(2);6426 else6427 n2 = n.getGeneric(1);6460 if(n.size() > 2) 6461 n2 = n.getGeneric(2); 6462 else 6463 n2 = n.getGeneric(1); 6428 6464 6429 6465 final Type t1 = (Type) dispatch(n1); … … 6462 6498 final Node n1 = n.getGeneric(0); 6463 6499 final Node n2; 6464 if (n.size() > 2)6465 n2 = n.getGeneric(2);6466 else6467 n2 = n.getGeneric(1);6468 6469 final Type t1 = (Type) dispatch(n1);6500 if (n.size() > 2) 6501 n2 = n.getGeneric(2); 6502 else 6503 n2 = n.getGeneric(1); 6504 6505 final Type t1 = (Type) dispatch(n1); 6470 6506 final Type t2 = (Type) dispatch(n2); 6471 6507 … … 6504 6540 final boolean stmtexpr = isStmtAsExpr; 6505 6541 isStmtAsExpr = false; 6506 6542 6507 6543 String name = table.freshName("BranchStatements"); 6508 6544 if (1 <= DEBUG) { … … 6519 6555 for (int i = 0; i < size; i++) { 6520 6556 try { 6521 6522 Object o = dispatch(n.getNode(i));6557 6558 Object o = dispatch(n.getNode(i)); 6523 6559 6524 6560 if ((size - 2 == i) && (o instanceof Type)) { … … 6530 6566 } 6531 6567 } catch (NullPointerException e) { 6532 e.printStackTrace();6533 System.err.println("Exception ");6568 e.printStackTrace(); 6569 System.err.println("Exception "); 6534 6570 } 6535 6571 } 6536 6572 6537 6573 table.exit(); 6538 6539 hasScope = scope;6574 6575 hasScope = scope; 6540 6576 return stmtexpr ? result : VoidT.TYPE; 6541 6577 } … … 6855 6891 if (scope || stmtexpr) { 6856 6892 String name = table.freshName("block"); 6857 table.enter(name);6893 table.enter(name); 6858 6894 table.mark(n); 6859 6895 } … … 6989 7025 if(kind.equals("FunctionMacro")) { 6990 7026 name = define.getGeneric(0).getString(0); 7027 macrosManager.updateDefine(name); 6991 7028 } else if(kind.equals("ObjectMacro")) { 6992 name = define.getGeneric(0).getGeneric(0).getString(0); 7029 name = define.getGeneric(0).getGeneric(0).getString(0); 7030 macrosManager.updateDefine(name); 6993 7031 } else if(kind.equals("Undef")) { 6994 7032 return; 6995 7033 } 6996 6997 if(isConditionallyDefined(define) && configOptions.size() > 0) {7034 7035 if(isConditionallyDefined(define) && configOptions.size() > 0) { 6998 7036 if(0 != conditionStack.size() && !name.equals("")) { 6999 7037 if(markedConfigOptions.size() > 0) // We add this function only if the condition is based on a config option … … 7004 7042 }catch(NullPointerException npe) { 7005 7043 System.err.println("Problem with the conditional definitions visitDefine " + define.getLocation() 7006 );7044 ); 7007 7045 npe.printStackTrace(); 7008 7046 conditionalDefs.put(name, null); … … 7084 7122 7085 7123 // Check for previous definitions. 7086 if (table.current().isDefinedLocally(name)) { 7087 Type previous = (Type) table.current().lookupLocally( 7088 name); 7089 7090 reportPrevious(name, previous); 7091 7092 } else { 7124 if (!table.current().isDefinedLocally(name)) { 7125 7093 7126 table.current().define(name, 7094 7127 new AliasT(name, type).locate(n).seal()); … … 7167 7200 && previous 7168 7201 .hasAttribute(Constants.ATT_DEFINED)) { 7169 reportPrevious(name, previous);7170 7
