protected void keywordParam() throws ParseException {
    if (!fInput.hasNext()) return;

    if (fInput.next().getTyp() == TSExpression.SYMBOL) {
      Symbol symbol = (Symbol) fInput.current();
      if (symbol.getSymbolName().equalsIgnoreCase(TOKEN_KEY)) {

        while (true) {
          if (!fInput.hasNext()) {
            break;
          }

          SExpression next = fInput.next();
          if (isSpecialSymbol(next)) {
            fInput.pushBack();
            break;
          }

          addKey(varInit(next));
        }

        allowOtherKeys();
      } else {
        fInput.pushBack();
      }
    } else {
      error("Unknown symbol in key list: &key expected", fInput.getInputSExpression());
    }
  }
  public static void reconstructHeaders(Iterable<NativeLibrary> libraries, PrintWriter out) {
    List<MemberRef> orphanMembers = new ArrayList<MemberRef>();
    Map<TypeRef, List<MemberRef>> membersByClass = new HashMap<TypeRef, List<MemberRef>>();
    for (NativeLibrary library : libraries) {
      for (Symbol symbol : library.getSymbols()) {
        MemberRef mr = symbol.getParsedRef();
        if (mr == null) continue;

        TypeRef et = mr.getEnclosingType();
        if (et == null) orphanMembers.add(mr);
        else {
          List<MemberRef> mrs = membersByClass.get(et);
          if (mrs == null) membersByClass.put(et, mrs = new ArrayList<MemberRef>());
          mrs.add(mr);
        }
      }
    }
    for (TypeRef tr : membersByClass.keySet()) out.println("class " + tr + ";");

    for (MemberRef mr : orphanMembers) out.println(mr + ";");

    for (Map.Entry<TypeRef, List<MemberRef>> e : membersByClass.entrySet()) {
      TypeRef tr = e.getKey();
      List<MemberRef> mrs = e.getValue();
      out.println("class " + tr + " \n{");
      for (MemberRef mr : mrs) {
        out.println("\t" + mr + ";");
      }
      out.println("}");
    }
  }
예제 #3
0
 @Nullable
 private Function rewriteAndValidateFields(Function function, Context context) {
   if (function.arguments().size() == 2) {
     Symbol left = function.arguments().get(0);
     Symbol right = function.arguments().get(1);
     if (left.symbolType() == SymbolType.REFERENCE && right.symbolType().isValueSymbol()) {
       Reference ref = (Reference) left;
       if (ref.info().ident().columnIdent().equals(DocSysColumns.ID)) {
         function.setArgument(
             0,
             new Reference(DocSysColumns.forTable(ref.ident().tableIdent(), DocSysColumns.UID)));
         function.setArgument(
             1,
             Literal.newLiteral(
                 Uid.createUid(
                     Constants.DEFAULT_MAPPING_TYPE, ValueSymbolVisitor.STRING.process(right))));
       } else {
         String unsupportedMessage =
             context.unsupportedMessage(ref.info().ident().columnIdent().name());
         if (unsupportedMessage != null) {
           throw new UnsupportedFeatureException(unsupportedMessage);
         }
       }
     }
   }
   return function;
 }
  protected void optionalParam() throws ParseException {
    if (!fInput.hasNext()) return; // leere Lambda Liste

    if (fInput.next().getTyp() == TSExpression.SYMBOL) {
      Symbol symbol = (Symbol) fInput.current();
      if (symbol.getSymbolName().equalsIgnoreCase(TOKEN_OPTIONAL)) {

        // if(!fInput.hasNext()) { //&optional gesehen, aber kein weiteres symbol angegeben
        //	error("At least one &optional parameter must be specified",
        // fInput.getInputSExpression());
        // }
        // addOptional(varInit(fInput.next())); //mindesten ein Symbol ist angegeben

        while (true) {
          if (!fInput.hasNext()) {
            break;
          }

          SExpression next = fInput.next();
          if (isSpecialSymbol(next)) {
            fInput.pushBack();
            break;
          }

          addOptional(varInit(next));
        }

      } else {
        fInput.pushBack();
        return;
      }
    } else {
      error("Unknown symbol in optional parameter list: &optional expected", fInput.current());
    }
  }
예제 #5
0
      @Override
      public Query apply(Function input, Context context) throws IOException {
        List<Symbol> arguments = input.arguments();
        assert arguments.size() == 4 : "invalid number of arguments";
        assert Symbol.isLiteral(arguments.get(0), DataTypes.OBJECT);
        assert Symbol.isLiteral(arguments.get(1), DataTypes.STRING);
        assert Symbol.isLiteral(arguments.get(2), DataTypes.STRING);
        assert Symbol.isLiteral(arguments.get(3), DataTypes.OBJECT);

        @SuppressWarnings("unchecked")
        Map<String, Object> fields = (Map) ((Literal) arguments.get(0)).value();
        BytesRef queryString = (BytesRef) ((Literal) arguments.get(1)).value();
        BytesRef matchType = (BytesRef) ((Literal) arguments.get(2)).value();
        Map options = (Map) ((Literal) arguments.get(3)).value();

        checkArgument(queryString != null, "cannot use NULL as query term in match predicate");

        MatchQueryBuilder queryBuilder;
        if (fields.size() == 1) {
          queryBuilder =
              new MatchQueryBuilder(context.mapperService, context.indexCache, matchType, options);
        } else {
          queryBuilder =
              new MultiMatchQueryBuilder(
                  context.mapperService, context.indexCache, matchType, options);
        }
        return queryBuilder.query(fields, queryString);
      }
예제 #6
0
  @Override
  public void visitTopLevel(JCCompilationUnit tree) {
    JavaFileObject prev = log.useSource(tree.sourcefile);
    boolean addEnv = false;
    boolean isPkgInfo =
        tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE);
    if (tree.pid != null) {
      tree.packge = reader.enterPackage(TreeInfo.fullName(tree.pid));
      if (tree.packageAnnotations.nonEmpty() || pkginfoOpt == PkgInfo.ALWAYS) {
        if (isPkgInfo) {
          addEnv = true;
        } else {
          log.error(tree.packageAnnotations.head.pos(), "pkg.annotations.sb.in.package-info.java");
        }
      }
    } else {
      tree.packge = syms.unnamedPackage;
    }
    tree.packge.complete(); // Find all classes in package.
    Env<AttrContext> topEnv = topLevelEnv(tree);

    // Save environment of package-info.java file.
    if (isPkgInfo) {
      Env<AttrContext> env0 = typeEnvs.get(tree.packge);
      if (env0 == null) {
        typeEnvs.put(tree.packge, topEnv);
      } else {
        JCCompilationUnit tree0 = env0.toplevel;
        if (!fileManager.isSameFile(tree.sourcefile, tree0.sourcefile)) {
          log.warning(
              tree.pid != null ? tree.pid.pos() : null, "pkg-info.already.seen", tree.packge);
          if (addEnv
              || (tree0.packageAnnotations.isEmpty()
                  && tree.docComments != null
                  && tree.docComments.get(tree) != null)) {
            typeEnvs.put(tree.packge, topEnv);
          }
        }
      }

      for (Symbol q = tree.packge; q != null && q.kind == PCK; q = q.owner) q.flags_field |= EXISTS;

      Name name = names.package_info;
      ClassSymbol c = reader.enterClass(name, tree.packge);
      c.flatname = names.fromString(tree.packge + "." + name);
      c.sourcefile = tree.sourcefile;
      c.completer = null;
      c.members_field = new Scope(c);
      tree.packge.package_info = c;
    }
    classEnter(tree.defs, topEnv);
    if (addEnv) {
      todo.append(topEnv);
    }
    log.useSource(prev);
    result = null;
  }
예제 #7
0
  // Verify if the number of items of list right member (on fedinition) is equal to left member
  public Boolean verifyNumberVarList(int num_var) {
    Iterator<Symbol> it1 = this.getMembers().iterator();
    Symbol sym1;
    int i;
    for (i = 1; i < num_var; i++) {
      sym1 = it1.next();
      if (sym1.getIsVariableSymbol() == false) break;
    }

    if (i == num_var) return true;
    else return false;
  }
