@Override
  public void typeCheck() {
    for (String type : mExtensions.keySet()) {
      int lineNum = mExtensions.get(type);
      Declaration d = mCompiler.getDeclaration(type);
      if (!(d instanceof ProtocolDeclaration)) {
        Compiler.typeError(fullName(), lineNum, type + " is not a Protocol");
      }
      if (type.equals(fullName())) {
        Compiler.typeError(fullName(), lineNum, fullName() + " cannot extend itself");
      }
      for (String f : ((ProtocolDeclaration) d).mOffsets.keySet()) {
        addFunction(f, lineNum);
      }
    }

    for (Declaration declaration : mImplementers.values()) {
      // TODO must not include static functions
      for (String f : mOffsets.keySet()) {
        if (!declaration.hasFunction(f)) {
          Compiler.typeError(
              declaration.fullName(),
              0,
              declaration.fullName() + " does not implement " + fullName() + ", missing " + f);
        }
      }
    }
  }
예제 #2
0
 public static void log(File logFile, ArrayList<AssemblyStatement> instructions) {
   PrintWriter out;
   try {
     out = new PrintWriter(logFile);
     // log instructions
     for (AssemblyStatement s : instructions) {
       out.write(s.mAddress + " : " + s + "\n");
     }
     out.close();
   } catch (Exception e) {
     Compiler.ioError(e);
   }
 }
예제 #3
0
 public static void write(File outFile, ArrayList<AssemblyStatement> instructions) {
   DataOutputStream out;
   try {
     if (!outFile.exists()) {
       outFile.createNewFile();
     }
     out = new DataOutputStream(new FileOutputStream(outFile));
     // write instructions
     for (AssemblyStatement s : instructions) {
       out.writeLong(s.emit());
     }
     out.close();
   } catch (Exception e) {
     Compiler.ioError(e);
   }
 }
 public void addFunction(String name, int lineNum) {
   if (mOffsets.containsKey(name)) {
     Compiler.syntaxError(name, lineNum, name + " was already declared");
   }
   mOffsets.put(name, mOffset++);
 }