Changeset 183

Show
Ignore:
Timestamp:
10/06/09 15:20:59 (7 weeks ago)
Author:
lb
Message:
 
Location:
trunk/cpp_analysis/src/xtc/lang/c4
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • trunk/cpp_analysis/src/xtc/lang/c4/C4.java

    r180 r183  
    285285  public Node parse(Reader in, File file) throws IOException, ParseException { 
    286286    if (runtime.test("optionParseTree")) { // ======================== Reader 
    287       if (runtime.test("optionNoIncr")) { 
     287         
     288        parserState.setParseTree(true);  
     289        if (runtime.test("optionNoIncr")) { 
    288290        C4Reader parser = new C4Reader(in, file.toString(), (int) file.length(), parserState); 
    289291        Result result = parser.pTranslationUnit(0); 
  • trunk/cpp_analysis/src/xtc/lang/c4/C4Core.rats

    r175 r183  
    328328  / <PDo>               void:"do":Keyword void:"{":Symbol  @PDo 
    329329  / <PartialExpression>  (void:",":Symbol)? Expression (void:",":Symbol)? @PExp 
    330   / <PartialInitializer> Designation? Initializer ",":Symbol? @PInit 
     330  / <PartialInitializer> Designation? Initializer (void:",":Symbol)? @PInit 
    331331  / ",":Symbol 
    332332; 
     
    769769        <RecursiveLess> IfGroupRelationalExpression "<":Symbol rv:IfGroupEqualityExpression 
    770770                        { 
    771                   if(yyState.isMacro(rv.get(0).toString())) { 
    772                     yyState.setRightValue(yyState.getMacroValue(rv.get(0).toString())); 
     771                   String isMacro = ""; 
     772              if((rv.get(0) instanceof String) || (rv.get(0) instanceof xtc.tree.Token))  
     773                isMacro = rv.getString(0); 
     774              else if( rv.get(0) instanceof xtc.tree.Annotation){ 
     775                if(rv.getNode(0).strip() instanceof xtc.tree.Token) 
     776                  isMacro = rv.getNode(0).strip().getString(0);  
     777              } 
     778             else if(rv.getNode(0).getName().startsWith("DefinedExpression")) { 
     779                    isMacro = rv.getGeneric(0).getString(0); 
     780              } 
     781              if(yyState.isMacro(isMacro)) { 
     782                    yyState.setRightValue(yyState.getMacroValue(isMacro)); 
    773783                  } else { 
    774784                    yyState.setRightValue(yyState.getTmpCondValue()); 
     
    778788  / <RecursiveLessEqual> IfGroupRelationalExpression "<=":Symbol rv:IfGroupEqualityExpression 
    779789            {  
    780               if(yyState.isMacro(rv.get(0).toString())) { 
    781                     yyState.setRightValue(yyState.getMacroValue(rv.get(0).toString())); 
     790              String isMacro = ""; 
     791  
     792              if((rv.get(0) instanceof String) || (rv.get(0) instanceof xtc.tree.Token)) 
     793                isMacro = rv.getString(0); 
     794              else if( rv.get(0) instanceof xtc.tree.Annotation){ 
     795                if(rv.getNode(0).strip() instanceof xtc.tree.Token) 
     796                  isMacro = rv.getNode(0).strip().getString(0);  
     797              } 
     798              else if(rv.getNode(0).getName().startsWith("DefinedExpression")) { 
     799                    isMacro = rv.getGeneric(0).getString(0); 
     800              } 
     801  
     802              else if(rv.getNode(0).getName().startsWith("DefinedExpression")) { 
     803                    isMacro = rv.getGeneric(0).getString(0); 
     804              } 
     805               
     806              if(yyState.isMacro(isMacro)) { 
     807                    yyState.setRightValue(yyState.getMacroValue(isMacro)); 
    782808              } else { 
    783809                yyState.setRightValue(yyState.getTmpCondValue()); 
     
    787813  /  <RecursiveGreater> lv:IfGroupRelationalExpression ">":Symbol rv:IfGroupEqualityExpression 
    788814                { 
    789                
    790               if(yyState.isMacro(rv.get(0).toString())) { 
    791                 yyState.setRightValue(yyState.getMacroValue(rv.get(0).toString())); 
     815             String isMacro = ""; 
     816              if((rv.get(0) instanceof String) || (rv.get(0) instanceof xtc.tree.Token)) 
     817                isMacro = rv.getString(0); 
     818              else if( rv.get(0) instanceof xtc.tree.Annotation){ 
     819                if(rv.getNode(0).strip() instanceof xtc.tree.Token) 
     820                  isMacro = rv.getNode(0).strip().getString(0);  
     821              } 
     822              else if(rv.getNode(0).getName().startsWith("DefinedExpression")) { 
     823                    isMacro = rv.getGeneric(0).getString(0); 
     824              } 
     825 
     826              if(yyState.isMacro(isMacro)) { 
     827                yyState.setRightValue(yyState.getMacroValue(isMacro)); 
    792828              } else { 
    793829                        yyState.setRightValue(yyState.getTmpCondValue()); 
    794830                  } 
     831             
    795832              yyState.setDefined(yyState.relation(">"));   
    796833                } 
    797834  / <RecursiveGreaterEqual> IfGroupRelationalExpression ">=":Symbol rv:IfGroupEqualityExpression 
    798                 {  
    799               if(yyState.isMacro(rv.get(0).toString())) { 
    800                 yyState.setRightValue(yyState.getMacroValue(rv.get(0).toString())); 
     835                { 
     836              String isMacro = ""; 
     837              if((rv.get(0) instanceof String) || (rv.get(0) instanceof xtc.tree.Token)) 
     838                isMacro = rv.getString(0); 
     839              else if( rv.get(0) instanceof xtc.tree.Annotation){ 
     840                if(rv.getNode(0).strip() instanceof xtc.tree.Token) 
     841                  isMacro = rv.getNode(0).strip().getString(0);  
     842              } 
     843              else if(rv.getNode(0).getName().startsWith("DefinedExpression")) { 
     844                    isMacro = rv.getGeneric(0).getString(0); 
     845              } 
     846  
     847  
     848              if(yyState.isMacro(isMacro)) { 
     849                yyState.setRightValue(yyState.getMacroValue(isMacro)); 
    801850              } else { 
    802851                yyState.setRightValue(yyState.getTmpCondValue()); 
     
    805854                } 
    806855  / <Base> yyValue:IfGroupEqualityExpression  
    807             {    
    808                   if(yyValue.getNode(0).getName() == "DefinedExpression") { 
    809                     if(yyState.isMacro(yyValue.getNode(0).getString(0))) { 
    810                   if(yyState.getMacroValue(yyValue.getNode(0).getString(0))!= "") { 
    811                     yyState.setLeftValue(yyState.getMacroValue(yyValue.getNode(0).getString(0))); 
     856            {  
     857                  if(yyValue.getGeneric(0).getName().startsWith("DefinedExpression") && yyValue.size() > 1) { 
     858                    String tmp = yyValue.getGeneric(0).strip().getString(0); 
     859                  if(yyState.isMacro(tmp)) { 
     860                  if(yyState.getMacroValue(tmp)!= "") { 
     861                    yyState.setLeftValue(yyState.getMacroValue(tmp)); 
    812862                  } else { 
    813863                    yyState.setLeftValue(null); 
     
    815865                } 
    816866               } else  { 
    817                 if(yyState.isSetTmpCondValue())  
     867                if(yyState.isSetTmpCondValue()) { 
    818868                  yyState.setLeftValue(yyState.getTmpCondValue()); 
     869 
     870                } 
    819871               } 
    820872             }     
     
    824876    <RecursionEq> lv:IfGroupAdditiveExpression "==":Symbol  
    825877            {  
    826                         if(yyState.isMacro(lv.get(0).toString())) { 
    827                           yyState.setLeftValue(yyState.getMacroValue((String)lv.get(0))); 
    828                         } else { 
     878                  String isMacro = ""; 
     879              if((lv.get(0) instanceof String) || (lv.get(0) instanceof xtc.tree.Token)) 
     880                isMacro = lv.getString(0); 
     881              else if( lv.get(0) instanceof xtc.tree.Annotation){ 
     882                if(lv.getNode(0).strip() instanceof xtc.tree.Token) 
     883                  isMacro = lv.getNode(0).strip().getString(0);  
     884              } 
     885              else if(lv.getNode(0).getName().startsWith("DefinedExpression")) { 
     886                    isMacro = lv.getGeneric(0).getString(0); 
     887              } 
     888 
     889              if(yyState.isMacro(isMacro)) { 
     890              yyState.setLeftValue(yyState.getMacroValue(isMacro)); 
     891                       
     892              } else { 
     893 
    829894                        yyState.compute(lv); 
    830895                        yyState.setLeftValue(yyState.getTmpCondValue()); 
     896 
    831897                      } 
    832898                    } 
    833899                  rv:IfGroupAdditiveExpression  
    834900                    {  
    835                       if(yyState.isMacro(rv.get(0).toString())) { 
    836                         yyState.setRightValue(yyState.getMacroValue((String)rv.get(0))); 
     901              isMacro = "";   
     902              if((rv.get(0) instanceof String) || (rv.get(0) instanceof xtc.tree.Token)) 
     903                isMacro = rv.getString(0); 
     904              else if( rv.get(0) instanceof xtc.tree.Annotation){ 
     905                if(rv.getNode(0).strip() instanceof xtc.tree.Token) 
     906                  isMacro = rv.getNode(0).strip().getString(0);  
     907              } 
     908              else if(rv.getNode(0).getName().startsWith("DefinedExpression")) { 
     909                    isMacro = rv.getGeneric(0).getString(0); 
     910              } 
     911              if(yyState.isMacro(isMacro)) { 
     912                        yyState.setRightValue(yyState.getMacroValue(isMacro)); 
    837913                      } else { 
    838914                        yyState.compute(rv); 
     
    843919  / <RecursionNEq> lv:IfGroupAdditiveExpression "!=":Symbol 
    844920                    {  
    845                       if(yyState.isMacro(lv.get(0).toString())) { 
    846                         yyState.setLeftValue(yyState.getMacroValue((String)lv.get(0))); 
     921               String isMacro = ""; 
     922              if((lv.get(0) instanceof String) || (lv.get(0) instanceof xtc.tree.Token)) 
     923                isMacro = lv.getString(0); 
     924              else if( lv.get(0) instanceof xtc.tree.Annotation){ 
     925 
     926                if(lv.getNode(0).strip() instanceof xtc.tree.Token) 
     927                  isMacro = lv.getNode(0).strip().getString(0);  
     928              } 
     929              else if(lv.getNode(0).getName().startsWith("DefinedExpression")) { 
     930                    isMacro = lv.getGeneric(0).getString(0); 
     931              } 
     932 
     933              if(yyState.isMacro(isMacro)) { 
     934                        yyState.setLeftValue(yyState.getMacroValue(isMacro)); 
    847935                      } else { 
    848936                        yyState.compute(lv); 
     
    851939                    } 
    852940                           rv:IfGroupAdditiveExpression  
    853                     {  
    854                       if(yyState.isMacro(rv.get(0).toString())) { 
    855                         yyState.setRightValue(yyState.getMacroValue((String)rv.get(0))); 
     941                    { 
     942              isMacro = ""; 
     943              if((rv.get(0) instanceof String) || (rv.get(0) instanceof xtc.tree.Token)) 
     944                isMacro = rv.getString(0); 
     945              else if( rv.get(0) instanceof xtc.tree.Annotation){ 
     946                if(rv.getNode(0).strip() instanceof xtc.tree.Token) 
     947                  isMacro = rv.getNode(0).strip().getString(0);  
     948              } 
     949              else if(rv.getNode(0).getName().startsWith("DefinedExpression")) { 
     950                    isMacro = rv.getGeneric(0).getString(0); 
     951              } 
     952 
     953                      if(yyState.isMacro(isMacro)) { 
     954                        yyState.setRightValue(yyState.getMacroValue(isMacro)); 
    856955                      } else { 
    857956                        yyState.compute(rv); 
     
    862961  / <Base> exp:IfGroupAdditiveExpression  
    863962                   { 
    864                      if (exp.getName() == "IfGroupAdditiveExpression"       ||  
    865                          exp.getName() == "IfGroupMultiplicativeExpression" ||  
    866                          exp.getName() == "IfGroupBinaryExpression"         || 
    867                          exp.getName() == "IntegerConstant"                 || 
    868                  exp.getName() == "FunctionMacroCallExpression" ) { 
    869                         yyState.compute(exp); 
     963                      Node tmpExp = exp.strip(); 
     964              if (tmpExp.getName() == "IfGroupAdditiveExpression"       ||  
     965                         tmpExp.getName() == "IfGroupMultiplicativeExpression" ||  
     966                         tmpExp.getName() == "IfGroupBinaryExpression"         || 
     967                         tmpExp.getName() == "IntegerConstant"                 || 
     968                 tmpExp.getName() == "FunctionMacroCallExpression" ) { 
     969                        yyState.compute(tmpExp); 
    870970                            yyState.setDefined(yyState.isTrue(yyState.getTmpCondValue())); 
    871971                     } 
     
    9171017 
    9181018generic DefinedExpression = 
    919   <Defined>    "defined":CPPKeyword (void:"(":Symbol/CPPSpacing) id:Identifier (void:")":Symbol/CPPSpacing)  
     1019  <Defined>    void:"defined":CPPKeyword (void:"(":Symbol/CPPSpacing) id:Identifier (void:")":Symbol/CPPSpacing)  
    9201020               { 
    9211021                 yyState.setDefined(yyState.isMacro(toText(id))); 
  • trunk/cpp_analysis/src/xtc/lang/c4/C4IncludeAction.rats

    r145 r183  
    2020        Node result; 
    2121    String header; 
    22     String headerFile; 
     22    String headerFile = ""; 
    2323    String headerFilePath = null; 
    2424    boolean systemHeader = false; 
     25     
     26    try { 
     27      headerFile = node.getGeneric(0).getString(0); 
     28      // Get the full path of the header file. 
     29      if (null != node.getGeneric(0) && node.getGeneric(0).hasName("UnparsedSystemHeader")) { 
     30      headerFilePath = yyState.getIncludePathManager().locate(headerFile, false); 
     31      systemHeader = true; 
     32      } else if (null != node.getGeneric(0) && node.getGeneric(0).hasName("UnparsedUserHeader")) { 
    2533      
    26     if (node.get(0) instanceof String) { 
    27       
     34       headerFilePath = yyState.getIncludePathManager().locate(headerFile, true); 
     35 
     36      } else { 
     37      System.err.println("Unknown node: " + node); 
     38      System.exit(1); 
     39      } 
     40     
     41      if (null == headerFilePath) { 
     42      System.err.println("Cannot find header file " + headerFile); 
     43      return null; 
     44      } else if (yyState.hasParsed(headerFilePath)) { 
     45      return null; 
     46      } 
     47    } catch(ClassCastException e) {  
     48    try { 
    2849      if (yyState.isFunctionMacro(node.getString(0))) { 
    2950        header = yyState.resolveInclusion(node);  
    30         if(header.startsWith("\"")) { 
     51      if(header.startsWith("\"")) { 
    3152          headerFile = header.substring(1,header.length()-1); 
    3253          headerFilePath = yyState.getIncludePathManager().locate(headerFile, true); 
     
    4263        return null; 
    4364      } 
    44     }  
    45     else { 
    46       headerFile = node.getGeneric(0).getString(0); 
    47       // Get the full path of the header file. 
    48       if (null != node.getGeneric(0) && node.getGeneric(0).hasName("UnparsedSystemHeader")) { 
    49       headerFilePath = yyState.getIncludePathManager().locate(headerFile, false); 
    50       systemHeader = true; 
    51       } else if (null != node.getGeneric(0) && node.getGeneric(0).hasName("UnparsedUserHeader")) { 
    52       headerFilePath = yyState.getIncludePathManager().locate(headerFile, true); 
    53  
    54       } else { 
    55       System.err.println("Unknown node: " + node); 
    56       System.exit(1); 
    57       } 
    58      
    59       if (null == headerFilePath) { 
    60       System.err.println("Cannot find header file " + headerFile); 
    61       return null; 
    62       } else if (yyState.hasParsed(headerFilePath)) { 
    63       return null; 
    64       } 
    65       
    66      } 
    67      
     65    }  catch(ClassCastException estring) { 
     66        System.out.println("Exception when trying the file with this node: " + 
     67node + "\nAborting..."); 
     68        System.exit(-1); 
     69    } 
     70    } 
     71 
    6872   
    6973    File currentFile = new File(this.yyColumns[0].file); 
     
    7377      result = parseHFile(node, headerFilePath, headerFile, systemHeader); 
    7478      yyState.getIncludePathManager().setCurrentWorkingPath(currentFile.getParent()); 
    75                     
    7679      return result;  
    7780    } catch( Exception e ) { 
     
    8790          return null; 
    8891       } 
    89  
    9092       Reader in   = new BufferedReader(new FileReader(headerFilePath)); 
    9193       Result result; 
     
    9395      yyState.start(); 
    9496      yyState.incIncludeLevel(); 
    95        
    96       C4Parser p = new C4Parser(in, headerFilePath); 
    97        
    98       // Adds the header to the list of parsed file. (Avoid circular include) 
    99       yyState.parsed(headerFilePath); 
    100       yyState.getIncludePathManager().setCurrentWorkingPath((new File(headerFilePath)).getParent()); 
    101    //System.out.println(">>>>>>>>>>>>>>>> " + headerFilePath);  
    102        
    103       result = p.pTranslationUnit(0); 
    104        
    105       if (!result.hasValue()) 
    106                                         p.signal(result.parseError()); 
    107        
    108    //System.out.println("<<<<<<<<<<<<<<<< " + headerFilePath);  
    109            
     97      if(!yyState.getParseTree()) { 
     98         C4Parser p = new C4Parser(in, headerFilePath); 
     99      
     100         yyState.parsed(headerFilePath); 
     101         yyState.getIncludePathManager().setCurrentWorkingPath((new File(headerFilePath)).getParent()); 
     102 
     103 
     104         result = p.pTranslationUnit(0); 
     105         if (!result.hasValue()) 
     106           p.signal(result.parseError()); 
     107        
     108      } else { 
     109         C4Reader p = (C4Reader) new C4Reader(in, headerFilePath); 
     110          
     111         yyState.parsed(headerFilePath); 
     112         yyState.getIncludePathManager().setCurrentWorkingPath((new File(headerFilePath)).getParent()); 
     113 
     114         result = p.pTranslationUnit(0); 
     115         if (!result.hasValue()) 
     116           p.signal(result.parseError()); 
     117        
     118    } 
    110119      yyState.decIncludeLevel(); 
    111120      yyState.commit(); 
     
    115124        if(systemHeader) { 
    116125                GNode tmp = GNode.create("SystemHeader", headerFile, result.semanticValue(), originalNode); 
    117            
    118           //Printer console = new Printer(new BufferedWriter(new OutputStreamWriter(System.out))); 
    119           //console.format(tmp ,false).pln().flush(); 
    120126          return tmp; 
    121127 
     
    123129        else { 
    124130                GNode tmp = GNode.create("UserHeader", headerFile, result.semanticValue(), originalNode); 
    125           //Printer console = new Printer(new BufferedWriter(new OutputStreamWriter(System.out))); 
    126           //console.format(tmp ,false).pln().flush(); 
    127131          return tmp; 
    128132        } 
  • trunk/cpp_analysis/src/xtc/lang/c4/C4IncludePathManager.java

    r60 r183  
    133133      for (String path : this.userIncludePath) { 
    134134        headerFile = new File(path + File.separator + header); 
    135 //        System.out.println("headerFile: " + headerFile.getAbsolutePath()); 
    136135        if (headerFile.exists()) 
    137136          return headerFile.getAbsolutePath(); 
     
    140139      // Search the current working directory. 
    141140      headerFile = new File(this.currentWorkingPath + File.separator + header); 
    142 //      System.out.println("headerFile: " + headerFile.getAbsolutePath()); 
    143141      if (headerFile.exists()) { 
    144142        return headerFile.getAbsolutePath(); 
     
    157155      for (String path : this.systemIncludePath) { 
    158156        headerFile = new File(path + File.separator + header); 
    159 //        System.out.println("headerFile: " + headerFile.getAbsolutePath()); 
    160157        if (headerFile.exists()) 
    161158          return headerFile.getAbsolutePath(); 
  • trunk/cpp_analysis/src/xtc/lang/c4/C4Logger.java

    r178 r183  
    1212import java.util.Iterator; 
    1313import java.util.Map; 
    14  
     14import java.util.Stack; 
    1515import xtc.tree.Location; 
    1616 
     
    2323public class C4Logger { 
    2424 
    25         /** To printOut the results of the movability analysis */ 
    26         BufferedWriter analysisOutput; 
    27  
    28         /** The name of the file currently analyzed **/ 
    29         String fileName; 
    30  
    31         public C4Logger(String fileName) { 
    32                 this.fileName = fileName; 
    33         } 
    34  
    35         protected void logConvertibleInfo(String kind, Location loc, boolean after, 
    36                         boolean isConvertible) { 
    37                 try { 
    38                         String message = kind + ": " + loc; 
    39  
    40                         if (after) 
    41                                 message += " ConvertibleAfter: " + isConvertible + "\n"; 
    42                         else 
    43                                 message += " ConvertibleBefore: " + isConvertible + "\n"; 
    44  
    45                         analysisOutput.write(message); 
    46  
    47                 } catch (IOException e) { 
    48                         System.err.println("Error when writing convertible info"); 
    49                         e.printStackTrace(); 
    50                 } 
    51  
    52         } 
    53  
    54         /** 
    55          * Builds a string from all the nested conditions (Basically just && all 
    56          * these conditions) 
    57          *  
    58          * @param conditions 
    59          * @return 
    60          */ 
    61         private String buildConditionsString(ArrayList<String> conditions) { 
    62                 String conditionString = ""; 
    63  
    64                 for (Iterator<String> iterator = conditions.iterator(); iterator 
    65                                 .hasNext();) { 
    66                         String string = (String) iterator.next(); 
    67                         if (!conditionString.equals("")) 
    68                                 conditionString = conditionString + "&&(" + string + ")"; 
    69                         else 
    70                                 conditionString = "(" + string + ")"; 
    71                 } 
    72                 return conditionString; 
    73  
    74         } 
     25    /** To printOut the results of the movability analysis */ 
     26    BufferedWriter analysisOutput; 
     27 
     28    /** The name of the file currently analyzed **/ 
     29    String fileName; 
     30 
     31    public C4Logger(String fileName) { 
     32        this.fileName = fileName; 
     33} 
     34 
     35 
     36protected void logWrapper(String toBeMoved, 
     37        String name, Location defLoc,  
     38        Location location, 
     39        ArrayList<String> conditions, Stack<ArrayList<String>> markedStack, ArrayList<String> condDefs, boolean movableBefore, HashMap<String, Boolean> movableAfter,  boolean convertibleBefore, boolean convertibleAfter) { 
     40 
     41    String condition = buildConditionsString(conditions); 
     42     
     43    String message = "{\n" + toBeMoved + ": " + location 
     44        + "; Name: " + name  
     45        + "; DefinitionLocation: " + defLoc   
     46        + "; UsageConfigOptions: { " + buildMarkedConfigOption(markedStack) + " } " 
     47        + "; DefinitionConfigOptions: { " + condDefs + " } "  
     48        + "; UsageConditions: { " + condition  + " }" 
     49        + "; MovableBefore: " + movableBefore  
     50        + "; MovableAfter: { " + build_movableAfter(movableAfter) + " }" 
     51        + "; ConvertibleBefore: " + convertibleBefore  
     52        + "; ConvertibleAfter: " + convertibleAfter 
     53        + "\n}\n"; 
     54    try { 
     55        analysisOutput.write(message); 
     56    } catch (IOException e) { 
     57        e.printStackTrace(); 
     58} 
     59 
     60} 
     61 
     62protected void logConvertibleInfo(String kind, Location loc, boolean after, 
     63        boolean isConvertible) { 
     64    try { 
     65        String message = kind + ": " + loc; 
     66 
     67        if (after) 
     68            message += " ConvertibleAfter: " + isConvertible + "\n"; 
     69        else 
     70            message += " ConvertibleBefore: " + isConvertible + "\n"; 
     71 
     72        analysisOutput.write(message); 
     73 
     74    } catch (IOException e) { 
     75        System.err.println("Error when writing convertible info"); 
     76        e.printStackTrace(); 
     77} 
     78 
     79} 
     80 
     81/** 
     82 * Builds a string from all the nested conditions (Basically just && all 
     83 * these conditions) 
     84 *  
     85 * @param conditions 
     86 * @return 
     87 */ 
     88private String buildConditionsString(ArrayList<String> conditions) { 
     89    String conditionString = ""; 
     90 
     91    for (Iterator<String> iterator = conditions.iterator(); iterator 
     92            .hasNext();) { 
     93        String string = (String) iterator.next(); 
     94        if (!conditionString.equals("")) 
     95            conditionString = conditionString + "&&(" + string + ")"; 
     96        else 
     97            conditionString = "(" + string + ")"; 
     98} 
     99return conditionString; 
     100 
     101} 
    75102 
    76103public void logAfterInfo(String toBeMoved, 
    77                         String name, Location defLoc, 
    78                         HashMap<String, Boolean> afterMap, Location location, 
    79                         ArrayList<String> conditions) { 
    80                 logAfterInfo(toBeMoved, name, defLoc, afterMap, location, conditions, null); 
    81 } 
    82  
    83  
    84         public void logAfterInfo(String toBeMoved, 
    85                         String name, Location defLoc, 
    86                         HashMap<String, Boolean> afterMap, Location location, 
    87                         ArrayList<String> conditions, ArrayList<String> condDefs) { 
    88                 String condition = buildConditionsString(conditions); 
    89                 String message; 
    90                 try { 
    91                  
    92                         if (afterMap != null) { 
    93                                 message = toBeMoved + ": " + location 
    94                                 + " Name: " + name  
    95                                 + " DefLoc: " + defLoc   
    96                     + " LocalCondition: { " + condition  + " }" 
    97                     + " CondDef: { " + condDefs + " }" 
    98                                 + " MovableAfter: { "; 
    99  
    100                                 for (Map.Entry<String, Boolean> map : afterMap.entrySet()) { 
    101                                                 message += map.getKey() + " " + map.getValue() + " "; 
    102                                 } 
    103                                 message += " }\n"; 
    104                                  
    105                         } else { 
    106                                 message = toBeMoved + ": " + location 
    107                                 + " Name: " + name  
    108                                 + " DefLoc: " + defLoc   
    109                                 + " LocalCondition: { " + condition + " }"  
    110                                 + " CondDef: { " + condDefs + " }" 
    111                                 + " MovableAfter: { false } \n"; 
    112                         } 
    113                          
    114                         analysisOutput.write(message); 
    115                          
    116                 } catch (IOException e) { 
    117                         System.err.println("Error when logging After info"); 
    118                         e.printStackTrace(); 
    119                 } 
    120         } 
    121  
    122     public void logBeforeInfo(String toBeMoved, String name, Location defLoc, Location location, 
    123                         boolean movableBefore, ArrayList<String> condition) { 
    124         logBeforeInfo(toBeMoved, name, defLoc, location, movableBefore, condition, null); 
    125         } 
    126  
    127  
    128  
    129         public void logBeforeInfo(String toBeMoved, String name, Location defLoc, Location location, 
    130                         boolean movableBefore, ArrayList<String> conditions, ArrayList<String> conditionDef) { 
    131                 String message; 
    132                 String condition = buildConditionsString(conditions); 
    133                 try { 
    134                         message = toBeMoved + ": " + location  
    135                         + " Name: " + name  
    136                         + " DefLoc: " + defLoc   
    137                         + " LocalCondition: { " + condition + " }"  
     104        String name, Location defLoc, 
     105        HashMap<String, Boolean> afterMap, Location location, 
     106        ArrayList<String> conditions) { 
     107    logAfterInfo(toBeMoved, name, defLoc, afterMap, location, conditions, null); 
     108} 
     109 
     110 
     111public String build_movableAfter(HashMap<String, Boolean> afterMap) { 
     112    String message = ""; 
     113 
     114    if (afterMap != null) { 
     115        for (Map.Entry<String, Boolean> map : afterMap.entrySet()) { 
     116            message += map.getKey() + " " + map.getValue() + " "; 
     117} 
     118 
     119} else { 
     120    message = "false"; 
     121} 
     122 
     123return message; 
     124} 
     125 
     126public ArrayList<String> buildMarkedConfigOption(Stack<ArrayList<String>> markedStack) { 
     127    ArrayList<String> result = new ArrayList<String>(); 
     128 
     129    for(ArrayList<String> tmp: markedStack) { 
     130        result.addAll(tmp); 
     131    } 
     132 
     133return result; 
     134} 
     135public void logAfterInfo(String toBeMoved, 
     136        String name, Location defLoc, 
     137        HashMap<String, Boolean> afterMap, Location location, 
     138        ArrayList<String> conditions, ArrayList<String> condDefs) { 
     139    String condition = buildConditionsString(conditions); 
     140    String message; 
     141    try { 
     142 
     143        if (afterMap != null) { 
     144            message = toBeMoved + ": " + location 
     145                + " Name: " + name  
     146                + " DefLoc: " + defLoc   
     147                + " LocalCondition: { " + condition  + " }" 
     148                + " CondDef: { " + condDefs + " }" 
     149                + " MovableAfter: { "; 
     150 
     151            for (Map.Entry<String, Boolean> map : afterMap.entrySet()) { 
     152                message += map.getKey() + " " + map.getValue() + " "; 
     153} 
     154message += " }\n"; 
     155 
     156} else { 
     157    message = toBeMoved + ": " + location 
     158        + " Name: " + name  
     159        + " DefLoc: " + defLoc   
     160        + " LocalCondition: { " + condition + " }"  
     161        + " CondDef: { " + condDefs + " }" 
     162        + " MovableAfter: { false } \n"; 
     163} 
     164 
     165analysisOutput.write(message); 
     166 
     167} catch (IOException e) { 
     168    System.err.println("Error when logging After info"); 
     169    e.printStackTrace(); 
     170} 
     171} 
     172 
     173public void logBeforeInfo(String toBeMoved, String name, Location defLoc, Location location, 
     174        boolean movableBefore, ArrayList<String> condition) { 
     175    logBeforeInfo(toBeMoved, name, defLoc, location, movableBefore, condition, null); 
     176} 
     177 
     178 
     179 
     180public void logBeforeInfo(String toBeMoved, String name, Location defLoc, Location location, 
     181        boolean movableBefore, ArrayList<String> conditions, ArrayList<String> conditionDef) { 
     182    String message; 
     183    String condition = buildConditionsString(conditions); 
     184    try { 
     185        message = toBeMoved + ": " + location  
     186            + " Name: " + name  
     187            + " DefLoc: " + defLoc   
     188            + " LocalCondition: { " + condition + " }"  
    138189            + " CondDef: { " + conditionDef + " }" 
    139190            + " MovableBefore: " + movableBefore + "\n"; 
    140                  
    141                         analysisOutput.write(message); 
    142                 } catch (IOException e) { 
    143                         e.printStackTrace(); 
    144                 } 
    145         } 
    146  
    147     /* 
    148     public void logBeforeInfo(String toBeMoved, String name, Location defLoc, Location location, 
    149                         boolean movableBefore) { 
    150         logBeforeInfo(toBeMoved, name, defLoc, location, movableBefore, (ArrayList<String>) null); 
    151     } 
    152          
    153     public void logBeforeInfo(String toBeMoved, String name, Location defLoc, Location location, 
    154                         boolean movableBefore, ArrayList<String> condDefs) { 
    155                 try { 
    156                         analysisOutput.write( 
    157                                         toBeMoved + ": " + location 
    158                                         + " Name: " + name  
    159                                         + " DefLoc: " + defLoc   
    160                                         + " MovableBefore: " + movableBefore + "\n"); 
    161  
    162                 } catch (IOException e) { 
    163                         e.printStackTrace(); 
    164                 } 
    165         } 
    166     */ 
    167         public void logStructCond(String structName, boolean last, Location location) { 
    168                 try { 
    169                         analysisOutput.write("Struct: " + structName + " " + location 
    170                                         + " Last: " + last + "\n"); 
     191 
     192        analysisOutput.write(message); 
     193    } catch (IOException e) { 
     194        e.printStackTrace(); 
     195} 
     196} 
     197 
     198/* 
     199   public void logBeforeInfo(String toBeMoved, String name, Location defLoc, Location location, 
     200   boolean movableBefore) { 
     201   logBeforeInfo(toBeMoved, name, defLoc, location, movableBefore, (ArrayList<String>) null); 
     202} 
     203 
     204public void logBeforeInfo(String toBeMoved, String name, Location defLoc, Location location, 
     205boolean movableBefore, ArrayList<String> condDefs) { 
     206try { 
     207analysisOutput.write( 
     208toBeMoved + ": " + location 
     209+ " Name: " + name  
     210+ " DefLoc: " + defLoc   
     211+ " MovableBefore: " + movableBefore + "\n"); 
     212 
     213} catch (IOException e) { 
     214e.printStackTrace(); 
     215} 
     216} 
     217*/ 
     218public void logStructCond(String structName, boolean last, Location location) { 
     219    try { 
     220        analysisOutput.write("{\nStruct: " + structName + " " + location 
     221                + " Last: " + last + "\n}\n"); 
    171222                } catch (IOException e) { 
    172223                        e.printStackTrace(); 
  • trunk/cpp_analysis/src/xtc/lang/c4/C4MacrosManager.java

    r146 r183  
    375375        public boolean isMacro(String macroName) { 
    376376                boolean result =(functionMacros.containsKey(macroName) || objectMacros.containsKey(macroName) ); 
    377  
    378                 if (!result) { 
     377                 
     378        if (!result) { 
    379379                        if(lastBranchMacrosFunction != null && lastBranchMacrosObject != null) { 
    380380                                result = (lastBranchMacrosFunction.containsKey(macroName)) || (lastBranchMacrosObject.containsKey(macroName)); 
     
    424424        public Node retrieveMacro(String macroName) { 
    425425                Node macroNode = null; 
    426  
    427426                if( lastBranchMacrosFunction != null ) { 
    428427                        if(lastBranchMacrosFunction.containsKey(macroName)) { 
  • trunk/cpp_analysis/src/xtc/lang/c4/C4ParserState.java

    r176 r183  
    1 /* 
    2  * xtc - The eXTensible Compiler 
    3  * Copyright (C) 2005-2006 Princeton University 
    4  * 
    5  * This program is free software; you can redistribute it and/or 
    6  * modify it under the terms of the GNU General Public License 
    7  * version 2 as published by the Free Software Foundation. 
    8  * 
    9  * This program is distributed in the hope that it will be useful, 
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    12  * GNU General Public License for more details. 
    13  * 
    14  * You should have received a copy of the GNU General Public License 
    15  * along with this program; if not, write to the Free Software 
    16  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
    17  * USA. 
    18  */ 
    19 package xtc.lang.c4; 
    20  
    21 import java.util.ArrayList; 
    22 import java.util.HashMap; 
    23 import java.util.Iterator; 
    24  
    25 import xtc.lang.c4.C4State.Context; 
    26 import xtc.tree.GNode; 
    27 import xtc.tree.LineMarker; 
    28 import xtc.tree.Location; 
    29 import xtc.tree.Node; 
    30 import xtc.tree.Pragma; 
    31 import xtc.tree.SourceIdentity; 
    32 import xtc.tree.Visitor; 
    33 import xtc.util.State; 
    34  
    35  
    36 /** 
    37  * State for parsing C4. 
    38  * 
    39  * @author Laurent Burgy 
    40  * @version $Revision: 1.3 $ 
    41  */ 
    42 public class C4ParserState implements State { 
    43  
    44   private class MacroUndefException extends RuntimeException { 
    45     /** 
     1  /* 
     2   * xtc - The eXTensible Compiler 
     3   * Copyright (C) 2005-2006 Princeton University 
     4   * 
     5   * This program is free software; you can redistribute it and/or 
     6   * modify it under the terms of the GNU General Public License 
     7   * version 2 as published by the Free Software Foundation. 
     8   * 
     9   * This program is distributed in the hope that it will be useful, 
     10   * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12   * GNU General Public License for more details. 
     13   * 
     14   * You should have received a copy of the GNU General Public License 
     15   * along with this program; if not, write to the Free Software 
     16   * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
     17   * USA. 
     18   */ 
     19  package xtc.lang.c4; 
     20 
     21  import java.util.ArrayList; 
     22  import java.util.HashMap; 
     23  import java.util.Iterator; 
     24 
     25  import xtc.lang.c4.C4State.Context; 
     26  import xtc.tree.GNode; 
     27  import xtc.tree.LineMarker; 
     28  import xtc.tree.Location; 
     29  import xtc.tree.Node; 
     30  import xtc.tree.Pragma; 
     31  import xtc.tree.SourceIdentity; 
     32  import xtc.tree.Visitor; 
     33  import xtc.util.State; 
     34 
     35 
     36  /** 
     37   * State for parsing C4. 
     38   * 
     39   * @author Laurent Burgy 
     40   * @version $Revision: 1.3 $ 
     41   */ 
     42  public class C4ParserState implements State { 
     43 
     44    private class MacroUndefException extends RuntimeException { 
     45      /** 
     46       *  
     47       */ 
     48      private static final long serialVersionUID = -4091350260433333109L; 
     49      private String macroName; 
     50 
     51      MacroUndefException(String name) { 
     52        super(); 
     53        macroName = name; 
     54      } 
     55 
     56      MacroUndefException() { 
     57        super(); 
     58      } 
     59 
     60      public void printStackTrace() {  
     61        System.out.println("Undefined Macro " + macroName); 
     62        super.printStackTrace(); 
     63      } 
     64 
     65      public String getMessage() { 
     66        return ("Undefined Macro" + macroName + " " + super.getMessage()); 
     67      } 
     68 
     69      public String getMacroName() { 
     70        if(null != macroName)  
     71          return macroName; 
     72        return ""; 
     73      } 
     74 
     75    } 
     76 
     77 
     78    // ========================================================================== 
     79 
     80    /** 
     81     * Add the specified number of fresh contexts to the pool. 
     82     * 
     83     * @param n The number to add. 
     84     */ 
     85    protected void fillPool(int n) { 
     86      preState.fillPool(n); 
     87    } 
     88 
     89    /** 
     90     * Take a context from the pool, refilling the pool if necessary. 
     91     * 
     92     * @return A fresh context. 
     93     */ 
     94    protected Context takeFromPool() { 
     95      return preState.takeFromPool(); 
     96    } 
     97 
     98    /** 
     99     * Return the specified context to the pool, clearing it along the 
     100     * way. 
     101     * 
     102     * @param c The context to return. 
     103     */ 
     104    protected void addToPool(Context c) { 
     105      preState.addToPool(c); 
     106    } 
     107 
     108    // ========================================================================== 
     109 
     110    /** 
     111     * Push the specified context onto the context stack. 
     112     * 
     113     * @param c The context to push. 
     114     */ 
     115    protected void push(Context c) { 
     116      preState.push(c); 
     117    } 
     118 
     119    /** 
     120     * Pop a context from the context stack. 
     121     * 
     122     * @return The top-most context. 
     123     */ 
     124    protected Context pop() { 
     125      return preState.pop(); 
     126    } 
     127 
     128    public void start() { 
     129      preState.start(); 
     130    } 
     131 
     132    public void commit() { 
     133      preState.commit(); 
     134    } 
     135 
     136    public void abort() { 
     137      preState.abort(); 
     138    } 
     139 
     140    // ========================================================================== 
     141 
     142    /** Record a typedef storage class specifier. */ 
     143    public void typedef() { 
     144      preState.typedef(); 
     145    } 
     146 
     147    /** Record a function parameter list. */ 
     148    public void parameters() { 
     149      preState.parameters(); 
     150    } 
     151 
     152    /** Record a function declarator. */ 
     153    public void functionDeclarator() { 
     154      preState.functionDeclarator(); 
     155    } 
     156 
     157    /** Enter a new scope. */ 
     158    public void pushScope() { 
     159      preState.pushScope(); 
     160    } 
     161 
     162    /** Exit the last scope. */ 
     163    public void popScope() { 
     164      preState.popScope(); 
     165    } 
     166 
     167    /** Enter a structure declaration list. */ 
     168    public void enterStructure() { 
     169      preState.enterStructure(); 
     170    } 
     171 
     172    /** Exit a structure declaration list. */ 
     173    public void exitStructure() { 
     174      preState.exitStructure(); 
     175    } 
     176 
     177 
     178 
     179    /** 
     180     * Determine whether a declaration actually is a declaration.  This 
     181     * method determines whether the sequence 
     182     * <pre> 
     183     *   DeclarationSpecifiers l:InitializedDeclaratorList? 
     184     * </pre> 
     185     * can actually represent a declaration.  It assumes that any type 
     186     * specifier encountered while parsing 
     187     * <code>DeclarationSpecifiers</code> has been marked through {@link 
     188     * #typeSpecifier()}. 
     189     * 
     190     * @param idl The result of parsing the optional initialized 
     191     *   declarator list. 
     192     * @return <code>true</code> if the declaration is a declaration. 
     193     */ 
     194    public boolean isValid(Node idl) { 
     195      return preState.isValid(idl); 
     196    } 
     197 
     198    // ========================================================================== 
     199 
     200    /** 
     201     * Record a line marker.  Note that string values for the four flags 
     202     * are interpreted as follows: Any non-null string counts for 
     203     * <code>true</code>, while null counts for <code>false</code>. 
     204     * 
     205     * @see LineMarker 
     206     * 
     207     * @param file The file name (without quotes). 
     208     * @param line The line number. 
     209     * @param isStartFile The start file flag. 
     210     * @param isReturnToFile The return to file flag. 
     211     * @param isSystemHeader The system header flag. 
     212     * @param isExternC The extern C flag. 
     213     * @param location The line marker's source location. 
     214     */ 
     215    public void lineMarker(String file, int line, String isStartFile, 
     216        String isReturnToFile, String isSystemHeader, 
     217        String isExternC, Location location) { 
     218      preState.lineMarker(file, line, isStartFile, isReturnToFile, isSystemHeader, isExternC, location); 
     219    } 
     220 
     221    /** 
     222     * Record a pragma. 
     223     * 
     224     * @see Pragma 
     225     * 
     226     * @param directive The actual directive. 
     227     * @param location The pragma's source location. 
     228     */ 
     229    public void pragma(String directive, Location location) { 
     230      preState.pragma(directive, location); 
     231    } 
     232 
     233    /** 
     234     * Record an ident directive. 
     235     * 
     236     * @see SourceIdentity 
     237     * 
     238     * @param ident The actual identity marker. 
     239     * @param location The ident directive's source location. 
     240     */ 
     241    public void ident(String ident, Location location) { 
     242      preState.ident(ident, location); 
     243    }    
     244 
     245    /** 
     246     * Mark the current annotation.  This method must be called before 
     247     * recognizing the nonterminals to be annotated.  Furthermore, it 
     248     * must be called within the context of a stateful production. 
     249     */ 
     250    public void mark() { 
     251      preState.mark(); 
     252    } 
     253 
     254    /** 
     255     * Annotate the specified node.  If any annotations have been 
     256     * recorded and {@link #mark() marked}, the specified node is 
     257     * wrapped by those annotations and the outer-most annotation is 
     258     * returned.  Otherwise, the specified node is returned. 
     259     * 
     260     * @param node The node. 
     261     * @return The annotated node. 
     262     */ 
     263    public Node annotate(Node node) { 
     264      return preState.annotate(node); 
     265    } 
     266 
     267    //=========================================================================== 
     268    /** The C4 State to manage everything 
     269     * before everything was collecting using C4ParserState  
     270     * but it's no longer possible 
     271     * I've added a static field that manages all the state 
     272     */ 
     273    static C4State preState = new C4State(); 
     274 
     275    /** The current Object MacroId */ 
     276    String omId ;        
     277 
     278    /** 
     279     * Expression Evaluator 
     280     */ 
     281    /** Left Value for a If directive */ 
     282    String leftValue ; 
     283 
     284    boolean leftValueSet; 
     285 
     286    boolean isLeft = false; 
     287 
     288    boolean isRight = false; 
     289 
     290    /** Right Value for a If directive */ 
     291    String rightValue; 
     292 
     293    /** To check if the macro currently defined is an attribute */ 
     294    boolean isAttribute = false; 
     295 
     296    /** 
     297     * Variable that stores the temp value of the IfSection Conditional (if arithmetic included) 
     298     */ 
     299    long tmpCondValue = 0; 
     300 
     301    boolean tmpCondValueSet = false; 
     302 
     303   // Logger dbgLogger; 
     304 
     305    /** 
     306     * Default constructor. 
     307     */ 
     308    public C4ParserState() { 
     309      super(); 
     310    } 
     311 
     312    /** 
     313     * Constructor with a macro manager. 
     314     *   
     315     * @param macrosManager An instance of the C4MacrosManager. 
     316     */ 
     317    public C4ParserState(C4MacrosManager macrosManager) { 
     318      this(); 
     319      if(preState == null) //If we do not use the wrapper  
     320        resetPreState();   // we need to instantiate the preState 
     321       
     322      preState.setMacrosManager(macrosManager); 
     323    } 
     324 
     325    /** 
     326     * Sets the include path manager. 
    46327     *  
    47      */ 
    48     private static final long serialVersionUID = -4091350260433333109L; 
    49     private String macroName; 
    50  
    51     MacroUndefException(String name) { 
    52       super(); 
    53       macroName = name; 
    54     } 
    55  
    56     MacroUndefException() { 
    57       super(); 
    58     } 
    59  
    60     public void printStackTrace() {  
    61       System.out.println("Undefined Macro " + macroName); 
    62       super.printStackTrace(); 
    63     } 
    64  
    65     public String getMessage() { 
    66       return ("Undefined Macro" + macroName + " " + super.getMessage()); 
    67     } 
    68  
    69     public String getMacroName() { 
    70       if(null != macroName)  
    71         return macroName; 
    72       return ""; 
    73     } 
    74  
    75   } 
    76  
    77  
    78   // ========================================================================== 
    79  
    80   /** 
    81    * Add the specified number of fresh contexts to the pool. 
    82    * 
    83    * @param n The number to add. 
    84    */ 
    85   protected void fillPool(int n) { 
    86     preState.fillPool(n); 
    87   } 
    88  
    89   /** 
    90    * Take a context from the pool, refilling the pool if necessary. 
    91    * 
    92    * @return A fresh context. 
    93    */ 
    94   protected Context takeFromPool() { 
    95     return preState.takeFromPool(); 
    96   } 
    97  
    98   /** 
    99    * Return the specified context to the pool, clearing it along the 
    100    * way. 
    101    * 
    102    * @param c The context to return. 
    103    */ 
    104   protected void addToPool(Context c) { 
    105     preState.addToPool(c); 
    106   } 
    107  
    108   // ========================================================================== 
    109  
    110   /** 
    111    * Push the specified context onto the context stack. 
    112    * 
    113    * @param c The context to push. 
    114    */ 
    115   protected void push(Context c) { 
    116     preState.push(c); 
    117   } 
    118  
    119   /** 
    120    * Pop a context from the context stack. 
    121    * 
    122    * @return The top-most context. 
    123    */ 
    124   protected Context pop() { 
    125     return preState.pop(); 
    126   } 
    127  
    128   public void start() { 
    129     preState.start(); 
    130   } 
    131  
    132   public void commit() { 
    133     preState.commit(); 
    134   } 
    135  
    136   public void abort() { 
    137     preState.abort(); 
    138   } 
    139  
    140   // ========================================================================== 
    141  
    142   /** Record a typedef storage class specifier. */ 
    143   public void typedef() { 
    144     preState.typedef(); 
    145   } 
    146  
    147   /** Record a function parameter list. */ 
    148   public void parameters() { 
    149     preState.parameters(); 
    150   } 
    151  
    152   /** Record a function declarator. */ 
    153   public void functionDeclarator() { 
    154     preState.functionDeclarator(); 
    155   } 
    156  
    157   /** Enter a new scope. */ 
    158   public void pushScope() { 
    159     preState.pushScope(); 
    160   } 
    161  
    162   /** Exit the last scope. */ 
    163   public void popScope() { 
    164     preState.popScope(); 
    165   } 
    166  
    167   /** Enter a structure declaration list. */ 
    168   public void enterStructure() { 
    169     preState.enterStructure(); 
    170   } 
    171  
    172   /** Exit a structure declaration list. */ 
    173   public void exitStructure() { 
    174     preState.exitStructure(); 
    175   } 
    176  
    177  
    178  
    179   /** 
    180    * Determine whether a declaration actually is a declaration.  This 
    181    * method determines whether the sequence 
    182    * <pre> 
    183    *   DeclarationSpecifiers l:InitializedDeclaratorList? 
    184    * </pre> 
    185    * can actually represent a declaration.  It assumes that any type 
    186    * specifier encountered while parsing 
    187    * <code>DeclarationSpecifiers</code> has been marked through {@link 
    188    * #typeSpecifier()}. 
    189    * 
    190    * @param idl The result of parsing the optional initialized 
    191    *   declarator list. 
    192    * @return <code>true</code> if the declaration is a declaration. 
    193    */ 
    194   public boolean isValid(Node idl) { 
    195     return preState.isValid(idl); 
    196   } 
    197  
    198   // ========================================================================== 
    199  
    200   /** 
    201    * Record a line marker.  Note that string values for the four flags 
    202    * are interpreted as follows: Any non-null string counts for 
    203    * <code>true</code>, while null counts for <code>false</code>. 
    204    * 
    205    * @see LineMarker 
    206    * 
    207    * @param file The file name (without quotes). 
    208    * @param line The line number. 
    209    * @param isStartFile The start file flag. 
    210    * @param isReturnToFile The return to file flag. 
    211    * @param isSystemHeader The system header flag. 
    212    * @param isExternC The extern C flag. 
    213    * @param location The line marker's source location. 
    214    */ 
    215   public void lineMarker(String file, int line, String isStartFile, 
    216       String isReturnToFile, String isSystemHeader, 
    217       String isExternC, Location location) { 
    218     preState.lineMarker(file, line, isStartFile, isReturnToFile, isSystemHeader, isExternC, location); 
    219   } 
    220  
    221   /** 
    222    * Record a pragma. 
    223    * 
    224    * @see Pragma 
    225    * 
    226    * @param directive The actual directive. 
    227    * @param location The pragma's source location. 
    228    */ 
    229   public void pragma(String directive, Location location) { 
    230     preState.pragma(directive, location); 
    231   } 
    232  
    233   /** 
    234    * Record an ident directive. 
    235    * 
    236    * @see SourceIdentity 
    237    * 
    238    * @param ident The actual identity marker. 
    239    * @param location The ident directive's source location. 
    240    */ 
    241   public void ident(String ident, Location location) { 
    242     preState.ident(ident, location); 
    243   }      
    244  
    245   /** 
    246    * Mark the current annotation.  This method must be called before 
    247    * recognizing the nonterminals to be annotated.  Furthermore, it 
    248    * must be called within the context of a stateful production. 
    249    */ 
    250   public void mark() { 
    251     preState.mark(); 
    252   } 
    253  
    254   /** 
    255    * Annotate the specified node.  If any annotations have been 
    256    * recorded and {@link #mark() marked}, the specified node is 
    257    * wrapped by those annotations and the outer-most annotation is 
    258    * returned.  Otherwise, the specified node is returned. 
    259    * 
    260    * @param node The node. 
    261    * @return The annotated node. 
    262    */ 
    263   public Node annotate(Node node) { 
    264     return preState.annotate(node); 
    265   } 
    266  
    267   //=========================================================================== 
    268   /** The C4 State to manage everything 
    269    * before everything was collecting using C4ParserState  
    270    * but it's no longer possible 
    271    * I've added a static field that manages all the state 
    272    */ 
    273   static C4State preState = new C4State(); 
    274  
    275   /** The current Object MacroId */ 
    276   String omId ;  
    277  
    278   /** 
    279    * Expression Evaluator 
    280    */ 
    281   /** Left Value for a If directive */ 
    282   String leftValue ; 
    283  
    284   boolean leftValueSet; 
    285  
    286   boolean isLeft = false; 
    287  
    288   boolean isRight = false; 
    289  
    290   /** Right Value for a If directive */ 
    291   String rightValue; 
    292  
    293   /** To check if the macro currently defined is an attribute */ 
    294   boolean isAttribute = false; 
    295  
    296   /** 
    297    * Variable that stores the temp value of the IfSection Conditional (if arithmetic included) 
    298    */ 
    299   long tmpCondValue = 0; 
    300  
    301   boolean tmpCondValueSet = false; 
    302  
    303  // Logger dbgLogger; 
    304  
    305   /** 
    306    * Default constructor. 
    307    */ 
    308   public C4ParserState() { 
    309     super(); 
    310   } 
    311  
    312   /** 
    313    * Constructor with a macro manager. 
    314    *   
    315    * @param macrosManager An instance of the C4MacrosManager. 
    316    */ 
    317   public C4ParserState(C4MacrosManager macrosManager) { 
    318     this(); 
    319     if(preState == null) //If we do not use the wrapper  
    320       resetPreState();   // we need to instantiate the preState 
     328     * @param manager 
     329     *          An instance of the include path manager. 
     330     */ 
     331    public void setIncludePathManager(C4IncludePathManager manager) { 
     332      preState.setIncludePathManager(manager); 
     333    } 
     334 
     335    /** 
     336     * Sets the parseTree flag 
     337     * @param parseTreeFlag 
     338     *          A boolean 
     339     */ 
     340    public void setParseTree(boolean parseTree) { 
     341      preState.setParseTree(parseTree); 
     342    } 
    321343     
    322     preState.setMacrosManager(macrosManager); 
    323   } 
    324  
    325   /** 
    326    * Sets the include path manager. 
    327    *  
    328    * @param manager 
    329    *          An instance of the include path manager. 
    330    */ 
    331   public void setIncludePathManager(C4IncludePathManager manager) { 
    332     preState.setIncludePathManager(manager); 
    333   } 
    334  
    335   /** 
    336    * Returns the include path manager. 
    337    *  
    338    * @return The include path manager. 
    339    */ 
    340   public C4IncludePathManager getIncludePathManager() { 
    341     return preState.getIncludePathManager(); 
    342   } 
    343  
    344   /** 
    345    * Increments the include level. 
    346    */ 
    347   public void incIncludeLevel() { 
    348     preState.incIncludeLevel(); 
    349   } 
    350  
    351   /** 
    352    * Decrements the include level. 
    353    */ 
    354   public void decIncludeLevel() { 
    355     preState.decIncludeLevel(); 
    356   } 
    357  
    358   public void reset(String file) { 
    359     preState.reset(file); 
    360   } 
    361  
    362   //--------------------------------------------------------------------------- 
    363   // Macros 
    364   //--------------------------------------------------------------------------- 
    365   /** 
    366    * for the String Constant with macro parameters 
    367    */ 
    368   public boolean isMacroParameter(String id) { 
    369     return preState.isMacroParameter(id); 
    370   } 
    371  
    372   /** 
    373    * Tells whether or not the token is a function Macro 
    374    * @param token 
    375    * @return true if the token is a function macro 
    376    */ 
    377   public boolean isFunctionMacro(String token) { 
    378     return preState.isFunctionMacro(token); 
    379   } 
    380  
    381   /** 
    382    * Gets the object macro associated with the token 
    383    * @param token 
    384    * @return Object representing the object macro 
    385    */ 
    386   public Object getObjectMacro(String token) { 
    387     return preState.getObjectMacro(token); 
    388   } 
    389  
    390   /** 
    391    * Tells whether or not the token is an object macro 
    392    * @param token 
    393    * @return true if the token is an object macro 
    394    */ 
    395   public boolean isObjectMacro(String token) { 
    396     return preState.isObjectMacro(token); 
    397   } 
    398  
    399   /** 
    400    * Tells whether or not the token is a macro 
    401    * @param token 
    402    * @return true if the token is a macro name 
    403    */ 
    404   public boolean isMacro(String token) { 
    405     return preState.isMacro(token); 
    406   } 
    407  
    408   /** 
    409    * Gets the function macro associated with the token 
    410    * @param token 
    411    * @return Object representing the object macro 
    412    */ 
    413   public Object getFunctionMacro(String token) { 
    414     return preState.getFunctionMacro(token); 
    415   } 
    416  
    417   /** 
    418    * Removes a macro 
    419    * @param id The name of the macro to remove 
    420    */ 
    421   public void removeMacro(String id) { 
    422     preState.removeMacro(id); 
    423   } 
    424  
    425   /** 
    426    * Gets a macro by its name 
    427    * @param macroName 
    428    * @return Node of the macro 
    429    */ 
    430   public Node getMacro(String macroName) { 
    431     return preState.getMacro(macroName); 
    432   } 
    433  
    434   /** 
    435    * Stores a new macro 
    436    * @param macroNode Node of the macro to store 
    437    */ 
    438   public void storeMacro(Node macroNode){ 
    439     preState.getMacrosManager().storeMacro(macroNode); 
    440   } 
    441  
    442   /** 
    443    * To store the parameters of a function Macro 
    444    * @param n The parameters node 
    445    */ 
    446   public void storeParameters(Node n) { 
    447     preState.storeParameters(n); 
    448   } 
    449  
    450   /** 
    451    * Clean-up function 
    452    */ 
    453   public void purgeParameters() {  
    454     preState.purgeParameters(); 
    455   } 
    456  
    457  
    458   /** 
    459    * A commodity method to convert a string as an integer 
    460    * @param tmpS1 String to be converted 
    461    * @return Integer representing the string parameter 
    462    */ 
    463   public long string2long(String tmpS1) { 
    464     long tmp1; 
    465     try { 
    466       tmp1 = Long.valueOf(tmpS1); 
    467     } catch (NumberFormatException e) { 
    468       //System.err.println("NumberFormatException " + tmpS1); 
    469       tmp1 = 0; 
    470     } 
    471     return tmp1; 
    472  
    473   } 
    474  
    475   /** 
    476    * Get The parameter at the index associated with the macro  
    477    * @param macroName 
    478    * @param paramIndex 
    479    * @return String representing the parameter 
    480    */ 
    481   public String retrieveFunctionMacroParamName(String macroName, int paramIndex) { 
    482     String paramName = "param"; 
    483     Node macro = preState.getMacrosManager().retrieveMacro(macroName); 
    484     Node parameterList = ((Node)((Node)macro.get(1)).get(0)); 
    485  
    486     paramName = parameterList.get(paramIndex).toString(); 
    487  
    488     return paramName; 
    489   } 
    490  
    491   /** 
    492    * Evaluates a parameter given to a Macro  
    493    * @param parameter 
    494    * @return String representing the parameter 
    495    */ 
    496   @SuppressWarnings("unused") 
    497   public String evalParameter(Node parameter) { 
    498     String tmpString = new Visitor() { 
    499  
    500       public String visitObjectMacroValueSupported(GNode n) { 
    501         return dispatch((Node)n.get(0)).toString(); 
    502       } 
    503  
    504       public String visitObjectMacroValue(GNode n) { 
    505         return  dispatch((Node)n.get(0)).toString(); 
    506       } 
    507  
    508       public String visitMacroFunctionExpression(GNode n) { 
    509         evalMacroFuncCall(n); 
    510         System.out.println("EvalParameter " + n); 
    511         return "1"; 
    512       } 
    513  
    514       public String visitMacroReference(GNode n) { 
    515         try { 
    516           return getMacroValue(n.get(0).toString()); 
    517         } catch(MacroUndefException e) { 
    518           //The macro that has been given as parameter is not defined 
    519           //This is weird. 
    520           //TODO check when a macro given as a parameter could be undefined. 
    521           e.printStackTrace(); 
    522           return "0"; 
    523         } 
    524       } 
    525  
    526       public String visitShiftExpression(GNode n) { 
    527         long tmp1 = 0, tmp2 = 0, result = 0; 
    528         String tmpS1, tmpS2; 
    529         tmpS1 = dispatch((Node)n.get(0)).toString(); 
    530         tmp1  = string2long(tmpS1); 
    531  
    532         tmpS2 = dispatch((Node)n.get(2)).toString(); 
    533         tmp2  = string2long(tmpS2); 
    534  
    535  
    536         if(n.get(1) == "<<")  
    537           result = tmp1 << tmp2; 
    538  
    539         return Long.toString(result); 
    540       } 
    541  
    542       public String visitLogicalOrExpression(GNode n) { 
    543         long tmp1 = 0, tmp2 = 0, result = 0; 
    544         String tmpS1, tmpS2; 
    545         tmpS1 = dispatch((Node)n.get(0)).toString(); 
    546         tmp1  = string2long(tmpS1); 
    547  
    548         tmpS2 = dispatch((Node)n.get(1)).toString(); 
    549         tmp2  = string2long(tmpS2); 
    550  
    551         result = ( tmp1 != 0 ) || ( tmp2 != 0 ) ?  1 : 0; 
    552  
    553         return Long.toString(result); 
    554       } 
    555  
    556       public String visitLogicalAndExpression(GNode n) { 
    557         long tmp1 = 0, tmp2 = 0, result = 0; 
    558         String tmpS1, tmpS2; 
    559         tmpS1 = dispatch((Node)n.get(0)).toString(); 
    560         tmp1  = string2long(tmpS1); 
    561  
    562         tmpS2 =  dispatch((Node)n.get(1)).toString(); 
    563         tmp2  = string2long(tmpS2); 
    564  
    565         result = ( tmp1 != 0 ) && ( tmp2 != 0 ) ?  1 : 0; 
    566  
    567         return Long.toString(result); 
    568  
    569       } 
    570  
    571       public String visitRelationalExpression(GNode n) { 
    572         long tmp1 = 0, tmp2 = 0, result = 0; 
    573         String tmpS1, tmpS2; 
    574         tmpS1 = dispatch((Node)n.get(0)).toString(); 
    575         tmp1  = string2long(tmpS1); 
    576  
    577         tmpS2 = dispatch((Node)n.get(2)).toString(); 
    578         tmp2  = string2long(tmpS2); 
    579  
    580         if(n.get(1) == "<")  
    581           result = tmp1 < tmp2 ?  1 : 0; 
    582         else if (n.get(1) == ">") 
    583           result = tmp1 > tmp2 ?  1 : 0; 
    584           else if (n.get(1) == ">=") 
    585             result = tmp1 >= tmp2 ? 1 : 0; 
    586             else if (n.get(1) == ">=") 
    587               result = tmp1 >= tmp2 ? 1 : 0; 
    588  
    589               return Long.toString(result); 
    590       } 
    591  
    592       public String visitEqualityExpression(GNode n) { 
    593         long tmp1 = 0, tmp2 = 0, result = 0; 
    594         String tmpS1, tmpS2; 
    595         tmpS1 = dispatch((Node)n.get(0)).toString(); 
    596         tmp1  = string2long(tmpS1); 
    597  
    598         tmpS2 = dispatch((Node)n.get(2)).toString(); 
    599         tmp2  = string2long(tmpS2); 
    600         if(n.get(1) == "==")  
    601           result = tmp1 == tmp2 ?  1 : 0; 
    602         else if (n.get(1) == "!=") 
    603           result = tmp1 != tmp2 ?  1 : 0; 
    604  
    605         return Long.toString(result); 
    606  
    607       } 
    608  
    609       public String visitAdditiveExpression(GNode n) { 
    610         long tmp1 = 0, tmp2 = 0, result = 0; 
    611         String tmpS1, tmpS2; 
    612         tmpS1 = dispatch((Node)n.get(0)).toString(); 
    613         tmp1  = string2long(tmpS1); 
    614  
    615         tmpS2 = dispatch((Node)n.get(2)).toString(); 
    616         tmp2  = string2long(tmpS2); 
    617  
    618         if(n.get(1) == "+")  
    619           result = tmp1+tmp2; 
    620         else if (n.get(1) == "-") 
    621           result = tmp1-tmp2; 
    622  
    623         return Long.toString(result); 
    624       } 
    625  
    626       public String visitMultiplicativeExpression(GNode n) { 
    627         long tmp1 = 0, tmp2 = 0, result = 0; 
    628         String tmpS1, tmpS2; 
    629         tmpS1 = dispatch((Node)n.get(0)).toString(); 
    630         tmp1  = string2long(tmpS1); 
    631  
    632         tmpS2 = dispatch((Node)n.get(2)).toString(); 
    633         tmp2  = string2long(tmpS2); 
    634  
    635  
    636         if(n.get(1) == "*")  
    637           result = tmp1*tmp2; 
    638         else if (n.get(1) == "/") 
    639           result = tmp1/tmp2; 
    640         else if (n.get(1) == "%") 
    641           result = tmp1%tmp2; 
    642         return Long.toString(result); 
    643       } 
    644  
    645       public String visitIntegerConstant(GNode n) { 
    646         long intValueI; 
    647         try { 
    648           String tmpS = n.get(0).toString(); 
    649  
    650           if(tmpS.startsWith("0x")) 
    651             intValueI = Long.valueOf(tmpS.substring(2), 16); 
    652           else   
    653             intValueI = Long.valueOf(tmpS.split("u|U|l|L")[0]); 
    654         } 
    655         catch (NumberFormatException nfe) { 
    656           //System.err.println("NumberFormatException " + nfe.getLocalizedMessage()); 
    657           intValueI  = 0; 
    658         } 
    659         return Long.toString(intValueI); 
    660       } 
    661  
    662       public String visitStringConstant(GNode n) { 
    663         return  dispatch((Node)n.get(0)).toString(); 
    664       } 
    665  
    666       public String visitCPPLineTerminator(GNode n) { 
    667         return ""; 
    668       } 
    669  
    670       public String visitFunctionMacroCallParameters(GNode n) { 
    671         return  dispatch(n.getNode(0)).toString(); 
    672       } 
    673  
    674       //TODO Check why we need that 
    675       public String visit(GNode n) { 
    676         return "1"; 
    677       } 
    678  
    679     }.dispatch(parameter).toString(); 
    680     return tmpString; 
    681   } 
    682  
    683   /** 
    684    * Evaluates the function macro call 
    685    * @param n 
    686    * @return String result of the evaluation of a macro function call 
    687    */ 
    688   public String evalMacroFuncCall(GNode n) { 
    689     String result = "1"; 
    690     int i = 0; 
    691     Node parameters = (Node) ((Node) n.get(1)); 
    692     HashMap<String, String> paramValue = new HashMap<String, String>(); 
    693     for (Object  o :  parameters) { 
    694       Node parameter = (Node) o; 
    695       String paramName = retrieveFunctionMacroParamName(n.getString(0), i++); 
    696       paramValue.put(paramName,evalParameter(parameter)); 
    697     } 
    698     return result; 
    699   } 
    700  
    701   /** 
    702    * Gets the macro value 
    703    * @param macroName 
    704    * @return 
    705    */ 
    706   @SuppressWarnings("unused") 
    707   public String getMacroValue(String macroName) throws MacroUndefException { 
    708     Node macroNode = preState.getMacrosManager().retrieveMacro(macroName); 
    709     String macroValue = "0"; 
    710     if( macroNode != null ){ 
    711       macroValue = new Visitor() { 
     344    /** 
     345     * Sets the parseTree flag 
     346     * @param parseTreeFlag 
     347     *          A boolean 
     348     */ 
     349    public boolean getParseTree() { 
     350      return preState.getParseTree(); 
     351    } 
     352 
     353    /** 
     354     * Returns the include path manager. 
     355     *  
     356     * @return The include path manager. 
     357     */ 
     358    public C4IncludePathManager getIncludePathManager() { 
     359      return preState.getIncludePathManager(); 
     360    } 
     361 
     362    /** 
     363     * Increments the include level. 
     364     */ 
     365    public void incIncludeLevel() { 
     366      preState.incIncludeLevel(); 
     367    } 
     368 
     369    /** 
     370     * Decrements the include level. 
     371     */ 
     372    public void decIncludeLevel() { 
     373      preState.decIncludeLevel(); 
     374    } 
     375 
     376    public void reset(String file) { 
     377      preState.reset(file); 
     378    } 
     379 
     380    //--------------------------------------------------------------------------- 
     381    // Macros 
     382    //--------------------------------------------------------------------------- 
     383    /** 
     384     * for the String Constant with macro parameters 
     385     */ 
     386    public boolean isMacroParameter(String id) { 
     387      return preState.isMacroParameter(id); 
     388    } 
     389 
     390    /** 
     391     * Tells whether or not the token is a function Macro 
     392     * @param token 
     393     * @return true if the token is a function macro 
     394     */ 
     395    public boolean isFunctionMacro(String token) { 
     396      return preState.isFunctionMacro(token); 
     397    } 
     398 
     399    /** 
     400     * Gets the object macro associated with the token 
     401     * @param token 
     402     * @return Object representing the object macro 
     403     */ 
     404    public Object getObjectMacro(String token) { 
     405      return preState.getObjectMacro(token); 
     406    } 
     407 
     408    /** 
     409     * Tells whether or not the token is an object macro 
     410     * @param token 
     411     * @return true if the token is an object macro 
     412     */ 
     413    public boolean isObjectMacro(String token) { 
     414      return preState.isObjectMacro(token); 
     415    } 
     416 
     417    /** 
     418     * Tells whether or not the token is a macro 
     419     * @param token 
     420     * @return true if the token is a macro name 
     421     */ 
     422    public boolean isMacro(String token) { 
     423      return preState.isMacro(token); 
     424    } 
     425 
     426    /** 
     427     * Gets the function macro associated with the token 
     428     * @param token 
     429     * @return Object representing the object macro 
     430     */ 
     431    public Object getFunctionMacro(String token) { 
     432      return preState.getFunctionMacro(token); 
     433    } 
     434 
     435    /** 
     436     * Removes a macro 
     437     * @param id The name of the macro to remove 
     438     */ 
     439    public void removeMacro(String id) { 
     440      preState.removeMacro(id); 
     441    } 
     442 
     443    /** 
     444     * Gets a macro by its name 
     445     * @param macroName 
     446     * @return Node of the macro 
     447     */ 
     448    public Node getMacro(String macroName) { 
     449      return preState.getMacro(macroName); 
     450    } 
     451 
     452    /** 
     453     * Stores a new macro 
     454     * @param macroNode Node of the macro to store 
     455     */ 
     456    public void storeMacro(Node macroNode){ 
     457      preState.getMacrosManager().storeMacro(macroNode); 
     458    } 
     459 
     460    /** 
     461     * To store the parameters of a function Macro 
     462     * @param n The parameters node 
     463     */ 
     464    public void storeParameters(Node n) { 
     465      preState.storeParameters(n); 
     466    } 
     467 
     468    /** 
     469     * Clean-up function 
     470     */ 
     471    public void purgeParameters() {  
     472      preState.purgeParameters(); 
     473    } 
     474 
     475 
     476    /** 
     477     * A commodity method to convert a string as an integer 
     478     * @param tmpS1 String to be converted 
     479     * @return Integer representing the string parameter 
     480     */ 
     481    public long string2long(String tmpS1) { 
     482      long tmp1; 
     483      try { 
     484        tmp1 = Long.valueOf(tmpS1); 
     485      } catch (NumberFormatException nfe) { 
     486        System.err.println("NumberFormatException " + tmpS1); 
     487        nfe.printStackTrace(); 
     488        tmp1 = 0; 
     489      } 
     490      return tmp1; 
     491 
     492    } 
     493 
     494    /** 
     495     * Get The parameter at the index associated with the macro  
     496     * @param macroName 
     497     * @param paramIndex 
     498     * @return String representing the parameter 
     499     */ 
     500    public String retrieveFunctionMacroParamName(String macroName, int paramIndex) { 
     501      String paramName = "param"; 
     502      Node macro = preState.getMacrosManager().retrieveMacro(macroName); 
     503      Node parameterList = ((Node)((Node)macro.get(1)).get(0)); 
     504 
     505      paramName = parameterList.get(paramIndex).toString(); 
     506 
     507      return paramName; 
     508    } 
     509 
     510    /** 
     511     * Evaluates a parameter given to a Macro  
     512     * @param parameter 
     513     * @return String representing the parameter 
     514     */ 
     515    @SuppressWarnings("unused") 
     516    public String evalParameter(Node parameter) { 
     517      String tmpString = new Visitor() { 
     518 
    712519        public String visitObjectMacroValueSupported(GNode n) { 
    713           String dispatched = dispatch((Node)n.get(0)).toString(); 
    714           return dispatched; 
    715  
     520          return dispatch((Node)n.get(0)).toString(); 
    716521        } 
    717522 
    718523        public String visitObjectMacroValue(GNode n) { 
    719           return dispatch((Node)n.get(0)).toString(); 
    720         } 
    721  
    722         public String visitPrimaryIdentifier(GNode n) { 
    723           //Can happen if we have a macro defined according to another 
    724           //one not yet defined 
    725           //At this time, the macro should be defined.. 
    726           if(isMacro(n.getString(0))) { 
    727             try{ 
    728               return getMacroValue(n.getString(0)); 
    729             } catch (MacroUndefException e) { 
    730               e.printStackTrace(); 
    731               return "0"; 
    732             } 
    733           } 
    734           //System.err.println("getMacroValue Problem " + n.getString(0)); 
     524          return  dispatch((Node)n.get(0)).toString(); 
     525        } 
     526 
     527        public String visitMacroFunctionExpression(GNode n) { 
     528          evalMacroFuncCall(n); 
     529          System.out.println("EvalParameter " + n); 
    735530          return "1"; 
    736  
    737         } 
    738  
    739         public String visitUnaryMinusExpression(GNode n) { 
    740           return "-"+dispatch((Node)n.get(0)).toString(); 
    741         } 
    742  
    743         public String visitFunctionCall(GNode n) { 
    744           String functionName = n.getGeneric(0).getString(0); 
    745           GNode parameters    = n.getGeneric(2); 
    746           if(isMacro(functionName)) { 
    747             GNode tmpMacroRef = GNode.create("MacroReference", functionName,getMacro(functionName)); 
    748             GNode tmpFuncMac = GNode.create("FunctionMacroCallExpression", tmpMacroRef, parameters); 
    749             String tmpRes = computeVisitor(tmpFuncMac).toString(); 
    750             return tmpRes; 
    751           } 
    752           //Should not occur 
    753           return "1"; 
    754         } 
    755  
    756         public String visitDeclarationWithoutColon(GNode n) { 
    757           System.out.println("VisitDeclarationWithoutColon " + n); 
    758           return "1"; 
    759         } 
    760  
    761         public String visitMacroFunctionExpression(GNode n) { 
    762           return evalMacroFuncCall(n); 
    763531        } 
    764532 
    765533        public String visitMacroReference(GNode n) { 
    766534          try { 
    767             return getMacroValue(n.get(0).toString()); 
     535            return getMacroValue(n.getString(0)); 
    768536          } catch(MacroUndefException e) { 
    769             e.printStackTrace(); 
    770             return "0"; 
    771           } 
    772         } 
    773  
    774         public String visitMacroObjectAttrib(GNode n) { 
    775           try { 
    776             return getMacroValue(n.get(0).toString()); 
    777           } catch (MacroUndefException e) { 
     537            //The macro that has been given as parameter is not defined 
     538            //This is weird. 
     539            //TODO check when a macro given as a parameter could be undefined. 
    778540            e.printStackTrace(); 
    779541            return "0"; 
     
    787549          tmp1  = string2long(tmpS1); 
    788550 
    789           tmpS2 =  dispatch((Node)n.get(2)).toString(); 
     551          tmpS2 = dispatch((Node)n.get(2)).toString(); 
    790552          tmp2  = string2long(tmpS2); 
    791553 
    792554 
    793           if(n.get(1) == "<<")  
     555          if(n.getString(1) == "<<")  
    794556            result = tmp1 << tmp2; 
    795557 
     
    817579          tmp1  = string2long(tmpS1); 
    818580 
    819           tmpS2 = dispatch((Node)n.get(1)).toString(); 
     581          tmpS2 =  dispatch((Node)n.get(1)).toString(); 
    820582          tmp2  = string2long(tmpS2); 
    821583 
     
    867629          long tmp1 = 0, tmp2 = 0, result = 0; 
    868630          String tmpS1, tmpS2; 
    869           tmpS1 =  dispatch((Node)n.get(0)).toString(); 
     631          tmpS1 = dispatch((Node)n.get(0)).toString(); 
    870632          tmp1  = string2long(tmpS1); 
    871633 
    872           tmpS2 =  dispatch((Node)n.get(2)).toString(); 
     634          tmpS2 = dispatch((Node)n.get(2)).toString(); 
    873635          tmp2  = string2long(tmpS2); 
    874  
    875636 
    876637          if(n.get(1) == "+")  
     
    885646          long tmp1 = 0, tmp2 = 0, result = 0; 
    886647          String tmpS1, tmpS2; 
    887           tmpS1 =  dispatch((Node)n.get(0)).toString(); 
     648          tmpS1 = dispatch((Node)n.get(0)).toString(); 
    888649          tmp1  = string2long(tmpS1); 
    889650 
     
    904665          long intValueI; 
    905666          try { 
    906             String tmpS = n.get(0).toString(); 
     667            String tmpS = n.getString(0); 
     668 
    907669            if(tmpS.startsWith("0x")) 
    908670              intValueI = Long.valueOf(tmpS.substring(2), 16); 
     
    911673          } 
    912674          catch (NumberFormatException nfe) { 
    913             System.out.println("INTEGER CONSTANT " + n + " " + n.get(0).toString().substring(2)); 
    914675            intValueI  = 0; 
    915676          } 
     
    922683 
    923684        public String visitCPPLineTerminator(GNode n) { 
    924           //System.err.println("VisitCPPLineTerminator "); 
    925           return "";  
    926         } 
    927  
     685          return ""; 
     686        } 
     687 
     688        public String visitFunctionMacroCallParameters(GNode n) { 
     689          return  dispatch(n.getNode(0)).toString(); 
     690        } 
     691 
     692        //TODO Check why we need that 
    928693        public String visit(GNode n) { 
    929           if (n.isEmpty()) 
     694          return "1"; 
     695        } 
     696 
     697      }.dispatch(parameter).toString(); 
     698      return tmpString; 
     699    } 
     700 
     701    /** 
     702     * Evaluates the function macro call 
     703     * @param n 
     704     * @return String result of the evaluation of a macro function call 
     705     */ 
     706    public String evalMacroFuncCall(GNode n) { 
     707      String result = "1"; 
     708      int i = 0; 
     709       
     710      Node parameters = (Node) ((Node) n.get(1)); 
     711      HashMap<String, String> paramValue = new HashMap<String, String>(); 
     712      for (Object  o :  parameters) { 
     713        try{ 
     714        if(!(((Node) o).strip() instanceof GNode)) { 
     715          continue; 
     716        } 
     717 
     718        GNode parameter = (GNode)((Node) o).strip(); 
     719        String paramName = retrieveFunctionMacroParamName(n.getString(0), i++); 
     720        paramValue.put(paramName,evalParameter(parameter)); 
     721        } catch (Exception e) {  
     722          e.printStackTrace(); 
     723        } 
     724      } 
     725      return result; 
     726    } 
     727 
     728    /** 
     729     * Gets the macro value 
     730     * @param macroName 
     731     * @return 
     732     */ 
     733    @SuppressWarnings("unused") 
     734    public String getMacroValue(String macroName) throws MacroUndefException { 
     735       
     736      Node macroNode = preState.getMacrosManager().retrieveMacro(macroName); 
     737      String macroValue = "0"; 
     738      if( macroNode != null ){ 
     739        macroValue = new Visitor() { 
     740          public String visitObjectMacroValueSupported(GNode n) { 
     741            String dispatched = dispatch(n.getGeneric(0)).toString(); 
     742            return dispatched; 
     743 
     744          } 
     745 
     746          public String visitObjectMacroValue(GNode n) { 
     747            return dispatch(n.getGeneric(0)).toString(); 
     748          } 
     749 
     750          public String visitPrimaryIdentifier(GNode n) { 
     751            //Can happen if we have a macro defined according to another 
     752            //one not yet defined 
     753            //At this time, the macro should be defined.. 
     754            if(isMacro(n.getString(0))) { 
     755              try{ 
     756                return getMacroValue(n.getString(0)); 
     757              } catch (MacroUndefException e) { 
     758                e.printStackTrace(); 
     759                return "0"; 
     760              } 
     761            } 
     762             
    930763            return "1"; 
    931           return dispatch((Node)n.get(0)).toString(); 
    932         } 
    933  
    934       }.dispatch(macroNode).toString(); 
    935     } 
    936     else  
    937     { 
    938       throw new MacroUndefException(macroName); 
    939     } 
    940  
    941     return macroValue; 
    942   } 
    943  
    944  
    945   /** 
    946    * Adds a new parent when nesting a new conditional sections 
    947    */ 
    948   public void addNewParent() {  
    949     preState.getMacrosManager().addNewParent(); 
    950   } 
    951  
    952   /** 
    953    * Pushes a new macro branch 
    954    */ 
    955   public void pushMacroBranch() { 
    956     preState.getMacrosManager().pushMacroBranch(); 
    957   } 
    958  
    959   /** 
    960    * Pops the last Macro Branch  
    961    */ 
    962   public void popMacroBranch() { 
    963     preState.getMacrosManager().popMacroBranch(); 
    964   }  
    965  
    966   /** 
    967    * Determines the given header file has already been parsed or not. 
    968    *  
    969    * @param headerPath The path of the header file. 
    970    * @return True or false. 
    971    */ 
    972   public boolean hasParsed(String headerPath) { 
    973     return preState.hasParsed(headerPath); 
    974   } 
    975  
    976   /** 
    977    * Adds a header file to the list of parsed headers. 
    978    *  
    979    * @param header Absolute path of the header file. 
    980    */ 
    981   public void parsed(String header) { 
    982     preState.parsed(header); 
    983   } 
    984  
    985   /** 
    986    * Flushes the macro keyword to make them visible 
    987    */ 
    988   public void flushMacroKeyword() { 
    989     preState.macrosManager.flushMacroKeyword(); 
    990   } 
    991  
    992   /** 
    993    * Adds everything to be flushed 
    994    */ 
    995   public void addToFlush() {  
    996     preState.macrosManager.addToFlush(); 
    997   }  
    998  
    999   /** 
    1000    * Tells whether the parameter is a macro keyword 
    1001    * @param id 
    1002    * @return true if the param is a macro keyword 
    1003    */ 
    1004   public boolean isMacroKeyword(String id) {  
    1005     return (preState.isMacroKeyword(id)); 
    1006   } 
    1007  
    1008   public boolean isObjectMacroForId(String id) { 
    1009     return(preState.isObjectMacroForId(id)); 
    1010   } 
    1011    
    1012   public boolean isKernelMacroObjectKeyword(String id) {   
    1013     return (isMacroKeyword(id) && isObjectMacro(id) && (!isBlockBeginning(id)) && (!isBlockEnding(id))); 
    1014   } 
    1015    
    1016   /** 
    1017    * Adds a macro keyword 
    1018    * @param id 
    1019    */ 
    1020   public void addMacroKeyword(String id) {  
    1021     preState.getMacrosManager().addMacroKeyword(id); 
    1022   } 
    1023  
    1024   /** 
    1025    * Tells whether the macro is an attribute 
    1026    * @return 
    1027    */ 
    1028   public boolean isAttribute() { 
    1029     return isAttribute; 
    1030   } 
    1031  
    1032   /** 
    1033    * Resets the attribute boo 
    1034    */ 
    1035   public void resetAttribute() { 
    1036     isAttribute = false; 
    1037   } 
    1038  
    1039   /** 
    1040    * Sets the attribute to true 
    1041    */ 
    1042   public void setAttribute() { 
    1043     isAttribute = true; 
    1044   } 
    1045  
    1046   /** 
    1047    * Enters the Function Declaration Context 
    1048    */ 
    1049   public void setInFunctionDecl() { 
    1050     preState.setInFunctionDecl(true); 
    1051   } 
    1052  
    1053   /** 
    1054    * Exits the Function Declaration Context 
    1055    */ 
    1056   public void unsetInFunctionDecl() { 
    1057     preState.setInFunctionDecl(false); 
    1058   } 
    1059  
    1060   /** 
    1061    * Checks the Function Declaration Context 
    1062    */ 
    1063   public boolean isInFunctionDecl() { 
    1064     return preState.isInFunctionDecl(); 
    1065   } 
    1066  
    1067   /** 
    1068    * Enters the macro context. 
    1069    */ 
    1070   public void macro() { 
    1071     preState.macro(); 
    1072   } 
    1073  
    1074   /** 
    1075    * Exits the macro context. 
    1076    */ 
    1077   public void exitMacro() { 
    1078     preState.exitMacro(); 
    1079   } 
    1080  
    1081   /**  
    1082    * Enters the function Defintion context. 
    1083    */ 
    1084   public void enterFunctionDefinition() { 
    1085     preState.funcDef(); 
    1086   } 
    1087    
    1088   public void exitFunctionDefinition() { 
    1089     preState.exitFuncDef(); 
    1090   } 
    1091    
    1092   public boolean inFuncDef() { 
    1093     return preState.inFuncDefContext(); 
    1094   } 
    1095   /** 
    1096    * Checks if top is in macro context. 
    1097    *  
    1098    * @return True or False. 
    1099    */ 
    1100   public boolean inMacroContext() { 
    1101     return preState.inMacroContext(); 
    1102   } 
    1103  
    1104   /** 
    1105    * To unparse not defined Macro 
    1106    *  
    1107    */ 
    1108   public  void unparseIfDef() { 
    1109     preState.unparseIfDef(); 
    1110   } 
    1111  
    1112   /** 
    1113    * To unparse an endif 
    1114    */ 
    1115   public void unparseEndif() {  
    1116     preState.unparseEndif(); 
    1117   } 
    1118  
    1119   /** 
    1120    * Tells whether the endif must be parsed 
    1121    * @return 
    1122    */ 
    1123   public boolean toParseEndif() { 
    1124     return (preState.toParseEndif()); 
    1125   } 
    1126  
    1127  
    1128   //-------------------------------------------------------------------------- 
    1129   // Registering and Retrieving the State before and after ifSection 
    1130   // -------------------------------------------------------------------------- 
    1131   public void registerStateIfSection() { 
    1132     preState.getStateIfSectionStack().add(isDefined()); 
    1133     //BUG correction Before: 
    1134     //this.stateIfSectionStack.add(isElseParsing()); 
    1135     preState.getStateElseStack().add(isElseParsing()); 
    1136   } 
    1137  
    1138   /** 
    1139    * Retrieve the state associated with the current IfSection 
    1140    */ 
    1141   public void retrieveStateIfSection() { 
    1142     preState.retrieveStateIfSection(); 
    1143   }  
    1144  
    1145   //----------------------------------- 
    1146   // Header Name resolution when given as a Macro 
    1147   //----------------------------------- 
    1148  
    1149  
    1150   /** 
    1151    * Concate all the elements of a concatenation expresionn. 
    1152    * Starts from a bad parsing (should be only one String Constant..) 
    1153    *TODO improve the parsing of this type of concatenation 
    1154    */ 
    1155   @SuppressWarnings("unused") 
    1156   private String concatParameter(GNode funcMacroCallParams, final ArrayList<String> formal, final ArrayList<String> actual, final boolean isStringify) { 
    1157     String concatenated = ""; 
    1158     concatenated = (String) new Visitor() { 
    1159  
    1160       public String visitStringConstant(GNode stringConst) { 
    1161         if(stringConst.size() == 1) { 
    1162           if(stringConst.get(0) instanceof String) 
    1163             return stringConst.getString(0); 
     764 
     765          } 
     766 
     767          public String visitUnaryMinusExpression(GNode n) { 
     768            return "-"+dispatch(n.getGeneric(0)).toString(); 
     769          } 
     770 
     771          public String visitFunctionCall(GNode n) { 
     772            String functionName = n.getGeneric(0).getString(0); 
     773            GNode parameters    = n.getGeneric(2); 
     774            if(isMacro(functionName)) { 
     775              GNode tmpMacroRef = GNode.create("MacroReference", functionName,getMacro(functionName)); 
     776              GNode tmpFuncMac = GNode.create("FunctionMacroCallExpression", tmpMacroRef, parameters); 
     777              String tmpRes = computeVisitor(tmpFuncMac).toString(); 
     778              return tmpRes; 
     779            } 
     780            //Should not occur 
     781            return "1"; 
     782          } 
     783 
     784          public String visitDeclarationWithoutColon(GNode n) { 
     785            return "1"; 
     786          } 
     787 
     788          public String visitMacroFunctionExpression(GNode n) { 
     789            return evalMacroFuncCall(n); 
     790          } 
     791 
     792          public String visitMacroReference(GNode n) { 
     793            try { 
     794              return getMacroValue(n.getString(0)); 
     795            } catch(MacroUndefException e) { 
     796              e.printStackTrace(); 
     797              return "0"; 
     798            } 
     799          } 
     800 
     801          public String visitMacroObjectAttrib(GNode n) { 
     802            try { 
     803              return getMacroValue(n.getString(0)); 
     804            } catch (MacroUndefException e) { 
     805              e.printStackTrace(); 
     806              return "0"; 
     807            } 
     808          } 
     809 
     810          public String visitShiftExpression(GNode n) { 
     811            long tmp1 = 0, tmp2 = 0, result = 0; 
     812            String tmpS1, tmpS2; 
     813            tmpS1 = dispatch((Node)n.get(0)).toString(); 
     814            tmp1  = string2long(tmpS1); 
     815 
     816            tmpS2 =  dispatch((Node)n.get(2)).toString(); 
     817            tmp2  = string2long(tmpS2); 
     818 
     819 
     820            if(n.getString(1) == "<<")  
     821              result = tmp1 << tmp2; 
     822 
     823            return Long.toString(result); 
     824          } 
     825 
     826          public String visitLogicalOrExpression(GNode n) { 
     827            long tmp1 = 0, tmp2 = 0, result = 0; 
     828            String tmpS1, tmpS2; 
     829            tmpS1 = dispatch((Node)n.get(0)).toString(); 
     830            tmp1  = string2long(tmpS1); 
     831 
     832            tmpS2 = dispatch((Node)n.get(1)).toString(); 
     833            tmp2  = string2long(tmpS2); 
     834 
     835            result = ( tmp1 != 0 ) || ( tmp2 != 0 ) ?  1 : 0; 
     836 
     837            return Long.toString(result); 
     838          } 
     839 
     840          public String visitLogicalAndExpression(GNode n) { 
     841            long tmp1 = 0, tmp2 = 0, result = 0; 
     842            String tmpS1, tmpS2; 
     843            tmpS1 = dispatch((Node)n.get(0)).toString(); 
     844            tmp1  = string2long(tmpS1); 
     845 
     846            tmpS2 = dispatch((Node)n.get(1)).toString(); 
     847            tmp2  = string2long(tmpS2); 
     848 
     849            result = ( tmp1 != 0 ) && ( tmp2 != 0 ) ?  1 : 0; 
     850 
     851            return Long.toString(result); 
     852 
     853          } 
     854 
     855          public String visitRelationalExpression(GNode n) { 
     856            long tmp1 = 0, tmp2 = 0, result = 0; 
     857            String tmpS1, tmpS2; 
     858            tmpS1 = dispatch((Node)n.get(0)).toString(); 
     859            tmp1  = string2long(tmpS1); 
     860 
     861            tmpS2 = dispatch((Node)n.get(2)).toString(); 
     862            tmp2  = string2long(tmpS2); 
     863 
     864            if(n.getString(1) == "<")  
     865              result = tmp1 < tmp2 ?  1 : 0; 
     866            else if (n.getString(1) == ">") 
     867              result = tmp1 > tmp2 ?  1 : 0; 
     868              else if (n.getString(1) == ">=") 
     869                result = tmp1 >= tmp2 ? 1 : 0; 
     870                else if (n.getString(1) == ">=") 
     871                  result = tmp1 >= tmp2 ? 1 : 0; 
     872 
     873                  return Long.toString(result); 
     874          } 
     875 
     876          public String visitEqualityExpression(GNode n) { 
     877            long tmp1 = 0, tmp2 = 0, result = 0; 
     878            String tmpS1, tmpS2; 
     879            tmpS1 = dispatch((Node)n.get(0)).toString(); 
     880            tmp1  = string2long(tmpS1); 
     881 
     882            tmpS2 = dispatch((Node)n.get(2)).toString(); 
     883            tmp2  = string2long(tmpS2); 
     884            if(n.getString(1) == "==")  
     885              result = tmp1 == tmp2 ?  1 : 0; 
     886            else if (n.getString(1) == "!=") 
     887              result = tmp1 != tmp2 ?  1 : 0; 
     888 
     889            return Long.toString(result); 
     890 
     891          } 
     892 
     893          public String visitAdditiveExpression(GNode n) { 
     894            long tmp1 = 0, tmp2 = 0, result = 0; 
     895            String tmpS1, tmpS2; 
     896            tmpS1 =  dispatch((Node)n.get(0)).toString(); 
     897            tmp1  = string2long(tmpS1); 
     898 
     899            tmpS2 =  dispatch((Node)n.get(2)).toString(); 
     900            tmp2  = string2long(tmpS2); 
     901 
     902 
     903            if(n.getString(1) == "+")  
     904              result = tmp1+tmp2; 
     905            else if (n.getString(1) == "-") 
     906              result = tmp1-tmp2; 
     907 
     908            return Long.toString(result); 
     909          } 
     910 
     911          public String visitMultiplicativeExpression(GNode n) { 
     912            long tmp1 = 0, tmp2 = 0, result = 0; 
     913            String tmpS1, tmpS2; 
     914            tmpS1 =  dispatch((Node)n.get(0)).toString(); 
     915            tmp1  = string2long(tmpS1); 
     916 
     917            tmpS2 = dispatch((Node)n.get(2)).toString(); 
     918            tmp2  = string2long(tmpS2); 
     919 
     920 
     921            if(n.getString(1) == "*")  
     922              result = tmp1*tmp2; 
     923            else if (n.getString(1) == "/") 
     924              result = tmp1/tmp2; 
     925            else if (n.getString(1) == "%") 
     926              result = tmp1%tmp2; 
     927 
     928 
     929            return Long.toString(result); 
     930          } 
     931 
     932          public String visitIntegerConstant(GNode n) { 
     933            long intValueI; 
     934            try { 
     935              String tmpS = n.getString(0); 
     936              if(tmpS.startsWith("0x")) 
     937                intValueI = Long.valueOf(tmpS.substring(2), 16); 
     938              else   
     939                intValueI = Long.valueOf(tmpS.split("u|U|l|L")[0]); 
     940            } 
     941            catch (NumberFormatException nfe) { 
     942              intValueI  = 0; 
     943            } 
     944            return Long.toString(intValueI); 
     945          } 
     946 
     947          public String visitStringConstant(GNode n) { 
     948            return  dispatch((Node)n.get(0)).toString(); 
     949          } 
     950 
     951          public String visitCPPLineTerminator(GNode n) { 
     952            return "";  
     953          } 
     954 
     955          public String visit(GNode n) { 
     956 
     957            if (n.isEmpty()) 
     958              return "1"; 
     959            else { 
     960              return dispatch((Node)n.get(0)).toString(); 
     961            } 
     962          } 
     963 
     964        }.dispatch(macroNode).toString(); 
     965      } 
     966      else  
     967      { 
     968        throw new MacroUndefException(macroName); 
     969      } 
     970      return macroValue; 
     971    } 
     972 
     973 
     974    /** 
     975     * Adds a new parent when nesting a new conditional sections 
     976     */ 
     977    public void addNewParent() {  
     978      preState.getMacrosManager().addNewParent(); 
     979    } 
     980 
     981    /** 
     982     * Pushes a new macro branch 
     983     */ 
     984    public void pushMacroBranch() { 
     985      preState.getMacrosManager().pushMacroBranch(); 
     986    } 
     987 
     988    /** 
     989     * Pops the last Macro Branch  
     990     */ 
     991    public void popMacroBranch() { 
     992      preState.getMacrosManager().popMacroBranch(); 
     993    }  
     994 
     995    /** 
     996     * Determines the given header file has already been parsed or not. 
     997     *  
     998     * @param headerPath The path of the header file. 
     999     * @return True or false. 
     1000     */ 
     1001    public boolean hasParsed(String headerPath) { 
     1002      return preState.hasParsed(headerPath); 
     1003    } 
     1004 
     1005    /** 
     1006     * Adds a header file to the list of parsed headers. 
     1007     *  
     1008     * @param header Absolute path of the header file. 
     1009     */ 
     1010    public void parsed(String header) { 
     1011      preState.parsed(header); 
     1012    } 
     1013 
     1014    /** 
     1015     * Flushes the macro keyword to make them visible 
     1016     */ 
     1017    public void flushMacroKeyword() { 
     1018      preState.macrosManager.flushMacroKeyword(); 
     1019    } 
     1020 
     1021    /** 
     1022     * Adds everything to be flushed 
     1023     */ 
     1024    public void addToFlush() {  
     1025      preState.macrosManager.addToFlush(); 
     1026    }  
     1027 
     1028    /** 
     1029     * Tells whether the parameter is a macro keyword 
     1030     * @param id 
     1031     * @return true if the param is a macro keyword 
     1032     */ 
     1033    public boolean isMacroKeyword(String id) {  
     1034      return (preState.isMacroKeyword(id)); 
     1035    } 
     1036 
     1037    public boolean isObjectMacroForId(String id) { 
     1038      return(preState.isObjectMacroForId(id)); 
     1039    } 
     1040     
     1041    public boolean isKernelMacroObjectKeyword(String id) {   
     1042      return (isMacroKeyword(id) && isObjectMacro(id) && (!isBlockBeginning(id)) && (!isBlockEnding(id))); 
     1043    } 
     1044     
     1045    /** 
     1046     * Adds a macro keyword 
     1047     * @param id 
     1048     */ 
     1049    public void addMacroKeyword(String id) {  
     1050      preState.getMacrosManager().addMacroKeyword(id); 
     1051    } 
     1052 
     1053    /** 
     1054     * Tells whether the macro is an attribute 
     1055     * @return 
     1056     */ 
     1057    public boolean isAttribute() { 
     1058      return isAttribute; 
     1059    } 
     1060 
     1061    /** 
     1062     * Resets the attribute boo 
     1063     */ 
     1064    public void resetAttribute() { 
     1065      isAttribute = false; 
     1066    } 
     1067 
     1068    /** 
     1069     * Sets the attribute to true 
     1070     */ 
     1071    public void setAttribute() { 
     1072      isAttribute = true; 
     1073    } 
     1074 
     1075    /** 
     1076     * Enters the Function Declaration Context 
     1077     */ 
     1078    public void setInFunctionDecl() { 
     1079      preState.setInFunctionDecl(true); 
     1080    } 
     1081 
     1082    /** 
     1083     * Exits the Function Declaration Context 
     1084     */ 
     1085    public void unsetInFunctionDecl() { 
     1086      preState.setInFunctionDecl(false); 
     1087    } 
     1088 
     1089    /** 
     1090     * Checks the Function Declaration Context 
     1091     */ 
     1092    public boolean isInFunctionDecl() { 
     1093      return preState.isInFunctionDecl(); 
     1094    } 
     1095 
     1096    /** 
     1097     * Enters the macro context. 
     1098     */ 
     1099    public void macro() { 
     1100      preState.macro(); 
     1101    } 
     1102 
     1103    /** 
     1104     * Exits the macro context. 
     1105     */ 
     1106    public void exitMacro() { 
     1107      preState.exitMacro(); 
     1108    } 
     1109 
     1110    /**  
     1111     * Enters the function Defintion context. 
     1112     */ 
     1113    public void enterFunctionDefinition() { 
     1114      preState.funcDef(); 
     1115    } 
     1116     
     1117    public void exitFunctionDefinition() { 
     1118      preState.exitFuncDef(); 
     1119    } 
     1120     
     1121    public boolean inFuncDef() { 
     1122      return preState.inFuncDefContext(); 
     1123    } 
     1124    /** 
     1125     * Checks if top is in macro context. 
     1126     *  
     1127     * @return True or False. 
     1128     */ 
     1129    public boolean inMacroContext() { 
     1130      return preState.inMacroContext(); 
     1131    } 
     1132 
     1133    /** 
     1134     * To unparse not defined Macro 
     1135     *  
     1136     */ 
     1137    public  void unparseIfDef() { 
     1138      preState.unparseIfDef(); 
     1139    } 
     1140 
     1141    /** 
     1142     * To unparse an endif 
     1143     */ 
     1144    public void unparseEndif() {  
     1145      preState.unparseEndif(); 
     1146    } 
     1147 
     1148    /** 
     1149     * Tells whether the endif must be parsed 
     1150     * @return 
     1151     */ 
     1152    public boolean toParseEndif() { 
     1153      return (preState.toParseEndif()); 
     1154    } 
     1155 
     1156 
     1157    //-------------------------------------------------------------------------- 
     1158    // Registering and Retrieving the State before and after ifSection 
     1159    // -------------------------------------------------------------------------- 
     1160    public void registerStateIfSection() { 
     1161      preState.getStateIfSectionStack().add(isDefined()); 
     1162      //BUG correction Before: 
     1163      //this.stateIfSectionStack.add(isElseParsing()); 
     1164      preState.getStateElseStack().add(isElseParsing()); 
     1165    } 
     1166 
     1167    /** 
     1168     * Retrieve the state associated with the current IfSection 
     1169     */ 
     1170    public void retrieveStateIfSection() { 
     1171      preState.retrieveStateIfSection(); 
     1172    }  
     1173 
     1174    //----------------------------------- 
     1175    // Header Name resolution when given as a Macro 
     1176    //----------------------------------- 
     1177 
     1178 
     1179    /** 
     1180     * Concate all the elements of a concatenation expresionn. 
     1181     * Starts from a bad parsing (should be only one String Constant..) 
     1182     *TODO improve the parsing of this type of concatenation 
     1183     */ 
     1184    @SuppressWarnings("unused") 
     1185    private String concatParameter(GNode funcMacroCallParams, final ArrayList<String> formal, final ArrayList<String> actual, final boolean isStringify) { 
     1186      String concatenated = ""; 
     1187      concatenated = (String) new Visitor() { 
     1188 
     1189        public String visitStringConstant(GNode stringConst) { 
     1190          if(stringConst.size() == 1) { 
     1191            if(stringConst.get(0) instanceof String) 
     1192              return stringConst.getString(0); 
     1193            else 
     1194              return (String) dispatch(stringConst.getGeneric(0)); 
     1195          } 
     1196          else return "";  
     1197        } 
     1198 
     1199        public String visitMacroReference(GNode macroRef) { 
     1200          if(isStringify) 
     1201            return (macroRef.getString(0)); 
    11641202          else 
    1165             return (String) dispatch(stringConst.getGeneric(0)); 
    1166         } 
    1167         else return "";  
    1168       } 
    1169  
    1170       public String visitMacroReference(GNode macroRef) { 
    1171         if(isStringify) 
    1172           return (macroRef.getString(0)); 
    1173         else 
    1174           return ((String) dispatch(macroRef.getGeneric(1))); 
    1175       } 
    1176  
    1177       public String visitMacroIdentifierConstant(GNode macroIdConst) { 
    1178         String tmpParam = macroIdConst.getString(0); 
    1179  
    1180         if(formal.contains(tmpParam)) 
    1181           return actual.get(formal.indexOf(tmpParam)); 
    1182         else  
    1183           return ""; 
    1184       } 
    1185  
    1186       public String visitDirectComponentSelection(GNode directComp) { 
    1187         return dispatch(directComp.getGeneric(0)) + "." + directComp.getString(1); 
    1188       } 
    1189  
    1190       public String visitVariadicConcatenateExpression(GNode varConc) { 
    1191         return (String) dispatch(varConc.getGeneric(0)) + dispatch(varConc.getGeneric(2)); 
    1192       } 
    1193  
    1194       public String visitPrimaryIdentifier(GNode pId) { 
    1195         return pId.getString(0); 
    1196       } 
    1197  
    1198       public String visitMultiplicativeExpression(GNode addExpr) { 
    1199         return dispatch(addExpr.getGeneric(0)) + addExpr.getString(1) + dispatch(addExpr.getGeneric(2)); 
    1200       } 
    1201  
    1202       public String visitAdditiveExpression(GNode addExpr) { 
    1203         return dispatch(addExpr.getGeneric(0)) + addExpr.getString(1) + dispatch(addExpr.getGeneric(2)); 
    1204       } 
    1205  
    1206       public String visitFunctionMacroCallParameters(GNode funcMacroCallParams) { 
    1207         String concatenateParam = ""; 
    1208         for (Iterator<Object> iterator = funcMacroCallParams.iterator(); iterator.hasNext();) { 
    1209           Object childo = (Object) iterator.next(); 
    1210           if(childo instanceof Node) 
    1211             concatenateParam = concatenateParam + dispatch((GNode) childo); 
    1212           else 
    1213             concatenateParam = concatenateParam + (String) childo; 
    1214  
    1215         } 
    1216         return concatenateParam; 
    1217       } 
    1218     }.dispatch(funcMacroCallParams); 
    1219     return concatenated; 
    1220   } 
    1221  
    1222   /** 
    1223    *tells whether the FunctionMacroCallParameters given to the macro should be concatenated. 
    1224    */ 
    1225   @SuppressWarnings("unused") 
    1226   private boolean isConcat(GNode funcMacroCallParams) { 
    1227     boolean isConcat = false; 
    1228     for (Iterator<Object> iterator = funcMacroCallParams.iterator(); iterator.hasNext();) { 
    1229       Object childo = (Object) iterator.next(); 
    1230       if(childo instanceof Node) { 
    1231  
    1232         boolean tmpBool = ((Boolean) new Visitor() { 
    1233           boolean tmpConcat = false; 
    1234  
    1235           public Boolean visit(GNode node) { 
    1236             for(int i = 0; i< node.size(); i++) { 
    1237               if(node.get(i) instanceof GNode) { 
    1238                 GNode tmpGen = node.getGeneric(i); 
    1239                 if(tmpGen.getName().equals("VariadicConcatenateExpression") || tmpGen.getName().equals("StringConcatenateExpression") ) { 
    1240                   return true; 
    1241                 } 
     1203            return ((String) dispatch(macroRef.getGeneric(1))); 
     1204        } 
     1205 
     1206        public String visitMacroIdentifierConstant(GNode macroIdConst) { 
     1207          String tmpParam = macroIdConst.getString(0); 
     1208 
     1209          if(formal.contains(tmpParam)) 
     1210            return actual.get(formal.indexOf(tmpParam)); 
     1211          else  
     1212            return ""; 
     1213        } 
     1214 
     1215        public String visitDirectComponentSelection(GNode directComp) { 
     1216          return dispatch(directComp.getGeneric(0)) + "." + directComp.getString(1); 
     1217        } 
     1218 
     1219        public String visitVariadicConcatenateExpression(GNode varConc) { 
     1220          return (String) dispatch(varConc.getGeneric(0)) + dispatch(varConc.getGeneric(2)); 
     1221        } 
     1222 
     1223        public String visitPrimaryIdentifier(GNode pId) { 
     1224          return pId.getString(0); 
     1225        } 
     1226 
     1227        public String visitMultiplicativeExpression(GNode addExpr) { 
     1228          return dispatch(addExpr.getGeneric(0)) + addExpr.getString(1) + dispatch(addExpr.getGeneric(2)); 
     1229        } 
     1230 
     1231        public String visitAdditiveExpression(GNode addExpr) { 
     1232          return dispatch(addExpr.getGeneric(0)) + addExpr.getString(1) + dispatch(addExpr.getGeneric(2)); 
     1233        } 
     1234 
     1235        public String visitFunctionMacroCallParameters(GNode funcMacroCallParams) { 
     1236          String concatenateParam = ""; 
     1237          for (Iterator<Object> iterator = funcMacroCallParams.iterator(); iterator.hasNext();) { 
     1238            Object childo = (Object) iterator.next(); 
     1239            if(childo instanceof Node) 
     1240              concatenateParam = concatenateParam + dispatch((GNode) childo); 
     1241            else 
     1242              concatenateParam = concatenateParam + (String) childo; 
     1243 
     1244          } 
     1245          return concatenateParam; 
     1246        } 
     1247      }.dispatch(funcMacroCallParams); 
     1248      return concatenated; 
     1249    } 
     1250 
     1251    /** 
     1252     *tells whether the FunctionMacroCallParameters given to the macro should be concatenated. 
     1253     */ 
     1254    @SuppressWarnings("unused") 
     1255    private boolean isConcat(GNode funcMacroCallParams) { 
     1256      boolean isConcat = false; 
     1257      for (Iterator<Object> iterator = funcMacroCallParams.iterator(); iterator.hasNext();) { 
     1258        Object childo = (Object) iterator.next(); 
     1259        if(childo instanceof GNode) { 
     1260 
     1261          boolean tmpBool = ((Boolean) new Visitor() { 
     1262            boolean tmpConcat = false; 
     1263 
     1264            public Boolean visit(GNode node) { 
     1265              for(int i = 0; i< node.size(); i++) { 
     1266                if(node.get(i) instanceof GNode) { 
     1267                  GNode tmpGen = node.getGeneric(i); 
     1268                  if(tmpGen.getName().equals("VariadicConcatenateExpression") || tmpGen.getName().equals("StringConcatenateExpression") ) { 
     1269                    return true; 
     1270                  } 
     1271                  else 
     1272                    tmpConcat = tmpConcat || ((Boolean) dispatch(node.getGeneric(i))).booleanValue(); 
     1273 
     1274                }  
     1275              } 
     1276 
     1277              return tmpConcat; 
     1278 
     1279            } 
     1280          }.dispatch((GNode) childo)).booleanValue(); 
     1281 
     1282          isC