Пример #1
0
 private List<Declaration> getInheritedMembers(String name, List<TypeDeclaration> visited) {
   List<Declaration> members = new ArrayList<Declaration>();
   for (TypeDeclaration t : getSatisfiedTypeDeclarations()) {
     // if ( !(t instanceof TypeParameter) ) { //don't look for members in a type parameter with a
     // self-referential lower bound
     for (Declaration d : t.getMembers(name, visited)) {
       if (d.isShared() && isResolvable(d)) {
         if (!contains(members, d)) {
           members.add(d);
         }
       }
     }
     // }
   }
   TypeDeclaration et = getExtendedTypeDeclaration();
   if (et != null) {
     for (Declaration d : et.getMembers(name, visited)) {
       if (d.isShared() && isResolvable(d)) {
         if (!contains(members, d)) {
           members.add(d);
         }
       }
     }
   }
   return members;
 }
    public int compare(Declaration d1, Declaration d2) {
      if (equals(d1, d2)) return 0;

      SourcePosition p1 = d1.getPosition();
      SourcePosition p2 = d2.getPosition();

      if (p1 == null && p2 != null) return 1;
      else if (p1 != null && p2 == null) return -1;
      else if (p1 == null && p2 == null) return compareEqualPosition(d1, d2);
      else {
        assert p1 != null && p2 != null;
        int fileComp = p1.file().compareTo(p2.file());
        if (fileComp == 0) {
          long diff = (long) p1.line() - (long) p2.line();
          if (diff == 0) {
            diff = Long.signum((long) p1.column() - (long) p2.column());
            if (diff != 0) return (int) diff;
            else {
              // declarations may be two
              // compiler-generated members with the
              // same source position
              return compareEqualPosition(d1, d2);
            }
          } else return (diff < 0) ? -1 : 1;
        } else return fileComp;
      }
    }
Пример #3
0
  protected void findConstructor(Declaration[] declarations) throws NoSuchMethodException {
    int N = this.abducibleArgs.length;

    cachedConstructor = null;
    List<Class> availableArgs = N > 0 ? new ArrayList<Class>(N) : Collections.<Class>emptyList();
    for (int j = 0; j < N; j++) {
      // during the initial build (KieBuilder), the declarations are provided on the fly and use for
      // type checking
      // when building the KieBase, the internal declarations are set and can be used
      Declaration decl =
          declarations != null ? declarations[mapArgToParam(j)] : getDeclaration(abducibleArgs[j]);
      if (decl != null) {
        availableArgs.add(decl.getExtractor().getExtractToClass());
      }
    }
    Class klass = returnType.getClassType();
    while (cachedConstructor == null) {
      try {
        cachedConstructor =
            klass.getConstructor(availableArgs.toArray(new Class[availableArgs.size()]));
      } catch (NoSuchMethodException nsme) {
        if (klass == Object.class) {
          throw nsme;
        } else {
          klass = klass.getSuperclass();
        }
      }
    }
  }
Пример #4
0
 private SupertypeDeclaration getMemberInternal(
     String name, List<ProducedType> signature, boolean variadic) {
   // first search for the member in the local
   // scope, including non-shared declarations
   Declaration d = getDirectMember(name, signature, variadic);
   if (d != null && d.isShared()) {
     // if it's shared, it's what we're
     // looking for, return it
     // TODO: should also return it if we're
     //      calling from local scope!
     if (signature != null && isAbstraction(d)) {
       // look for a supertype decl that matches the signature better
       SupertypeDeclaration sd = getSupertypeDeclaration(name, signature, variadic);
       Declaration sm = sd.getMember();
       if (sm != null && !isAbstraction(sm)) {
         return sd;
       }
     }
     return new SupertypeDeclaration(d, false);
   } else {
     // now look for inherited shared declarations
     SupertypeDeclaration sd = getSupertypeDeclaration(name, signature, variadic);
     if (sd.getMember() != null || sd.isAmbiguous()) {
       return sd;
     }
   }
   // finally return the non-shared member we
   // found earlier, so that the caller can give
   // a nice error message
   return new SupertypeDeclaration(d, false);
 }