예제 #8
0
 boolean computeSubtypeOf(Klass k) {
   // An array is a subtype of Serializable, Clonable, and Object
   Symbol name = k.getName();
   if (name != null
       && (name.equals(javaIoSerializableName())
           || name.equals(javaLangCloneableName())
           || name.equals(javaLangObjectName()))) {
     return true;
   } else {
     return false;
   }
 }
예제 #9
0
 /*
  * Return a specific symbol
  */
 public Symbol getSymbolOfListSymbols(String symName) {
   Symbol sym_final = null;
   Iterator<Symbol> it = this.getMembers().iterator();
   Symbol sym;
   for (; it.hasNext(); ) {
     sym = it.next();
     if (sym.getName().equals(symName) == true) {
       sym_final = sym;
       break;
     }
   }
   return sym_final;
 }
예제 #10
0
 /*
  * Tells if the symbols list contains a gived symbol
  */
 public Boolean containsSymbol(String symName) {
   Iterator<Symbol> it = this.getMembers().iterator();
   Symbol sym;
   Boolean haveSymbol = false;
   for (; it.hasNext(); ) {
     sym = it.next();
     if (sym.getName().equals(symName) == true) {
       haveSymbol = true;
       break;
     }
   }
   return haveSymbol;
 }
예제 #11
0
      @Nullable
      protected Tuple<Reference, Literal> prepare(Function input) {
        assert input != null;
        assert input.arguments().size() == 2;

        Symbol left = input.arguments().get(0);
        Symbol right = input.arguments().get(1);

        if (!(left instanceof Reference) || !(right.symbolType().isValueSymbol())) {
          return null;
        }
        assert right.symbolType() == SymbolType.LITERAL;
        return new Tuple<>((Reference) left, (Literal) right);
      }
  protected boolean isSpecialSymbol(final SExpression sexp) {
    if (sexp.getTyp() != TSExpression.SYMBOL) return false;

    Symbol symbol = (Symbol) sexp;
    String symName = symbol.getSymbolName();
    return symName.equalsIgnoreCase(TOKEN_OPTIONAL)
        || symName.equalsIgnoreCase(TOKEN_BODY)
        || symName.equalsIgnoreCase(TOKEN_KEY)
        || symName.equalsIgnoreCase(TOKEN_REST)
        || symName.equals(TOKEN_AUX)
        || symName.equals(TOKEN_ALLOW_OTHER_KEYS)
        || symName.equals(TOKEN_WHOLE)
        || symName.equals(TOKEN_ENVIRONMENT);
  }
예제 #13
0
 public static ArrayList<Symbol> toSymbols(String expression) {
   ArrayList<Symbol> symbols = new ArrayList<>();
   for (int i = 0; i < expression.length(); i++) {
     char c = expression.charAt(i);
     if (isBracket(c)) {
       // bracket
       symbols.add(new Symbol(c));
     } else if (c == ',') {
       symbols.add(new Symbol(c));
     } else if (isOperator(c)) {
       if (c == '-') {
         if (i == 0) {
           // must be first +/-, so add 0
           symbols.add(new Symbol(BigDecimal.valueOf(0)));
           symbols.add(new Symbol(c));
         } else {
           char previous = expression.charAt(i - 1);
           if ((previous == ')') || isNumber(String.valueOf(previous))) {
             // must be "minus"
             // e.g. sin(3)-5, 100-5,
             symbols.add(new Symbol(c));
           } else if ((previous == '(') || (previous == ',')) {
             // must be "negative"
             // e.g. (-3+5)/2
             symbols.add(new Symbol(BigDecimal.valueOf(0)));
             symbols.add(new Symbol(c));
           } else if ((previous == '*') || (previous == '/') || (previous == '^')) {
             int end = Symbol.getNumberEndAt(i + 1, expression);
             symbols.add(new Symbol(new BigDecimal(expression.substring(i, end))));
             i = end - 1;
           }
         }
       } else {
         symbols.add(new Symbol(c));
       }
     } else if (Character.isLetter(c)) {
       // function
       int end = Symbol.getFunctionEndAt(i, expression);
       symbols.add(new Symbol(expression.substring(i, end)));
       i = end - 1;
     } else if (Character.isDigit(c)) {
       int end = Symbol.getNumberEndAt(i, expression);
       String number = expression.substring(i, end);
       symbols.add(new Symbol(new BigDecimal(number)));
       i = end - 1;
     }
   }
   return symbols;
 }
