Skip to content
Snippets Groups Projects
Select Git revision
  • d2bc2971509e3eb87f39a0139e6e75a8f104a93d
  • main default protected
  • cont-frb/moberg-review
  • v0.9.26
  • v0.9.25
  • v0.9.24
  • v0.9.23
  • v0.9.22
  • v0.9.21
  • v0.9.20
  • v0.9.19
  • v0.9.18
  • v0.9.17
  • v0.9.16
  • v0.9.15
  • v0.9.14
  • v0.9.13
  • v0.9.12
  • v0.9.11
  • v0.9.10
  • v0.9.9
  • v0.9.8
  • v0.9.7
23 results

setup.py

Blame
  • NameAnalysis.jrag 1.55 KiB
    
    aspect NameAnalysis {
    
      inh String Decl.lookupName(String name);
      eq Program.getDecl(int index).lookupName(String name) {
        for (int i = 0; i < index; i++) {
          String s = getDecl(i).getName();
          if (s.equals(name)) {
          	return s;
          }
        }
        return null;
      }
      inh String Field.lookupName(String name);
      eq StructType.getField(int index).lookupName(String name) {
        for (int i = 0; i < index; i++) {
          String s = getField(i).getName();
          if (s.equals(name)) {
          	return s;
          }
        }
        return null;
      }
    
      inh TypeDecl Decl.lookupType(String name);
      inh TypeDecl UserType.lookupType(String name);
      eq Program.getDecl(int index).lookupType(String name) {
        for(int i = 0; i < index; i++) {
          Decl d = getDecl(i);  
          if(d instanceof TypeDecl && d.getName().equals(name)) {
    	return (TypeDecl)d;
          }
        }
        return null;
      }
    
      syn TypeDecl Type.decl(); 
      eq Type.decl() = null;
      eq UserType.decl() = lookupType(getName());
      eq PrimType.decl() = null; //HERE BE DRAGONS XXX
      
      
      public void ASTNode.nameCheck() {
        for (int i = 0; i < getNumChild(); i++) {
          getChild(i).nameCheck();
        }
      }
      
      public void Decl.nameCheck() {
        if (lookupType(getName()) != null || lookupName(getName()) != null) {
          error(getName() + " multiply declared");
        }
      }
      
      public void Field.nameCheck() {
        if(lookupName(getName()) != null) {
          error(getName() + " multiply declared");
        }
      }
      
      public void UserType.nameCheck() {
        if (decl() == null) {
          error("Use of undeclared type");
        } 
      }
    
    }