Пример #5
0
  private void replaceDeclarations(
      DeclarationScopeResolver resolver, Pattern pattern, Constraint constraint) {
    Declaration[] decl = constraint.getRequiredDeclarations();
    for (Declaration aDecl : decl) {
      Declaration resolved = resolver.getDeclaration(null, aDecl.getIdentifier());

      if (constraint instanceof MvelConstraint && ((MvelConstraint) constraint).isUnification()) {
        if (ClassObjectType.DroolsQuery_ObjectType.isAssignableFrom(
            resolved.getPattern().getObjectType())) {
          Declaration redeclaredDeclr =
              new Declaration(
                  resolved.getIdentifier(),
                  ((MvelConstraint) constraint).getFieldExtractor(),
                  pattern,
                  false);
          pattern.addDeclaration(redeclaredDeclr);
        } else if (resolved.getPattern() != pattern) {
          ((MvelConstraint) constraint).unsetUnification();
        }
      }

      if (resolved != null && resolved != aDecl && resolved.getPattern() != pattern) {
        constraint.replaceDeclaration(aDecl, resolved);
      } else if (resolved == null) {
        // it is probably an implicit declaration, so find the corresponding pattern
        Pattern old = aDecl.getPattern();
        Pattern current = resolver.findPatternByIndex(old.getIndex());
        if (current != null && old != current) {
          resolved = new Declaration(aDecl.getIdentifier(), aDecl.getExtractor(), current);
          constraint.replaceDeclaration(aDecl, resolved);
        }
      }
    }
  }
  /**
   * Visits a class declaration.
   *
   * @param d the declaration to visit
   */
  public void visitClassDeclaration(ClassDeclaration d) {
    d.accept(pre);

    SortedSet<Declaration> decls = new TreeSet<Declaration>(SourceOrderDeclScanner.comparator);

    for (TypeParameterDeclaration tpDecl : d.getFormalTypeParameters()) {
      decls.add(tpDecl);
    }

    for (FieldDeclaration fieldDecl : d.getFields()) {
      decls.add(fieldDecl);
    }

    for (MethodDeclaration methodDecl : d.getMethods()) {
      decls.add(methodDecl);
    }

    for (TypeDeclaration typeDecl : d.getNestedTypes()) {
      decls.add(typeDecl);
    }

    for (ConstructorDeclaration ctorDecl : d.getConstructors()) {
      decls.add(ctorDecl);
    }

    for (Declaration decl : decls) decl.accept(this);

    d.accept(post);
  }
  @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);
        }
      }
    }
  }
Пример #8
0
 static Expression derefFunc(Expression afunc) {
   if (afunc instanceof ReferenceExp) {
     Declaration func_decl = ((ReferenceExp) afunc).binding;
     func_decl = Declaration.followAliases(func_decl);
     if (func_decl != null && !func_decl.getFlag(Declaration.IS_UNKNOWN))
       afunc = func_decl.getValue();
   }
   return afunc;
 }
Пример #9
0
 @Override
 public boolean satisfies(TypeDeclaration type) {
   if (type.equals(TypeDeclaration.this)) {
     return false;
   } else {
     Declaration dm = type.getDirectMember(member.getName(), signature, false);
     return dm != null && dm.equals(member);
   }
 }
Пример #10
0
 private void processEvalCondition(DeclarationScopeResolver resolver, EvalCondition element) {
   Declaration[] decl = element.getRequiredDeclarations();
   for (Declaration aDecl : decl) {
     Declaration resolved = resolver.getDeclaration(null, aDecl.getIdentifier());
     if (resolved != null && resolved != aDecl) {
       element.replaceDeclaration(aDecl, resolved);
     }
   }
 }
  /* some straightforward attribute - accessor/mutator checks */
  public void testAccessors() {
    testSetValidDefinitions();

    assertTrue(!dvar.isScopeHolder());
    assertTrue(dfn.isScopeHolder());

    //		assert (dvar.isDefining ());

    assertTrue(dvar.getUnqualifiedName().equals(VARID));
  }
Пример #12
0
  public static void ajouterDeclaratioInvalide(Declaration declaration) {
    if (declaration != null
        && regle.Declaration.estOrdreValide(declaration.getOrdre())
        && !regle.Declaration.getRegle(declaration.getOrdre())
            .possedeNumeroDePermisValide(declaration)) {
      STATISTIQUE.nbDeclarationsNumeroInvalide++;
    }

    STATISTIQUE.nbDeclarationsIncompletesOuInvalide++;
  }
 private JSType lookupTypeByName(
     String name, Node n, DeclaredTypeRegistry registry, ImmutableList<String> outerTypeParameters)
     throws UnknownTypeException {
   String tvar = UniqueNameGenerator.findGeneratedName(name, outerTypeParameters);
   if (tvar != null) {
     return JSType.fromTypeVar(tvar);
   }
   Declaration decl = registry.getDeclaration(QualifiedName.fromQualifiedString(name), true);
   if (decl == null) {
     unknownTypeNames.put(n, name);
     throw new UnknownTypeException("Unhandled type: " + name);
   }
   // It's either a typedef, an enum, a type variable or a nominal type
   if (decl.getTypedef() != null) {
     return getTypedefType(decl.getTypedef(), registry);
   }
   if (decl.getEnum() != null) {
     return getEnumPropType(decl.getEnum(), registry);
   }
   if (decl.isTypeVar()) {
     howmanyTypeVars++;
     return decl.getTypeOfSimpleDecl();
   }
   if (decl.getNominal() != null) {
     return getNominalTypeHelper(decl.getNominal(), n, registry, outerTypeParameters);
   }
   return JSType.UNKNOWN;
 }
 @SuppressWarnings("unchecked")
 static <E extends Element> E cleanClone(E e) {
   E c = (E) e.clone();
   c.setCommentBefore(null);
   c.setCommentAfter(null);
   if (c instanceof Declaration) {
     Declaration d = (Declaration) c;
     d.setAnnotations(null);
   }
   return c;
 }
