Package anvil.script.statements

Examples of anvil.script.statements.FunctionStatement



  protected Node onFunction(ErrorListener listener, Type type)
  {
    if (type instanceof FunctionStatement) {
      FunctionStatement function = (FunctionStatement)type;
      if (function.getContext() != null) {
        if (hasArgs()) {
          return new InlinedCallNode(_statement.getFunctionStatement(), function, consumeArgs());
        } else {
          return new InlinedFunctionNode(_statement.getFunctionStatement(), function);
        }
View Full Code Here


    } else {
      switch(_role) {
      case DECLARE:
        {
          consumeSymbol();
          FunctionStatement function = _statement.getFunctionStatement();
          type = function.lookupDeclaration(symbol);
          if (type == null) {
            type = function.declare(symbol);
          }
        }
        break;
       
      case ASSIGN:
        {
          consumeSymbol();
          type = _statement.lookupAnyDeclaration(symbol);
          if (type == null) {
            consumeSymbol();
            FunctionStatement function = _statement.getFunctionStatement();
            if (function != null) {
              type = function.declare(symbol);
            } else {
              listener.error(_location, "Entity '" + _name + "' is undeclared");
              return null;
            }
          }
        }
        break;
       
      default:
        {
          type = _statement.lookupAnyDeclaration(symbol);
          if (type == null) {
            type = LangModule.__module__.lookupDeclaration(symbol);
            if (type == null) {
              consumeSymbol();
              type = lookupLibrary(listener);
              if (type == null) {
                listener.error(_location, "Entity '" + _name + "' is undeclared");
                return null;
              }
              symbol = type.getName();

            } else {
              type = LangModule.__module__;
              symbol = type.getName();

            }
          } else {
            consumeSymbol();
          }
        }
        break;
      }
     
    }

    type = followImports(listener, type);
    if (type == null) {
      return null;
    }
   
    if (type instanceof ReflectedJava) {
      if (type instanceof Reflection) {
        return new JavaClassNode(type.getName());
      } else {
        return new JavaClassNode(type.getParent().getName());
      }
    }

    switch(type.getType()) {
    case Type.MODULE:
    case Type.NAMESPACE: 
      {
        if (!hasMoreSymbols()) {
          return new TypeNode(type);
        }
        return construct(listener, (Scope)type);
      }
     
    case Type.INTERFACE:
    case Type.CLASS: 
      {
        return classConstruct(listener, (Scope)type);
      }
     
    case Type.GLOBAL_NAMESPACE:
      {
        return GlobalNamespaceNode.INSTANCE;
      }

    case Type.SYSTEM_NAMESPACE:
      {
        return new NamespaceNode((NamespaceType)type);
      }

    case Type.FUNCTION:
      {
        return onFunction(listener, type);
      }
     
    case Type.INTERFACE_METHOD:
      {
        return new TypeNode(type);
      }

    case Type.METHOD:
      {
        MethodType method = (MethodType)type;
        ClassStatement context = _statement.getClassStatement();

        if (type instanceof FunctionStatement) {
          FunctionStatement function = (FunctionStatement)type;
          if (function.getContext() != null) {
            if (hasArgs()) {
              return new InlinedCallNode(_statement.getFunctionStatement(), function, consumeArgs());
            } else {
              return new InlinedFunctionNode(_statement.getFunctionStatement(), function);
            }
          }
        }
        if (hasMoreSymbols()) {
          return new TypeNode(type);
        } else {
          Grammar.checkInstanceAmbiguity(listener, _location, context, method);
          if (hasArgs()) {
            //methodname(...)
            checkArguments(listener, method);
            return new StaticInvokeNode(method.getClassType(), context, method, consumeArgs());
          } else {
            //methodname
            return new DelegateNode(new ThisNode(context, method.getClassType()), method);
          }
        }
      }
     
    case Type.CONSTRUCTOR:
      {
        if (!hasMoreSymbols()) {
          if (hasArgs()) {
            listener.error(_location, "Trying to call constructor '"+type+"'");
            return null;
          }
        }
        return new TypeNode(type);
      }

    case Type.CONSTANT_VARIABLE:
      {
        if (_role != GET) {
          listener.error(_location, "Attempting to assign to constant '"+symbol+"'");
        }
        return new ConstantVariableNode((ConstantVariableType)type);
      }
   
    case Type.STATIC_VARIABLE:
      {
        return new StaticVariableNode((StaticVariableType)type);
      }

    case Type.MEMBER_VARIABLE:
      {
        ClassStatement context = _statement.getClassStatement();
        MemberVariableType member = (MemberVariableType)type;
        Grammar.checkInstanceAmbiguity(listener, _location, context, member);
        return new MemberVariableNode(context, member);
      }

    case Type.FUNCTION_PARAMETER:
    case Type.LOCAL_VARIABLE:
      {
        FunctionStatement context = _statement.getFunctionStatement();
        if (type.getParent() != context) {
          return new EscapedVariableNode(symbol, (LocalVariableStatement)type, context);
        } else {
          return new VariableNode((LocalVariableStatement)type);
        }   
View Full Code Here

     
    case ParserBaseConstants.FUNCTION:
      {
        // function
        consumeSymbol();
        FunctionStatement function = _statement.getFunctionStatement();
        if (function != null) {
          return onFunction(listener, function);
        } else {
          listener.error(_location, "Cannot use 'function' outside functions");
          return null;
View Full Code Here

      String name = s.image;
      String document = (r!=null) ? r.document : t.document;

      DefinitionStatement target = flowPeek().getDefinitionStatement();
      DefinitionStatement parent = flowPeek().getScopeStatement();
      FunctionStatement  context = flowPeek().getFunctionStatement();

      FunctionStatement function = new FunctionStatement(toLocation(t), parent, context, is_synchronized, name, document, parameters);
      function.setParentStatement(flowPeek());
      if (target.lookupDeclaration(name) == null) {
        parent.declare(function);
        if (context != null) {
          context.declare(name, function);
        }
      } else {
        error(toLocation(t), "Entity '" + name + "' is already declared");
      }
      flowPush(function);
      flowPush(function.getChildStatement());
    jj_consume_token(BEGIN);
    label_8:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case MODULE:
View Full Code Here

      String document = t.document;
      String name = s.image;

      DefinitionStatement target = flowPeek().getDefinitionStatement();
      ClassStatement      parent = flowPeek().getClassStatement();
      FunctionStatement  context = flowPeek().getFunctionStatement();

      if (context != null) {
        if (context.getType() == Type.FUNCTION) {
          is_static = true;
        }
      }
      if (is_static) {
        if (name.equals(parent.getName())) {
          error(location, "Static methods may not used as constructors");
        }
        FunctionStatement function = new FunctionStatement(location, parent, context, is_synchronized, name, document, parameters);
        function.setParentStatement(flowPeek());
        if (target.lookupDeclaration(name) == null) {
          parent.declare(function);
          if (context != null) {
            context.declare(name, function);
          }
        } else {
          error(location, "Entity '" + name + "' is already declared");
        }
        flowPush(function);
        flowPush(function.getChildStatement());

      } else {
        MethodStatement method;
        if ((context == null) && name.equals(parent.getName())) {
          is_constructor = true;
View Full Code Here

      jj_consume_token(-1);
      throw new ParseException();
    }
      Statement stmt = flowPeek();
      DefinitionStatement parent = stmt.getScopeStatement();
      FunctionStatement context  = stmt.getFunctionStatement();
      FunctionStatement function;
      String name = "inline$" + parent.getNextInlined();
      if (parent.typeOf() == Statement.ST_CLASS) {
        function = new MethodStatement(toLocation(t), parent, context, false, name, null, parameters);
      } else {
        function = new FunctionStatement(toLocation(t), parent, context, false, name, null, parameters);
      }
      function.setParentStatement(flowPeek());
      parent.declare(function);
      flowPush(function);
      flowPush(function.getChildStatement());
      push(new InlinedFunctionNode(context, function));
    label_10:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case MODULE:
View Full Code Here

  }

  final public void LazyExpression() throws ParseException {
  Token op = null;
  Location location = null;
  FunctionStatement thunk = null;
  FunctionStatement context = null;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case CARET:
      op = jj_consume_token(CARET);
      location = toLocation(op);
      Statement stmt = flowPeek();
      DefinitionStatement parent = stmt.getScopeStatement();
      context = stmt.getFunctionStatement();
      String name = "thunk$" + parent.getNextInlined();
      if (parent.typeOf() == Statement.ST_CLASS) {
        thunk = new MethodStatement(location, parent, context, false, name, null, ParameterListDeclaration.EMPTY);
      } else {
        thunk = new FunctionStatement(location, parent, context, false, name, null, ParameterListDeclaration.EMPTY);
      }
      thunk.setParentStatement(flowPeek());
      parent.declare(thunk);
      flowPush(thunk);
      flowPush(thunk.getChildStatement());
View Full Code Here

    case INF:
    case FALSE:
    case TRUE:
    case PATTERN:
      ArrayArgument();
      FunctionStatement function = flowPeek().getFunctionStatement();
      VariableNode var = new VariableNode(function.declare("array$"+root.hashCode()));
      Location location = parent.getLocation();
      AssignmentNode assign = new AssignmentNode(location, 2);
      assign.setChild(0, new EmptyReferenceNode(var));
      assign.setChild(1, pop());
      parent.setChildStatement(new EvalStatement(parent, location,
View Full Code Here

    super();
    _local = local;
    _index = local.getSlot();
    _context = context;
    local.markEscaped();
    FunctionStatement function = context;
    while(function != null && function != local.getParent()) {
      _depth++;
      function = function.getContext();
      if (function != null) {
        function.markEscaped();
      }
    }
  }
View Full Code Here

TOP

Related Classes of anvil.script.statements.FunctionStatement

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.