예제 #14
0
  // ########################
  // set the scope root symbol taint
  public void printtt(String sp, Scope cp) {
    System.out.println(sp + "Scope: " + cp.getScopeName());

    Iterator<Symbol> it = cp.getMembers().iterator();
    Symbol sy;
    for (; it.hasNext(); ) {
      sy = it.next();
      if (sy.getRootScope() == null) {
        System.out.println(sp + "\tmember: " + sy.getName());
      } else {
        cp = (Scope) sy;
        sp = sp + "\t";
        cp.printtt(sp, cp);
      }
    }
  }
예제 #15
0
  /** Field access by name. */
  public Field findLocalField(Symbol name, Symbol sig) {
    TypeArray fields = getFields();
    int n = (int) fields.getLength();
    ConstantPool cp = getConstants();
    for (int i = 0; i < n; i += NEXT_OFFSET) {
      int nameIndex = fields.getShortAt(i + NAME_INDEX_OFFSET);
      int sigIndex = fields.getShortAt(i + SIGNATURE_INDEX_OFFSET);
      Symbol f_name = cp.getSymbolAt(nameIndex);
      Symbol f_sig = cp.getSymbolAt(sigIndex);
      if (name.equals(f_name) && sig.equals(f_sig)) {
        return newField(i);
      }
    }

    return null;
  }
예제 #16
0
 public String getInstanceNameFromAliases(String s, InstanceTable instTab) {
   String instName = "";
   boolean found = false;
   while (found == false) {
     if (instTab.containsInstance(s) == true) {
       instName = s;
       found = true;
     } else {
       if (this.getAliases().containsKey(s)) {
         Symbol sym = (Symbol) this.getAliases().get(s);
         s = sym.getName();
       }
     }
   }
   return instName;
 }
  protected void bodyOrRest() throws ParseException {
    if (!fInput.hasNext()) return;

    if (fInput.next().getTyp() == TSExpression.SYMBOL) {
      Symbol symbol = (Symbol) fInput.current();
      if (symbol.getSymbolName().equalsIgnoreCase(TOKEN_BODY)) {
        fBody = readRestOrBodySymbol("body");
      } else if (symbol.getSymbolName().equalsIgnoreCase(TOKEN_REST)) {
        fRest = readRestOrBodySymbol("rest");
      } else {
        fInput.pushBack(); // evtl. &key
        return;
      }
    } else {
      error("Unknown symbol in rest or body list: &body or &rest expected", fInput.current());
    }
  }
예제 #18
0
  private Boolean verifyCallItself(Scope scp, String scp_name_resolve) {
    Symbol sym;
    int i;
    Boolean equalItself = false;
    for (Iterator<Symbol> it = scp.getMembers().iterator(); it.hasNext(); ) {
      sym = it.next();
      if (sym.getRootScope() != null) {
        Scope scp_aux = (Scope) sym;
        equalItself = verifyCallItself(scp_aux, scp_name_resolve);
        if (equalItself == true) return true;
      } else {
        if (sym.getName().equals(scp_name_resolve) == true) return true;
      }
    }

    return equalItself;
  }
예제 #19
0
 /*
  * Print the elements of the main Map scope.
  */
 public void print(Scope scp) {
   Symbol aux1;
   Scope s;
   if (!scp.getMembers().isEmpty()) {
     System.out.println("\nScope: " + scp.getScopeName() + "\tsize=" + scp.getMembers().size());
     Iterator<Symbol> it = scp.getMembers().iterator();
     for (; it.hasNext(); ) {
       aux1 = it.next();
       if (aux1.getRootScope() != null) { // is a root of a new scope?
         s = aux1.getRootScope();
         s.print(s);
       }
     }
   } else {
     aux1 = scp.getScopeSymbol();
     System.out.println(
         "Name: "
             + aux1.getName()
             + "\t\tline: "
             + aux1.getCodeLine()
             + "\t\ttainted: "
             + aux1.getTainted()
             + "\t\tScope: "
             + aux1.getScope().getScopeName()
             + "\n");
   }
 }