Пример #15
0
 @Override
 public boolean satisfies(TypeDeclaration type) {
   // do not look in ourselves
   if (type == TypeDeclaration.this) return false;
   Declaration d = type.getDirectMember(name, null, false);
   if (d != null && d.isShared() && isResolvable(d)) {
     // only accept abstractions
     return isAbstraction(d);
   } else {
     return false;
   }
 }
Пример #16
0
 @Override
 public boolean satisfies(TypeDeclaration type) {
   // do not look in ourselves
   if (type == TypeDeclaration.this) return false;
   Declaration d = type.getDirectMember(name, signature, variadic);
   if (d != null && d.isShared() && isResolvable(d)) {
     // only accept abstractions if we don't have a signature
     return !isAbstraction(d) || signature == null;
   } else {
     return false;
   }
 }
Пример #17
0
 @Override
 public void visit(Param visitor) {
   SymTab symtab = new SymTab();
   Declaration dec = new Declaration();
   dec.id = visitor.getIdent();
   dec.type = visitor.getTipo();
   dec.fila = visitor.fila;
   st.set(dec);
   for (int i = 0; i < st.scopes.size(); i++) {
     symtab.scopes.add(i, st.scopes.get(i));
   }
   visitor.alcance = symtab.scopes;
 }
Пример #18
0
 /** Only used for inline- and tail-calls. */
 private static void pushArgs(
     LambdaExp lexp, Expression[] args, int[] incValues, Compilation comp) {
   Declaration param = lexp.firstDecl();
   int args_length = args.length;
   for (int i = 0; i < args_length; ++i) {
     Expression arg = args[i];
     if (param.ignorable()) arg.compile(comp, Target.Ignore);
     else if (incValues != null
         && (incValues[i] = SetExp.canUseInc(arg, param)) != SetExp.BAD_SHORT) ;
     else arg.compileWithPosition(comp, StackTarget.getInstance(param.getType()));
     param = param.nextDecl();
   }
 }
  public void visitExecutableDeclaration(ExecutableDeclaration d) {
    d.accept(pre);

    SortedSet<Declaration> decls = new TreeSet<Declaration>(SourceOrderDeclScanner.comparator);

    for (TypeParameterDeclaration tpDecl : d.getFormalTypeParameters()) decls.add(tpDecl);

    for (ParameterDeclaration pDecl : d.getParameters()) decls.add(pDecl);

    for (Declaration decl : decls) decl.accept(this);

    d.accept(post);
  }
Пример #20
0
  @RequestMapping(value = "Declaration", method = RequestMethod.POST)
  public ModelAndView declaration(Declaration declaration) {
    ModelAndView mv = new ModelAndView("jsp/printPage");
    declaration = this.declarationService.create(declaration);
    for (int i = 0; i < this.instructorList.size(); i++)
      instructorList.get(i).setId(declaration.getId());
    this.instructorService.create(this.instructorList);
    for (int i = 0; i < this.scheduleList.size(); i++)
      scheduleList.get(i).setId(declaration.getId());
    this.scheduleService.create(this.scheduleList);
    for (int i = 0; i < this.budgetList.size(); i++) budgetList.get(i).setId(declaration.getId());
    this.budgetService.create(this.budgetList);
    for (int i = 0; i < this.hoursList.size(); i++) hoursList.get(i).setId(declaration.getId());
    this.hoursService.create(this.hoursList);

    mv.addObject("Declaration", declaration);
    List<Instructor> getI = this.instructorService.selectById(declaration.getId());
    List<Teacher> getT = this.teacherService.selectByInstructorList(getI);
    mv.addObject("Instructor", getT);
    mv.addObject("InstructorLength", getT.size() + 1);
    List<Schedule> getS = this.scheduleService.selectById(declaration.getId());
    mv.addObject("Schedule", getS);
    List<Budget> getB = this.budgetService.selectById(declaration.getId());
    mv.addObject("Budget", getB);
    mv.addObject("BudgetLength", getB.size() + 1);
    List<Hours> getH = this.hoursService.selectById(declaration.getId());
    mv.addObject("Hours", getH);
    mv.addObject("HoursLength", getH.size() + 1);

    return mv;
  }
