Package anvil.script

Examples of anvil.script.Type


    int intclazz = pool.addClass("java/lang/Integer");
    int intclazzctor = pool.addMethodRef(intclazz, "<init>", "(I)V");
    code.iconst(size * 4);
    code.anewarray("java/lang/Object");
    for(int i=0; types.hasMoreElements();) {
      Type type = (Type)types.nextElement();
      switch(type.getType()) {
      case Type.MODULE:
      case Type.CLASS:
      case Type.INTERFACE:
      case Type.NAMESPACE:
      case Type.FUNCTION:
      case Type.METHOD:
      case Type.INTERFACE_METHOD:
      case Type.CONSTRUCTOR:
      case Type.CONSTANT_VARIABLE:
      case Type.STATIC_VARIABLE:
      case Type.MEMBER_VARIABLE:
        {
          code.dup();
          code.iconst(i++);
          code.anew(intclazz);
          code.dup();
          code.iconst(type.getType());
          code.invokespecial(intclazzctor);
          code.aastore();

          code.dup();
          code.iconst(i++);
          code.astring(type.getName());
          code.aastore();

          code.dup();
          code.iconst(i++);
          Doc doc = type.getDocument();
          if (doc != null) {
            doc.compile(code);
          } else {
            code.aconst_null();
          }
          code.aastore();     

          code.dup();
          code.iconst(i++);
          switch(type.getType()) {
          case Type.FUNCTION:
          case Type.METHOD:
          case Type.INTERFACE_METHOD:
          case Type.CONSTRUCTOR:
            ((FunctionStatement)type).compileDescriptor(context);
View Full Code Here


      for(int i=0; i<size; i++) {
        Import imprt = (Import)_imports.get(i);
        Location location = imprt.getLocation();
        Object source = imprt.getSource();
        Name[] decls = imprt.getDeclarations();
        Type type = imprt.resolve(listener);
        if (type != null) {
          if (imprt.importAll()) {
            if (type instanceof Scope) {
              addExternals(listener, location, source, (Scope)type);
            } else {
              listener.error(location, "Trying to import all contained types from non-scoped entity '"+source+"'");
           
           
          } else if (decls != null) {
         
            if (type instanceof Scope) {
              int n = decls.length;
              for(int j=0; j<n; j++) {
                Name childname = decls[j];
                Type child = follow(type, childname);
                if (child != null) {
                  if (childname.hasStar()) {
                    switch(child.getType()) {
                    case MODULE:
                    case NAMESPACE:
                    case CLASS:
                    case INTERFACE:
                      addExternals(listener, location, source, (Scope)child);
View Full Code Here

      DefinitionStatement scope = this;
      for(int i=0; i<n; i++) {
        String part = name.get(i);
        ns = new NamespaceStatement(location, scope);
        ns.setName(part);
        Type declared = scope.lookupDeclaration(part);
        if (declared == null) {
          ns = new NamespaceStatement(location, scope);
          ns.setName(part);
          scope.declare(ns);
        } else if (declared.getType() == Type.NAMESPACE) {
          ns = (NamespaceStatement)declared;
        } else {
          parser.error(location, "Entity '"+name+"' already declared");
          ns = new NamespaceStatement(location, scope);
          ns.setName(part);
View Full Code Here

  protected Type lookupLibrary(ErrorListener context)
  {
    Zone zone = _script.getAddress().getZone();
    Modules modules = zone.getModules();
    Type type = modules.lookupDeclaration(_name.get(_index-1));
    if (type != null) {
      return type;
    }

    StringBuffer libname = new StringBuffer(32);
View Full Code Here

   
    if (!hasMoreSymbols()) {
      return new ThisNode(context, classtype);
    }
   
    Type type = classtype.lookupDeclaration(peekSymbol());
    if (type == null) {
      listener.error(_location, "Undefined entity '" + _name + "'");
      return null;
    }
    switch(type.getType()) {
    case Type.METHOD:
      {
        MethodType method = (MethodType)type;
       
        consumeSymbol();
View Full Code Here

        listener.error(_location, "Left of 'this' in '"+_name+"' does not point into class");
      }
    }

    String symbol = peekSymbol();
    Type type = scope.lookupDeclaration(symbol);
    if (type == null) {
      return new TypeNode(scope);
    }
    switch(type.getType()) {
    case Type.CLASS:
    case Type.INTERFACE:
      {
        consumeSymbol();
        if (hasMoreSymbols()) {
View Full Code Here

  }

  protected Node construct(ErrorListener listener, Scope scope)
  {
    String symbol = peekSymbol();
    Type type;
    if (scope != null) {
      consumeSymbol();
      type = scope.lookupDeclaration(symbol);
      if (type == null) {
        listener.error(_location, "Entity '" + _name + "' is undeclared");
        return null;
      }
       
    } 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

      context.error(_location, "Invalid use of 'super'.");
      return null;
    }
   
    String symbol = consumeSymbol();
    Type type = classtype.lookupInheritedDeclaration(symbol);
    if (type == null) {
      context.error(_location, "Undefined entity '"+_name+"'");
      return null;
    }
   
    switch(type.getType()) {
    case Type.INTERFACE_METHOD:
      {
        context.error(_location, "Illegal access to interface method with 'super'");
        return null;
      }
View Full Code Here

    if (!hasMoreSymbols()) {
      listener.error(_location, "Syntax error: class name expected after 'new'");
      return null;
    }

    Type type;
    String symbol;
   
    if (peekKind() == ParserBaseConstants.MODULE) {
      consumeSymbol();
      type = _script;   
    } else {
      symbol = consumeSymbol();
      type = _statement.lookupAnyDeclaration(symbol);
      if (type == null) {
        type = LangModule.__module__.lookupDeclaration(symbol);
        if (type == null) {
          type = lookupLibrary(listener);
        }
      }
    }
   
    while(true) {
   
      if (type == null) {
        listener.error(_location, "Entity '" + _name.toString(1) + "' is undeclared");
        return null;
      }
     
      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()) {
            symbol = consumeSymbol();
View Full Code Here

    Node node = doLink(listener);
    if (node == null) {
      node = ConstantNode.UNDEFINED;
    }
    if (node instanceof TypeNode) {
      Type type = ((TypeNode)node).getType();
      if (type instanceof Synthetic) {
        listener.error(_location, "Cannot refer to synthetic entities");
        node = ConstantNode.UNDEFINED;
      }
    }
View Full Code Here

TOP

Related Classes of anvil.script.Type

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.