예제 #20
0
      @Override
      public Query apply(Function input, Context context) {
        assert input != null;
        assert input.arguments().size() == 1;
        Symbol arg = input.arguments().get(0);
        if (arg.symbolType() != SymbolType.REFERENCE) {
          return null;
        }
        Reference reference = (Reference) arg;

        String columnName = reference.info().ident().columnIdent().fqn();
        QueryBuilderHelper builderHelper = QueryBuilderHelper.forType(reference.valueType());
        BooleanFilter boolFilter = new BooleanFilter();
        boolFilter.add(
            builderHelper.rangeFilter(columnName, null, null, true, true),
            BooleanClause.Occur.MUST_NOT);
        return new FilteredQuery(Queries.newMatchAllQuery(), boolFilter);
      }
예제 #21
0
  public Rule newRule(NonTerminal head, Symbol... symbols) {
    try {
      if (head.getGrammar() != this) {
        throw new IllegalArgumentException();
      }
      for (Symbol s : symbols) {
        if (s.getGrammar() != this) {
          throw new IllegalArgumentException();
        }
      }

      Rule result = new Rule(this, head, symbols);
      myRules.add(result);
      head.addRule(result);
      return result;
    } finally {
      invalidateGrammarData();
    }
  }
예제 #22
0
 private Query queryFromInnerFunction(Function function, Context context) {
   for (Symbol symbol : function.arguments()) {
     if (symbol.symbolType() == SymbolType.FUNCTION) {
       String functionName = ((Function) symbol).info().ident().name();
       InnerFunctionToQuery functionToQuery = innerFunctions.get(functionName);
       if (functionToQuery != null) {
         try {
           Query query = functionToQuery.apply(function, (Function) symbol, context);
           if (query != null) {
             return query;
           }
         } catch (IOException e) {
           throw ExceptionsHelper.convertToRuntime(e);
         }
       }
     }
   }
   return null;
 }
예제 #23
0
    private boolean fieldIgnored(Function function, Context context) {
      if (function.arguments().size() != 2) {
        return false;
      }

      Symbol left = function.arguments().get(0);
      Symbol right = function.arguments().get(1);
      if (left.symbolType() == SymbolType.REFERENCE && right.symbolType().isValueSymbol()) {
        String columnName = ((Reference) left).info().ident().columnIdent().name();
        if (Context.FILTERED_FIELDS.contains(columnName)) {
          context.filteredFieldValues.put(columnName, ((Input) right).value());
          return true;
        }
        String unsupportedMessage = Context.UNSUPPORTED_FIELDS.get(columnName);
        if (unsupportedMessage != null) {
          throw new UnsupportedFeatureException(unsupportedMessage);
        }
      }
      return false;
    }
예제 #24
0
  // refer to compute_modifier_flags in VM code.
  public long computeModifierFlags() {
    long access = getAccessFlags();
    // But check if it happens to be member class.
    TypeArray innerClassList = getInnerClasses();
    int length = (innerClassList == null) ? 0 : (int) innerClassList.getLength();
    if (length > 0) {
      if (Assert.ASSERTS_ENABLED) {
        Assert.that(length % InnerClassAttributeOffset.innerClassNextOffset == 0, "just checking");
      }
      for (int i = 0; i < length; i += InnerClassAttributeOffset.innerClassNextOffset) {
        int ioff =
            innerClassList.getShortAt(i + InnerClassAttributeOffset.innerClassInnerClassInfoOffset);
        // 'ioff' can be zero.
        // refer to JVM spec. section 4.7.5.
        if (ioff != 0) {
          // only look at classes that are already loaded
          // since we are looking for the flags for our self.
          Oop classInfo = getConstants().getObjAt(ioff);
          Symbol name = null;
          if (classInfo instanceof Klass) {
            name = ((Klass) classInfo).getName();
          } else if (classInfo instanceof Symbol) {
            name = (Symbol) classInfo;
          } else {
            throw new RuntimeException("should not reach here");
          }

          if (name.equals(getName())) {
            // This is really a member class
            access =
                innerClassList.getShortAt(
                    i + InnerClassAttributeOffset.innerClassAccessFlagsOffset);
            break;
          }
        }
      } // for inner classes
    }

    // Remember to strip ACC_SUPER bit
    return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
  }