Пример #21
0
 // TODO Revisar las variables solo dentro del alcance
 @Override
 public void visit(ExprVar visitor) {
   Declaration decl = new Declaration();
   decl.id = visitor.getIdent();
   decl.fila = visitor.fila;
   int scope = st.searchDeclaration(decl.id);
   if (scope == SymTab.INVALID_SCOPE) {
     System.out.println(
         "Error Semantico en fila "
             + decl.fila
             + ", la variable "
             + decl.id
             + " no ha sido declarada");
   }
 }
Пример #22
0
 @Override
 public Map<String, DeclarationWithProximity> getMatchingDeclarations(
     Unit unit, String startingWith, int proximity) {
   Map<String, DeclarationWithProximity> result =
       super.getMatchingDeclarations(unit, startingWith, proximity);
   // Inherited declarations hide outer and imported declarations
   result.putAll(getMatchingMemberDeclarations(null, startingWith, proximity));
   // Local declarations always hide inherited declarations, even if non-shared
   for (Declaration d : getMembers()) {
     if (isResolvable(d) && !isOverloadedVersion(d) && isNameMatching(startingWith, d)) {
       result.put(d.getName(), new DeclarationWithProximity(d, proximity));
     }
   }
   return result;
 }
  public void testGetFieldValue() throws IntrospectionException {
    final FieldExtractor extractor =
        cache.getExtractor(Cheese.class, "type", getClass().getClassLoader());

    final Pattern pattern = new Pattern(5, new ClassObjectType(Cheese.class));

    // Bind the extractor to a decleration
    // Declarations know the pattern they derive their value from
    final Declaration declaration = new Declaration("typeOfCheese", extractor, pattern);

    // Create some facts
    final Cheese cheddar = new Cheese("cheddar", 5);

    // Check we can extract Declarations correctly
    assertEquals("cheddar", declaration.getValue(null, cheddar));
  }
Пример #24
0
 /**
  * Constructs flow graphs for {@code ast}. It also prints warnings if there are syntactically
  * unreachable blocks.
  *
  * @param ast the AST for which to build flow graphs
  * @return whether there were missing blocks
  */
 public boolean process(Declaration ast) {
   currentBlock = null;
   errors = false;
   flowGraphs = new HashMap<Implementation, SimpleGraph<Block>>();
   ast.eval(this);
   return errors;
 }
Пример #25
0
 public HashMap<String, SecLevel> getSecurityLevel() {
   HashMap<String, SecLevel> secLevel = new HashMap<String, SecLevel>();
   if (declaration != null) {
     return declaration.getSecurityLevel();
   }
   return secLevel;
 }
Пример #26
0
 public String toString() {
   if (declaration != null) {
     return declaration.toString() + "\n" + statement.toString();
   } else {
     return statement.toString();
   }
 }
Пример #27
0
  @Override
  public void see(Implementation implementation, Signature sig, Body body, Declaration tail) {
    // initialize graph
    currentFlowGraph = new SimpleGraph<Block>();
    flowGraphs.put(implementation, currentFlowGraph);

    // get blocks by name
    blocksByName = new HashMap<String, Block>();
    Block b = body.getBlocks();
    while (b != null) {
      blocksByName.put(b.getName(), b);
      currentFlowGraph.node(b);
      b = b.getTail();
    }

    // build graph
    body.eval(this);

    // check for reachability
    seenBlocks = new HashSet<Block>();
    b = body.getBlocks();
    if (b == null) return;
    dfs(b);
    while (b != null) {
      if (!seenBlocks.contains(b))
        Err.warning("" + b.loc() + ": Block " + b.getName() + " is unreachable.");
      b = b.getTail();
    }

    if (tail != null) tail.eval(this);
  }
 /** @apilevel low-level */
 public void flushCache() {
   super.flushCache();
   getModule_visited = false;
   lookupFunction_String_visited = null;
   lookupVar_String_visited = null;
   lookupVar_String_values = null;
 }
Пример #29
0
 public void setPackage(String s) {
   s = parser.pack_replace(s);
   super.setPackage(s);
   const_type.setPackage(s);
   const_expr.setPackage(s);
   t.typeName = name;
   t.setPackage(s);
 }
Пример #30
0
 private List<Declaration> getMembers(String name, List<TypeDeclaration> visited) {
   if (visited.contains(this)) {
     return Collections.emptyList();
   } else {
     visited.add(this);
     List<Declaration> members = new ArrayList<Declaration>();
     for (Declaration d : getMembers()) {
       if (d.getName() != null && d.getName().equals(name)) {
         members.add(d);
       }
     }
     if (members.isEmpty()) {
       members.addAll(getInheritedMembers(name));
     }
     return members;
   }
 }