예제 #1
0
  @Override
  public boolean analyze(
      SalsaNode parent, Map<String, SymbolType> typeEnv, Map<String, SymbolType> knownTypes) {
    // Make a copy first
    knownTypes = new HashMap<String, SymbolType>(CompilerHelper.initKnownTypes);
    typeEnv = new HashMap<String, SymbolType>();
    // Add import types into knownTypes
    for (String className : imports) {
      if (!className.endsWith("*")) {
        SymbolType st = CompilerHelper.getSymbolTypeByName(knownTypes, className);
        if (st == null) System.err.println("ERROR: Cannot find " + className);
        else {
          // Put into the typEnv for classes that contain static fields
          CompilerHelper.addStaticTypeEnv(typeEnv, st);
        }
      } else {
        int index = className.lastIndexOf('.');
        String prefix = className;
        if (index > 0) {
          prefix = className.substring(0, index);
        }
        CompilerHelper.classPrefixes.add(prefix);
      }
    }
    // Add necessary library classes into knownTypes
    CompilerHelper.getSymbolTypeByName(knownTypes, "java.lang.String");
    CompilerHelper.getSymbolTypeByName(knownTypes, "java.lang.Object");

    for (Iterator<TypeDeclaration> it = typeDeclarations.iterator(); it.hasNext(); ) {
      it.next().analyze(this, new HashMap<String, SymbolType>(typeEnv), knownTypes);
    }
    return true;
  }
예제 #2
0
 public void analyzeMethod(Map<String, SymbolType> knownTypes) {
   // Following code is repeated in analyze(), need rework...
   // Make a copy first
   knownTypes = new HashMap<String, SymbolType>(CompilerHelper.initKnownTypes);
   // Add import types into knownTypes
   for (String className : imports) {
     if (!className.endsWith("*")) {
       SymbolType st = CompilerHelper.getSymbolTypeByName(knownTypes, className);
       if (st == null) System.err.println("ERROR: Cannot find " + className);
       else {
         // Put into the typEnv for classes that contain static fields
       }
     } else {
       int index = className.lastIndexOf('.');
       String prefix = className;
       if (index > 0) {
         prefix = className.substring(0, index);
       }
       CompilerHelper.classPrefixes.add(prefix);
     }
   }
   // Add necessary library classes into knownTypes
   CompilerHelper.getSymbolTypeByName(knownTypes, "java.lang.String");
   CompilerHelper.getSymbolTypeByName(knownTypes, "java.lang.Object");
   for (Iterator<TypeDeclaration> it = typeDeclarations.iterator(); it.hasNext(); ) {
     it.next().analyzeMethod(knownTypes);
   }
 }