⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 namecheck.jrag

📁 JDK1.4编译器前端
💻 JRAG
📖 第 1 页 / 共 2 页
字号:
  }  syn boolean VarAccess.inSameInitializer() {    BodyDecl b = closestBodyDecl(decl().hostType());    if(b == null) return false;    if(b instanceof FieldDeclaration && ((FieldDeclaration)b).isStatic() == decl().isStatic())      return true;    if(b instanceof InstanceInitializer && !decl().isStatic())      return true;    if(b instanceof StaticInitializer && decl().isStatic())      return true;    return false;  }  syn boolean VarAccess.simpleAssignment() = isDest() && getParent() instanceof AssignSimpleExpr;  syn boolean VarAccess.inDeclaringClass() = hostType() == decl().hostType();  inh boolean TypeDecl.hasPackage(String packageName);  inh boolean PackageAccess.hasPackage(String packageName);  inh ASTNode TypeDecl.enclosingBlock();  eq MethodDecl.getBlock().enclosingBlock() = this;  eq ConstructorDecl.getBlock().enclosingBlock() = this;  eq InstanceInitializer.getBlock().enclosingBlock() = this;  eq Program.getChild().enclosingBlock() = null;  public void TypeDecl.nameCheck() {    if(isTopLevelType() && lookupType(packageName(), name()) != this)      error("duplicate member " + name() + " in compilation unit");      if(!isTopLevelType() && !isAnonymous() && !isLocalClass() && extractSingleType(enclosingType().memberTypes(name())) != this)      error("duplicate member type " + name() + " in type " + enclosingType().typeName());    // 14.3    if(isLocalClass()) {      TypeDecl typeDecl = extractSingleType(lookupType(name()));      if(typeDecl != null && typeDecl != this && typeDecl.isLocalClass() && enclosingBlock() == typeDecl.enclosingBlock())        error("local class named " + name() + " may not be redeclared as a local class in the same block");    }    if(!packageName().equals("") && hasPackage(fullName()))      error("duplicate member class and package " + name());        // 8.1 & 9.1    if(hasEnclosingTypeDecl(name())) {      error("type may not have the same simple name as an enclosing type declaration");    }  }  syn boolean TypeDecl.hasEnclosingTypeDecl(String name) {    TypeDecl enclosingType = enclosingType();    if(enclosingType != null) {      return enclosingType.name().equals(name) || enclosingType.hasEnclosingTypeDecl(name);    }    return false;  }  public void FieldDeclaration.nameCheck() {    super.nameCheck();    // 8.3    for(Iterator iter = hostType().memberFields(name()).iterator(); iter.hasNext(); ) {      Variable v = (Variable)iter.next();      if(v != this && v.hostType() == hostType())        error("field named " + name() + " is multiply declared in type " + hostType().typeName());    }  }  inh VariableScope ParameterDeclaration.outerScope();  inh VariableScope VariableDeclaration.outerScope();  eq CatchClause.getParameter().outerScope() = this;  eq Block.getStmt().outerScope() = this;  eq TypeDecl.getBodyDecl().outerScope() = this;  eq ForStmt.getInitStmt().outerScope() = this;  eq ForStmt.getStmt().outerScope() = this;  eq Program.getChild().outerScope() {    throw new UnsupportedOperationException("outerScope() not defined");  }  public void VariableDeclaration.nameCheck() {    SimpleSet decls = outerScope().lookupVariable(name());    for(Iterator iter = decls.iterator(); iter.hasNext(); ) {      Variable var = (Variable)iter.next();      if(var instanceof VariableDeclaration) {        VariableDeclaration decl = (VariableDeclaration)var;        if(decl != this && decl.enclosingBodyDecl() == enclosingBodyDecl())  	      error("duplicate declaration of local variable " + name() + " in enclosing scope");      }      // 8.4.1      else if(var instanceof ParameterDeclaration) {        ParameterDeclaration decl = (ParameterDeclaration)var;	      if(decl.enclosingBodyDecl() == enclosingBodyDecl())  	      error("duplicate declaration of local variable and parameter " + name());      }    }    if(getParent().getParent() instanceof Block) {      Block block = (Block)getParent().getParent();      for(int i = 0; i < block.getNumStmt(); i++) {        if(block.getStmt(i) instanceof Variable) {          Variable v = (Variable)block.getStmt(i);          if(v.name().equals(name()) && v != this) {     	    error("duplicate declaration of local variable " + name());          }	}      }    }  }    public void ParameterDeclaration.nameCheck() {    SimpleSet decls = outerScope().lookupVariable(name());    for(Iterator iter = decls.iterator(); iter.hasNext(); ) {      Variable var = (Variable)iter.next();      if(var instanceof VariableDeclaration) {        VariableDeclaration decl = (VariableDeclaration)var;	      if(decl.enclosingBodyDecl() == enclosingBodyDecl())  	      error("duplicate declaration of local variable " + name());      }      else if(var instanceof ParameterDeclaration) {        ParameterDeclaration decl = (ParameterDeclaration)var;	      if(decl.enclosingBodyDecl() == enclosingBodyDecl())          error("duplicate declaration of local variable " + name());      }    }    // 8.4.1      if(!lookupVariable(name()).contains(this)) {      error("duplicate declaration of parameter " + name());    }  }  inh BodyDecl ParameterDeclaration.enclosingBodyDecl();    public void LabeledStmt.nameCheck() {    LabeledStmt stmt = lookupLabel(getLabel());    if(stmt != null) {      if(stmt.enclosingBodyDecl() == enclosingBodyDecl()) {        error("Labels can not shadow labels in the same member");      }    }  }    inh boolean BreakStmt.insideLoop();  inh boolean ContinueStmt.insideLoop();  eq Program.getChild().insideLoop() = false;  eq TypeDecl.getBodyDecl(int i).insideLoop() = false;  eq ForStmt.getStmt().insideLoop() = true;  eq WhileStmt.getStmt().insideLoop() = true;  eq DoStmt.getStmt().insideLoop() = true;    inh boolean BreakStmt.insideSwitch();  eq Program.getChild().insideSwitch() = false;  eq TypeDecl.getBodyDecl(int i).insideSwitch() = false;  eq SwitchStmt.getBlock().insideSwitch() = true;  public void BreakStmt.nameCheck() {    if(!hasLabel() && !insideLoop() && !insideSwitch())      error("break outside switch or loop");    else if(hasLabel()) {      LabeledStmt label = lookupLabel(getLabel());      if(label == null)        error("labeled break must have visible matching label");    }  }    public void ContinueStmt.nameCheck() {    if(!insideLoop())      error("continue outside loop");    else if(hasLabel()) {      LabeledStmt label = lookupLabel(getLabel());      if(label == null)        error("labeled continue must have visible matching label");      else if(!label.getStmt().continueLabel())        error(getLabel() + " is not a loop label");    }  }  syn boolean Stmt.continueLabel() = false;  eq ForStmt.continueLabel() = true;  eq WhileStmt.continueLabel() = true;  eq DoStmt.continueLabel() = true;    public void ConstCase.nameCheck() {    if(getValue().isConstant() && bind(this) != this) {      error("constant expression " + getValue() + " is multiply declared in two case statements");    }  }  public void DefaultCase.nameCheck() {    if(bind(this) != this) {      error("only one default case statement allowed");    }  }  inh lazy Case Case.bind(Case c);  eq SwitchStmt.getBlock().bind(Case c) {    Block b = getBlock();    for(int i = 0; i < b.getNumStmt(); i++)      if(b.getStmt(i) instanceof Case && ((Case)b.getStmt(i)).constValue(c))        return (Case)b.getStmt(i);    return null;  }  eq Program.getChild().bind(Case c) = null;  syn boolean TypeDecl.assignableToInt() = false;  eq IntegralType.assignableToInt() = true;  eq LongType.assignableToInt() = false;  syn boolean Case.constValue(Case c);  eq ConstCase.constValue(Case c) {    if(!(c instanceof ConstCase) || !getValue().isConstant())      return false;    if(!getValue().type().assignableToInt() || !((ConstCase)c).getValue().type().assignableToInt())      return false;    return getValue().constant().intValue() == ((ConstCase)c).getValue().constant().intValue();  }  eq DefaultCase.constValue(Case c) = c instanceof DefaultCase;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -