Package sizzle.types

Examples of sizzle.types.SizzleFunction


    final String source = "out: table sum[key: string][month: int][day: int] of int;\nstatic keywords: array of string = { \"hitchhiker\", \"benedict\", \"vytorin\", \"itanium\", \"aardvark\" };\nquerywords: array of string = words_from_query();\nmonth: int = month_of_query();\nday: int = day_of_query();\nwhen (i: each int; j: some int; querywords[i] == keywords[j])\n    emit out <- 1;\n";

    final SymbolTable st = new SymbolTable();

    // fake functions for this unit test
    st.setFunction("day_of_query", new SizzleFunction(new SizzleInt(), new SizzleType[] {}, "Nonexistant.day_of_query()"));
    st.setFunction("month_of_query", new SizzleFunction(new SizzleInt(), new SizzleType[] {}, "Nonexistant.month_of_query()"));
    st.setFunction("words_from_query", new SizzleFunction(new SizzleArray(new SizzleString()), new SizzleType[] {}, "Nonexistant.words_from_query()"));

    SizzleParser.ReInit(new StringReader(source));
    TestTypeCheckingVisitor.typeChecker.visit(SizzleParser.Start(), st);
  }
View Full Code Here


            throw new TypeException("invalid operand type " + ioperand + " for indexing expression");
          }
        case 2: // call
          final List<SizzleType> formalParameters = this.check((Call) nodeChoice.choice, argu);

          final SizzleFunction f = new FunctionFindingVisitor(formalParameters).visit(n.f0, argu);

          // if (f.countParameters() != formalParameters.size())
          // for (int i = 0; i < formalParameters.size(); i++)
          // if (!f.getParameter(i).assigns(formalParameters.get(i)))
          // throw new TypeException("invalid args " +
View Full Code Here

        }

        String src = ((NodeSequence) nodeChoice.choice).elementAt(1).accept(this, argu);

        if (!type.assigns(t)) {
          final SizzleFunction f = argu.getCast(t, type);

          if (f.hasName()) {
            src = f.getName() + "(" + src + ")";
          } else if (f.hasMacro()) {
            src = CodeGeneratingVisitor.expand("X" + f.getMacro(), src.split(","));
          }
        }

        st.setAttribute("initializer", src);
        break;
View Full Code Here

  @Override
  public String visit(final Call n, final SymbolTable argu) {
    final StringTemplate st = this.stg.getInstanceOf("Call");

    final SizzleFunction f = argu.getFunction(this.namefinder.visit(argu.getOperand()).toArray()[0].toString(), this.typechecker.check(n, argu));

    if (f.hasMacro()) {
      st.setAttribute("call", CodeGeneratingVisitor.expand(f.getMacro(), ((ExprList) n.f1.node).accept(this, argu).split(",")));
    } else if (f.hasName()) {
      st.setAttribute("operand", f.getName());

      if (n.f1.present())
        st.setAttribute("parameters", n.f1.node.accept(this, argu));
    }
View Full Code Here

    for (int i = 0; i < formalParameters.length; i++)
      ids[i + 1] = formalParameters[i];

    ids[ids.length - 1] = "";

    final SizzleFunction function = this.getFunction(ids);

    if (function == null)
      throw new TypeException("no such function " + name + "(" + Arrays.toString(formalParameters) + ")");

    return function;
View Full Code Here

  private SizzleFunction getFunction(final Object[] ids) {
    if (this.trie.containsKey(ids[0])) {
      if (ids[0].equals("")) {
        return (SizzleFunction) this.trie.get("");
      } else {
        final SizzleFunction function = ((FunctionTrie) this.trie.get(ids[0])).getFunction(Arrays.copyOfRange(ids, 1, ids.length));

        if (function != null)
          return function;
      }
    } else {
      for (final Object o : this.trie.keySet())
        if (o instanceof SizzleVarargs && ((SizzleVarargs) o).accepts((SizzleType) ids[0])) {
          return ((FunctionTrie) this.trie.get(o)).getFunction();
        } else if (o instanceof SizzleType && ((SizzleType) o).accepts((SizzleType) ids[0])) {
          final SizzleFunction function = ((FunctionTrie) this.trie.get(o)).getFunction(Arrays.copyOfRange(ids, 1, ids.length));

          if (function != null)
            return function;
        }
    }
View Full Code Here

TOP

Related Classes of sizzle.types.SizzleFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.