예제 #25
0
    RefLiteralPair(Function function) {
      assert function.arguments().size() == 2 : "function requires 2 arguments";
      Symbol left = function.arguments().get(0);
      Symbol right = function.arguments().get(1);

      if (left instanceof Reference) {
        reference = (Reference) left;
      } else if (right instanceof Reference) {
        reference = (Reference) right;
      } else {
        reference = null;
      }

      if (left.symbolType().isValueSymbol()) {
        input = (Input) left;
      } else if (right.symbolType().isValueSymbol()) {
        input = (Input) right;
      } else {
        input = null;
      }
    }
예제 #26
0
    FunctionLiteralPair(Function outerFunction) {
      assert outerFunction.arguments().size() == 2 : "function requires 2 arguments";
      Symbol left = outerFunction.arguments().get(0);
      Symbol right = outerFunction.arguments().get(1);

      functionName = outerFunction.info().ident().name();

      if (left instanceof Function) {
        function = (Function) left;
      } else if (right instanceof Function) {
        function = (Function) right;
      } else {
        function = null;
      }

      if (left.symbolType().isValueSymbol()) {
        input = (Input) left;
      } else if (right.symbolType().isValueSymbol()) {
        input = (Input) right;
      } else {
        input = null;
      }
    }
예제 #27
0
 public void populateList(
     Scope scp_main,
     Scope scp_right,
     int num_var,
     TaintedTable mts,
     UntaintedTable mus,
     String filename) {
   Iterator<Symbol> it = this.getMembers().iterator();
   Iterator<Symbol> it1 = scp_right.getMembers().iterator();
   Symbol sym, sym1;
   for (int i = 1; i < num_var; i++) {
     sym1 = it1.next();
     sym = it.next();
     CallSymbol ms_aux =
         new CallSymbol(sym.getName(), sym.getCodeLine(), scp_main, 0, sym.getFileSymbol());
     VariableSymbol vs =
         new VariableSymbol(
             sym1.getName(), sym1.getTainted(), sym1.getCodeLine(), sym1.getFileSymbol()) {};
     ms_aux.define(vs, null, true);
     ms_aux.resolveSymbol(ms_aux, (Symbol) vs, mts, mus, filename);
     scp_main.define(ms_aux, ms_aux, false);
   }
 }
예제 #28
0
 @Override
 public Query apply(Function function, Context context) throws IOException {
   Symbol left = function.arguments().get(0);
   Symbol collectionSymbol = function.arguments().get(1);
   Preconditions.checkArgument(
       DataTypes.isCollectionType(collectionSymbol.valueType()),
       "invalid argument for ANY expression");
   if (left.symbolType().isValueSymbol()) {
     // 1 = any (array_col) - simple eq
     assert collectionSymbol.symbolType().isReference()
         : "no reference found in ANY expression";
     return applyArrayReference((Reference) collectionSymbol, (Literal) left, context);
   } else if (collectionSymbol.symbolType().isValueSymbol()) {
     assert left.symbolType().isReference() : "no reference found in ANY expression";
     return applyArrayLiteral((Reference) left, (Literal) collectionSymbol, context);
   } else {
     // should never get here - 2 literal arguments must have been normalized away yet
     return null;
   }
 }
예제 #29
0
 @Override
 public void dispose() {
   super.dispose();
   for (final IVariable v : variables.values()) {
     v.dispose();
   }
   variables.clear();
   for (final AspectStatement ac : aspects.values()) {
     ac.dispose();
   }
   aspects.clear();
   for (final ActionStatement ac : actions.values()) {
     ac.dispose();
   }
   actions.clear();
   for (final IStatement c : behaviors) {
     c.dispose();
   }
   behaviors.clear();
   macroSpecies = null;
   parentSpecies = null;
   // TODO dispose micro_species first???
   microSpecies.clear();
 }
예제 #30
0
 /*
  * Insert a root symbol (new scope) in main Map.
  */
 public void define(Symbol sym, Scope scp, Boolean IsVariableSymbol) {
   symbols.add(sym);
   sym.setRootScope(scp);
   sym.setScope(this);
   sym.setIsVariableSymbol(IsVariableSymbol);
 }