Package macromedia.asc.semantics

Examples of macromedia.asc.semantics.Slot


        {
            // second time we are evaluated from statementList's evaluator in order to add this def to
            //  the block's def_bits.
            getEmitter().AddStmtToBlock(node.toString());
            node.gen_bits = getEmitter().NewDef(node);
            Slot slot = node.ref.getSlot(cx);
            if (slot != null)
                slot.addDefBits(node.gen_bits);

            node.needs_init = false;
            return null;
        }

        if (node.ref != null) { return null; }

        // If this is a toplevel definition (pkgdef!=null), then set up access namespaces

        if( node.attrs != null && node.attrs.hasAttribute(STATIC) )
        {
            cx.error(node.attrs.pos(), kError_StaticModifiedNamespace);
        }

        if( node.pkgdef != null && cx.getScopes().size() == 1 )
        {
            public_namespaces.push_back(node.pkgdef.publicNamespace);
            default_namespaces.push_back(node.pkgdef.internalNamespace);
            usednamespaces_sets.push_back(node.pkgdef.used_namespaces);
            importednames_sets.push_back(node.pkgdef.imported_names);
        }

        ClassBuilder classBuilder = classBuilderOnScopeChain(cx);
        if (classBuilder != null && classBuilder.is_interface)
        {
            cx.error(node.pos(), kError_NamespaceInInterface);
        }
        Namespaces namespaces = new Namespaces();
        ObjectList<String> namespace_ids = new ObjectList<String>();
        computeNamespaces(cx,node.attrs,namespaces,namespace_ids);

        Value v = node.name.evaluate(cx,this);
        node.ref = ((v instanceof ReferenceValue) ? (ReferenceValue)v : null);

        // Get the current object and its builder

        ObjectValue obj = cx.scope();
        Builder     bui = obj.builder;

        boolean is_intrinsic = false;

        int slot_id = -1;

        Namespaces hasNamespaces = obj.hasNames(cx,GET_TOKEN,node.ref.name,namespaces);
        if( hasNamespaces != null )
        {
            cx.error(node.pos(), kError_DuplicateNamespaceDefinition);
        }
        else
        {
            if( bui.is_intrinsic || is_intrinsic )
            {
                slot_id = bui.ExplicitVar(cx,obj,node.ref.name,namespaces,cx.noType(),-1);
            }
            else
            {
                int var_id;
                var_id  = bui.Variable(cx,obj);
                slot_id = bui.ExplicitVar(cx,obj,node.ref.name,namespaces,cx.noType(),-1,-1,var_id);
            }
        }


        node.debug_name = region_name_stack.back();
        // store debug name on the slot as well.  asDoc needs fully qualified debug_names for all
        //  type references.
        Slot s = obj.getSlot(cx,slot_id);
        if (s != null)
        {
            s.setDebugName(node.debug_name);
        }

        node.qualifiedname = cx.computeQualifiedName(node.debug_name, node.ref.name, namespaces.back(), EMPTY_TOKEN);

        if( !is_intrinsic && slot_id >= 0 )
        {
            Slot slot = obj.getSlot(cx,slot_id);
            if( node.value != null )
            {
                if( node.value instanceof LiteralStringNode )
                {
        // NOTE we distinguish between package public (NS_PUBLIC) and explicit namespaces (NS_EXPLICIT)
        // so that we know which builtin namespaces to mark with a version marker
        slot.setObjectValue(cx.getNamespace(((LiteralStringNode)node.value).value, Context.NS_EXPLICIT));
                }
                else
                {
                    Value val= node.value.evaluate(cx, this);
                    if( val instanceof ReferenceValue )
                    {
                        Slot ns_slot = ((ReferenceValue)val).getSlot(cx);
                        if( ns_slot != null && cx.isNamespace(ns_slot.getObjectValue()) )
                        {
                            slot.setObjectValue(ns_slot.getObjectValue() );
                        }
                    }
                }
            }
            else
View Full Code Here


            // Simple references always have a node.ref, unless they
            // are a function literal.

            if( node.ref != null )
            {
                Slot slot = node.ref.getSlot(cx,(node.ref.getKind()==SET_TOKEN?SET_TOKEN:GET_TOKEN));
                node.ref.slot = null; // Don't bind to this slot, since it could be hidden by another slot later
                if (slot == null)
                {
                    // System.err.println("Unresolved symbol '" + node.ref.toMultiName() + "' on line " + (cx.getInputLine(node.selector.pos()) + 1) + " in " + cx.getErrorOrigin());
                    unresolved.add(node.ref);
View Full Code Here

        {
            node.args.evaluate(cx, this);

            if (cx.statics.withDepth == -1)
            {
                Slot slot = null;
                node.ref.setBase(node.base)// inherited attribute
                slot = node.ref.getSlot(cx, GET_TOKEN);
                node.ref.setKind(SET_TOKEN);
                if (slot != null)
                {
                    slot.addDefBits(node.gen_bits);
                }
            }
        }

        freeTemp(t);
View Full Code Here

            else
            {
                int var_id;
                var_id  = bui.Variable(cx,obj);
                slot_id = bui.ExplicitVar(cx,obj,node.ref.name,namespaces,type,-1,-1,var_id);
                Slot slot = obj.getSlot(cx,slot_id);
                slot.setConst(is_const);
                slot.setTypeRef(node.typeref);

                if( (node.block != null) ||  // node.block is null for defintions at the top level of the method
                  (node.initializer == null) )
                {
                  // Need to init the local at the beginning of the method
                  // so that the types at the backwards branch will match at
                  // verify time.
                  slot.setNeedsInit(true);
                }
            }
        }
        else
        {
            String nsstr = "";
            for (ObjectValue ns : matchingNamespaces)
            {
                if (nsstr.length() != 0)
                    nsstr += " ";

                if (ns.name.length() == 0)
                {
                    nsstr += PUBLIC;
                }
                else
                {
                    switch( ns.getNamespaceKind() )
                    {
                        case Context.NS_PRIVATE:
                            nsstr += PRIVATE;
                            break;
                        case Context.NS_INTERNAL:
                            nsstr += INTERNAL;
                            break;
                        case Context.NS_PROTECTED:
                            nsstr += PROTECTED;
                            break;
                        default:
                            nsstr += ns.name;
                            break;
                    }
                }
            }

            int slot_index = obj.getSlotIndex(cx, kind,node.ref.name, matchingNamespaces.back());
            Slot orig = obj.getSlot(cx, slot_index);

            boolean isGlobalDefinition = bui instanceof GlobalBuilder && !node.inPackage();
            boolean isLocalDefinition  = bui instanceof ActivationBuilder;
            boolean isGlobalOrLocalDefinition = isGlobalDefinition || isLocalDefinition;

            if( isGlobalOrLocalDefinition && node.attrs == null && node.variable.type == null )
            {
                if( orig.getType().getTypeValue() == cx.typeType() || orig.isConst() )
                {
                    // attempting to declare a var with the same name as a class, don't allow that
                    cx.error(node.variable.identifier.pos(), kError_ConflictingNameInNamespace, node.ref.name, "internal");
                }
                else
                {
                    // ed.3 decl, so let it go
                    // need to modify the qualified identifers attribute list, so that the
                    // qualified identifier node that was auto generated for the init statement will refer to the correct namespace
                    NodeFactory nf = cx.getNodeFactory();
                    AttributeListNode aln = nf.attributeList(nf.identifier(matchingNamespaces.back().name,node.variable.pos()),null);
                    aln.items.clear();
                    aln.namespaces.addAll(matchingNamespaces);
                    if( node.variable.identifier instanceof QualifiedIdentifierNode )
                    {
                        ((QualifiedIdentifierNode)node.variable.identifier).qualifier = aln;
                    }
                    else
                    {
                        node.variable.identifier = nf.qualifiedIdentifier(aln, node.variable.identifier.name, node.variable.identifier.pos());
                    }
                    node.variable.identifier.ref = null; // force this to be regenerated since the namespace has probably changed
                    Value val2 = node.variable.identifier.evaluate(cx,this);
                    node.ref = (val instanceof ReferenceValue) ? (ReferenceValue) val2 : null;
                }
            }
            else
            if( orig.declaredBy != obj )
            {
                String fullname = getFullNameForInheritedSlot(cx, orig.declaredBy, node.ref.name);
                cx.error(node.variable.identifier.pos(), kError_ConflictingInheritedNameInNamespace, fullname, nsstr);
            }
            else
            {
                if( isGlobalOrLocalDefinition && !orig.isConst() && (orig.getTypeRef()==null || node.typeref==null || orig.getTypeRef().name.equals(node.typeref.name)) )
                {
                    // compatible definitions so allow
                }
                else
                {
                    cx.error(node.variable.identifier.pos(), kError_ConflictingNameInNamespace, node.ref.name, "internal");
                }
            }
            if( (node.block != null) ||  // node.block is null for defintions at the top level of the method
                  (node.initializer == null) )
            {
              // Need to init the local at the beginning of the method
              // so that the types at the backwards branch will match at
              // verify time.
              orig.setNeedsInit(true);
            }
           
        }

        node.debug_name = cx.debugName(region_name_stack.back(),node.ref.name,namespace_ids,VAR_TOKEN);
View Full Code Here

                    isDynamic = base.isDynamic() && !(base.getType(cx).getTypeValue() == cx.functionType() && (base.builder instanceof GlobalBuilder));
                }


                int refType = !(node.selector instanceof SetExpressionNode) ? GET_TOKEN : SET_TOKEN;
                Slot slot = node.ref.getSlot(cx,refType);
                if( slot == null )
                {
                    //  cn: Function is declared dynamic in Function.as, but its not dynamic in !
                    if( !in_with && !isDynamic )
                    {
                        ObjectList<ObjectValue> scopes = cx.getScopes();
                        int x;
                        for(x=0;x<scopes.size();x++)
                        {
                            ObjectValue scope = scopes.get(x);
                            if ( (scope.builder) instanceof InstanceBuilder &&
                                 !(node.selector.expr instanceof QualifiedIdentifierNode) &&  // If it was qualified then fall through to the normal unfound property error
                                 scope.hasNameUnqualified(cx, node.ref.name, GET_TOKEN)  )
                            {
                                cx.error(node.selector.expr.pos(), kError_InaccessiblePropertyReference,node.ref.name, scope.type.getName(cx).toString());
                                break;
                            }
                        }
                        // bad function calls have already been reported in CallExpressionNode
                        if (x == scopes.size() && !(node.selector instanceof CallExpressionNode))
                        {
                            String qualified_pkg_name = null;
                            if( node.selector.expr instanceof QualifiedIdentifierNode )
                            {
                                ObjectValue namespace = node.ref.namespaces.at(0);
                                if( namespace.isPackage() )
                                {
                                    qualified_pkg_name = namespace.name;
                                }
                            }
                            if( node.selector instanceof SetExpressionNode )
                            {
                                slot = node.ref.getSlot(cx, GET_TOKEN);
                                if( !( slot != null && slot.getType()!= null && slot.getType().getTypeValue() == cx.functionType() && slot.getObjectValue() != null) )
                                {
                                    if( qualified_pkg_name != null )
                                        cx.error(node.selector.expr.pos(), kError_UnfoundPackageProperty, node.ref.name, qualified_pkg_name);
                                    else
                                        // Attempting to set a function will be caught by the SetExpressionNode
                                        cx.error(node.selector.expr.pos(), kError_UnfoundProperty,node.ref.name);
                                }
                            }
                            else
                            {
                                if( qualified_pkg_name != null )
                                    cx.error(node.selector.expr.pos(), kError_UnfoundPackageProperty, node.ref.getDiagnosticTypeName(), qualified_pkg_name);
                                else
                                    cx.error(node.selector.expr.pos(), kError_UnfoundProperty,node.ref.getDiagnosticTypeName());
                            }
                        }
                    }
                }
            }
            if( node.selector.is_package && node.ref.getSlotIndex(GET_TOKEN) < 0 )
            {
                cx.error(node.selector.expr.pos(),kError_IllegalPackageReference,node.ref.name);
            }
        }

        val = node.selector.evaluate(cx, this);

       // If the base is an XML or XMLIST, return type * to avoid possibly bogus -strict type coercion errors.
        if (node.base != null && node.base instanceof MemberExpressionNode)
        {
            MemberExpressionNode m = (MemberExpressionNode)(node.base);
            Slot s = (m.ref != null) ? m.ref.getSlot(cx,GET_TOKEN) : null;
            TypeInfo ti = s != null ? s.getType() : null;
            TypeValue slot_type = ti != null ? ti.getTypeValue() : null;
            if (slot_type == cx.xmlType() || slot_type == cx.xmlListType())
            {
                return cx.noType().prototype; //  a property like .name may resolve to a method slot, but might actually be refering to a dynamically defined xml attribute or child
            }
View Full Code Here

            else
            {
              type[0] = null;
            }

            Slot slot;

            {
                ObjectValue global = cx.builtinScope();
                if (type[0] != null && type[0].getTypeValue() != cx.uintType()) // overloading not working correctly for uints
                    slot_index  = global.getOverloadIndex(cx,slot_index,type[0].getTypeValue());
               
                slot = global.getSlot(cx, slot_index);

                // Now we know the type expected by the unary operator. Coerce it.
                //  cn: (but not if node.op == typeof.  typeof should return 'undefined' for an
                //  undefined variable,  don't try to coerce the potentially undefined expr to Object).
                if (node.op != TYPEOF_TOKEN)
                    node.expr = cx.coerce(node.expr, type, size(slot.getTypes()) != 0 ? slot.getTypes().get(0) : null);

                // Save the slot index in the node for later use
                // by the code generator.
                node.slot = slot;
            }

            val = slot.getType().getPrototype();
        }
        return val;
    }
View Full Code Here

        TypeInfo type = val != null ? val.getType(cx) : null;

        if (node.ref != null)
        {
            node.ref.calcUseDefinitions(cx, rch_bits);
            Slot slot = node.ref.getSlot(cx,GET_TOKEN);
            if( cx.useStaticSemantics() ) // bang
            {
                if( slot == null )
                {
                    ObjectValue base = node.ref.getBase();
                    //  cn: Function is declared dynamic in Function.as, but its not dynamic in !

                    if( base != null && (!base.isDynamic() || (base.getType(cx).getTypeValue() == cx.functionType() && !(base.builder instanceof GlobalBuilder))) )
                    {
                        if (base.hasNameUnqualified(cx, node.ref.name, GET_TOKEN))
                            cx.error(node.pos(), kError_InaccessiblePropertyReference, node.ref.name, base.getType(cx).getName(cx).toString());
                        else
                            cx.error(node.pos(), kError_UndefinedProperty,node.ref.name,base.getType(cx).getName(cx).toString());
                    }
                }
            }

            if (slot != null &&
              !(slot instanceof VariableSlot) && // FIXME: tpr added this since var's don't get a set slot,  
              node.ref.getSlot(cx,SET_TOKEN) == null)
            {
                cx.error(node.pos(), node.op == PLUSPLUS_TOKEN ? kError_InvalidIncrementOperand : kError_InvalidDecrementOperand);
            }
        }
        else
        {
            QualifiedExpressionNode qen = node.getIdentifier() instanceof QualifiedExpressionNode? (QualifiedExpressionNode)node.getIdentifier() : null;
            if (qen != null && qen.nss != null )
            {
                cx.error(node.pos(), node.op == PLUSPLUS_TOKEN ? kError_InvalidIncrementOperand : kError_InvalidDecrementOperand);
                     // this is a case we just don't handle. might need a more descriptive message
            }

        }
        ObjectValue global = cx.builtinScope();
        int slot_index = 0;
        switch (node.op)
        {
            case PLUSPLUS_TOKEN:
                // [ed] issue re-enable incrementlocal only when no coersion is needed
                //slot_index = (base_index != 0 && base_index == scope_depth) ? SLOT_Global_IncrementLocalOp : SLOT_Global_IncrementOp;
                slot_index = SLOT_Global_IncrementOp;
                break;
            case MINUSMINUS_TOKEN:
                //slot_index = (base_index != 0 && base_index == scope_depth) ? SLOT_Global_DecrementLocalOp : SLOT_Global_DecrementOp;
                slot_index = SLOT_Global_DecrementOp;
                break;
            default:
                assert(false); // throw "invalid unary operator";
        }

        if (type != null && type.getTypeValue() != cx.uintType()) // overloading not working correctly for uints
            slot_index  = global.getOverloadIndex(cx,slot_index,type.getTypeValue());
        node.slot = global.getSlot(cx, slot_index);

        Slot s = val instanceof ReferenceValue ? ((ReferenceValue)val).getSlot(cx): null;
        TypeInfo atype[] = new TypeInfo[1];
        atype[0] = s != null ? s.getType() : val!=null ? val.getType(cx) : cx.noType().getDefaultTypeInfo();      // get the static type from the reference value, or literal

       
        TypeValue currentNumberType = cx.doubleType();
        if (node.numberUsage != null)
          switch (node.numberUsage.get_usage()) {
View Full Code Here

        {
            lhsval = node.lhs.evaluate(cx,this);
            if (lhsval != null)
            {
                Value constVal = lhsval.getValue(cx);
                Slot s = lhsval instanceof ReferenceValue ? ((ReferenceValue)lhsval).getSlot(cx): null;
                lhstype[0] = s != null ? s.getType():lhsval.getType(cx);      // get the static type from the reference value, or literal
                lhsval = constVal!=null&&constVal.hasValue()?constVal:null;
            }
        }
        if (node.rhs != null)
        {
            rhsval = node.rhs.evaluate(cx,this);
            if (rhsval != null)
            {
                Value constVal = rhsval.getValue(cx);
                Slot s = rhsval instanceof ReferenceValue ? ((ReferenceValue)rhsval).getSlot(cx): null;
                rhstype[0] = s != null ? s.getType():rhsval.getType(cx);      // get the static type from the reference value, or literal
                rhsval = constVal!=null&&constVal.hasValue()?constVal:null;

                if (node.op == AS_TOKEN)     // save rhsval as result of "as"
                {
                    TypeValue typeval = (constVal instanceof TypeValue) ? (TypeValue)constVal : cx.objectType();
                    resultType = typeval.getDefaultTypeInfo();
                }
            }
        }

        int slot_index = 0;


        if (cx.useStaticSemantics() && lhstype[0] != null && rhstype[0] != null ) // null types are o.k., they mean don't do type checking or op-code overriding.
        {
            switch(node.op)
            {
                // check for comparisions between incompatable types
                case EQUALS_TOKEN:
                case NOTEQUALS_TOKEN:
                case LESSTHAN_TOKEN:
                case GREATERTHAN_TOKEN:
                case LESSTHANOREQUALS_TOKEN:
                case GREATERTHANOREQUALS_TOKEN:
                case STRICTNOTEQUALS_TOKEN:
                case STRICTEQUALS_TOKEN:

                    if ( lhstype[0].getTypeValue() == cx.noType() || rhstype[0].getTypeValue() == cx.noType() ||
                         lhstype[0].getTypeValue() == cx.booleanType() || rhstype[0].getTypeValue() == cx.booleanType() ||
                         lhstype[0].isInterface()      || rhstype[0].isInterface() ||
                         lhstype[0].includes(cx,rhstype[0]) || rhstype[0].includes(cx,lhstype[0]) )
                    {
                        // no problem
                        // why boolean?  since everyting implicitly converts to boolean,
                        //  var s:string = "",
                        //  if (s) {} // should be equivalent to
                        //  if (s == true) { }
                    }
                    // check comparision between null and un-nullable type
                    else if (lhstype[0].getTypeValue() == cx.nullType() || rhstype[0].getTypeValue() == cx.nullType())
                    {
                        if (lhstype[0].getTypeValue() == cx.nullType() &&
                            (rhstype[0].getTypeValue().isNumeric(cx)   || rhstype[0].getTypeValue() == cx.booleanType() ))
                        {
                            cx.error(node.pos(), kError_IncompatableValueComparison, lhstype[0].getName(cx).toString(), rhstype[0].getName(cx).toString());
                        }
                            // yes, this could be combined with the above, but it would be hard to read
                        else if (rhstype[0].getTypeValue() == cx.nullType() &&
                                 (lhstype[0].getTypeValue().isNumeric(cx)   || lhstype[0].getTypeValue() == cx.booleanType() ))
                        {
                            cx.error(node.pos(), kError_IncompatableValueComparison, lhstype[0].getName(cx).toString(), rhstype[0].getName(cx).toString());
                        }
                        // else no problem
                    }
                    // E4X allows  XML to be compared directly with Strings
                    else if ( (lhstype[0].getTypeValue() == cx.xmlType() && rhstype[0].getTypeValue() == cx.stringType()) ||
                         (rhstype[0].getTypeValue() == cx.stringType() && lhstype[0].getTypeValue() == cx.xmlType()) )
                    {
                        // no problem, <a>test</a> == "test"; // is true
                    }
                    // Check for comparision between unrelated types (unless its between number types)
                    else if ( !((lhstype[0].getTypeValue().isNumeric(cx)) && (rhstype[0].getTypeValue().isNumeric(cx))) )
                    {
                        cx.error(node.pos(), kError_IncompatableValueComparison, lhstype[0].getName(cx).toString(), rhstype[0].getName(cx).toString());
                    }

                    break;
            }
        }

        TypeValue lhstypeval = lhstype[0] != null ? lhstype[0].getTypeValue() : null;
        TypeValue rhstypeval = rhstype[0] != null ? rhstype[0].getTypeValue() : null;
       
        TypeValue currentNumberType = cx.doubleType();
        if (node.numberUsage != null)
          switch (node.numberUsage.get_usage()) {
           case NumberUsage.use_int:
            currentNumberType = cx.intType();
            break;
          case NumberUsage.use_uint:
            currentNumberType = cx.uintType();
            break;
          case NumberUsage.use_decimal:
            currentNumberType = cx.decimalType();
            break;
          case NumberUsage.use_double:
          case NumberUsage.use_Number:
          default:
            currentNumberType = cx.doubleType();
          }


        // now process op as normal
        switch (node.op)
        {
            case MULT_TOKEN:
                slot_index = SLOT_Global_MultiplyOp;
                // RES this is probably wrong with uint as a full citizen
                if ((lhstypeval == cx.intType() || lhstypeval == cx.uintType()) && (rhstypeval == cx.intType() || rhstypeval == cx.uintType()))
                {
                    resultType = cx.intType().getDefaultTypeInfo();
                }
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                break;
            case DIV_TOKEN:
                slot_index = SLOT_Global_DivideOp;
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                break;
            case MODULUS_TOKEN:
                slot_index = SLOT_Global_ModulusOp;
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                break;
            case PLUS_TOKEN:
                if( lhsval != null && rhsval != null && lhsval.hasValue() && rhsval.hasValue() )
                {
                    // cn: see bug 124260.  A literal number might not always print as its compile time string rep
                    /* cn actually, this is causing errors even when lhs and rhs are strings
                    if( (lhstype[0] == cx.stringType() && rhstype[0] != cx.numberType()) ||
                        (rhstype[0] == cx.stringType() && lhstype[0] != cx.numberType()))
                    {
                        node.lhs = cx.getNodeFactory().literalString(lhsval.toString()+rhsval.toString(),0);
                        node.op = EMPTY_TOKEN;
                        val = node.lhs.evaluate(cx,this);  // get the folded value
                    }
                    */
                }
                slot_index = SLOT_Global_BinaryPlusOp;
                if ( (lhstypeval == cx.xmlListType() || lhstypeval == cx.xmlType()) &&
                     (rhstypeval == cx.xmlListType() || rhstypeval == cx.xmlType()))
                {
                    resultType = cx.xmlListType().getDefaultTypeInfo();
                }
                else if ( (lhstypeval != null) && (lhstypeval.isNumeric(cx)) &&
                          (rhstypeval != null) && (rhstypeval.isNumeric(cx)) )
                {
                    resultType = currentNumberType.getDefaultTypeInfo();
                }
                else if ( lhstypeval == cx.stringType() || rhstypeval == cx.stringType() ) // anything + a string is a string.
                {
                    resultType = cx.stringType().getDefaultTypeInfo();
                }
                else
                {
                    resultType = cx.noType().getDefaultTypeInfo(); // can't tell.  Could be number, string or xmllist
                }

                break;
            case MINUS_TOKEN:
                slot_index = SLOT_Global_BinaryMinusOp;
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                if ((lhstypeval == cx.intType() || lhstypeval == cx.uintType()) && (rhstypeval == cx.intType() || rhstypeval == cx.uintType()))
                    resultType = cx.intType().getDefaultTypeInfo();
                break;
            case LEFTSHIFT_TOKEN:
                slot_index = SLOT_Global_LeftShiftOp;
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                break;
            case RIGHTSHIFT_TOKEN:
                slot_index = SLOT_Global_RightShiftOp;
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                break;
            case UNSIGNEDRIGHTSHIFT_TOKEN:
                slot_index = SLOT_Global_UnsignedRightShiftOp;
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                break;
            case LESSTHAN_TOKEN:
                slot_index = SLOT_Global_LessThanOp;
                break;
            case GREATERTHAN_TOKEN:
                slot_index = SLOT_Global_GreaterThanOp;
                break;
            case LESSTHANOREQUALS_TOKEN:
                slot_index = SLOT_Global_LessThanOrEqualOp;
                break;
            case GREATERTHANOREQUALS_TOKEN:
                slot_index = SLOT_Global_GreaterThanOrEqualOp;
                break;
            case INSTANCEOF_TOKEN:
                slot_index = SLOT_Global_InstanceofOp;
                break;
            case IN_TOKEN:
                slot_index = SLOT_Global_InOp;
                break;
            case IS_TOKEN:
                slot_index = SLOT_Global_IsLateOp;
                cx.coerce(node.rhs,rhstype,cx.typeType());
                break;
            case AS_TOKEN:
                slot_index = SLOT_Global_AsLateOp;
                cx.coerce(node.rhs,rhstype,cx.typeType());
                break;
            case EQUALS_TOKEN:
                slot_index = SLOT_Global_EqualsOp;
                break;
            case NOTEQUALS_TOKEN:
                slot_index = SLOT_Global_NotEqualsOp;
                break;
            case STRICTEQUALS_TOKEN:
                slot_index = SLOT_Global_StrictEqualsOp;
                break;
            case STRICTNOTEQUALS_TOKEN:
                slot_index = SLOT_Global_StrictNotEqualsOp;
                break;
            case BITWISEAND_TOKEN:
                slot_index = SLOT_Global_BitwiseAndOp;
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                break;
            case BITWISEXOR_TOKEN:
                slot_index = SLOT_Global_BitwiseXorOp;
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                break;
            case BITWISEOR_TOKEN:
                slot_index = SLOT_Global_BitwiseOrOp;
                cx.coerce(node.lhs,lhstype,currentNumberType);
                cx.coerce(node.rhs,rhstype,currentNumberType);
                break;
            case LOGICALAND_TOKEN:
                slot_index = SLOT_Global_LogicalAndOp;

                if (lhstype[0] == rhstype[0])
                    resultType = lhstype[0];
                /*
                else if (lhstype[0] != null && lhstype[0] != cx.noType() && rhstype[0] != null && rhstype[0] != cx.noType())
                    resultType = cx.objectType(); // if its not null or *, then we at least know it can't be undefined.
                */
                break;

            case LOGICALOR_TOKEN:
                slot_index = SLOT_Global_LogicalOrOp;
                if (lhstype[0] == rhstype[0])
                    resultType = lhstype[0];
                /*
                else if (lhstype[0] != null && lhstype[0] != cx.noType() && rhstype[0] != null && rhstype[0] != cx.noType())
                    resultType = cx.objectType(); // if its not null or *, then we at least know it can't be undefined.
                */
                break;

            case EMPTY_TOKEN:
                // do nothing, already been folded
                break;
            default:
                cx.internalError("unrecognized binary operator");
                break;
        }

        Slot slot;

        if( node.op != EMPTY_TOKEN )
        {
            // ObjectValue global = null;

            ObjectValue global = cx.builtinScope();
            if (lhstypeval != cx.uintType() && rhstypeval != cx.uintType() ) // overloading not working correctly for uints
            {
                slot_index  = global.getOverloadIndex(cx, slot_index, lhstypeval, rhstypeval);
            }
            slot = global.getSlot(cx, slot_index);

            // Now we know the types expected by the overloaded operator.
            // Coerce the operands.
            node.lhs = cx.coerce(node.lhs, lhstype, size(slot.getTypes()) > 0 ? slot.getTypes().get(0) : null);
            node.rhs = cx.coerce(node.rhs, rhstype, size(slot.getTypes()) > 0 ? slot.getTypes().get(1) : null);

            node.lhstype = lhstype[0];
            node.rhstype = rhstype[0];

            // Save the slot index in the node for later use
            // by the code generator.
            node.slot = slot;

            if( lhsval instanceof ObjectValue && rhsval instanceof ObjectValue )
            {
                val = computeBinaryExpr(cx,node.op,(ObjectValue)lhsval,(ObjectValue)rhsval, node.numberUsage);
            }
            else if (resultType != null)
            {
                val = resultType.getPrototype();
            }
            else
            {
                val = slot.getType().getPrototype();
            }
        }

        return val;
    }
View Full Code Here

    }

    public Value evaluate(Context cx, VariableBindingNode node)
    {
        TypeInfo type = null;
        Slot slot = node.ref.getSlot(cx);

        if( node.typeref != null )
        {
            Slot typeSlot = node.typeref.getSlot(cx);
            if (typeSlot == null  || typeSlot.getValue() == null)
            {
                cx.error(node.variable.type.pos(), kError_UnknownType, node.typeref.getDiagnosticTypeName());
                slot.setType(type = cx.noType().getDefaultTypeInfo());
            }
            else
            {
                Value v = typeSlot.getValue();
                if( v instanceof TypeValue )
                {
                    TypeValue tv = (TypeValue)v;
                    type = node.typeref.has_nullable_anno ? tv.getTypeInfo(node.typeref.is_nullable) : tv.getDefaultTypeInfo();
                }
View Full Code Here

            if( node.name.kind == GET_TOKEN ||
                node.name.kind == SET_TOKEN )
            {
                node.ref.getType(cx,GET_TOKEN); // lazily inherit type info
                node.ref.getType(cx,SET_TOKEN); //  yeah.
                Slot s1 = node.ref.getSlot(cx,GET_TOKEN);
                Slot s2 = node.ref.getSlot(cx,SET_TOKEN);
                if( s1 != null && s2 != null )
                {
                    TypeInfo t1 = s1.getType();
                    TypeInfo t2 = size(s2.getTypes()) > 0 ? s2.getTypes().get(0) : cx.noType().getDefaultTypeInfo();
                    if( !compareTypeInfos(t1, t2) && (t1.getTypeValue() != cx.noType() && t2.getTypeValue() != cx.noType()) )
                    {
                        int pos = node.name.kind == GET_TOKEN ?
                                (node.fexpr.signature.result != null ? node.fexpr.signature.result.pos() : node.fexpr.signature.pos()) :
                                (node.fexpr.signature.parameter != null ? node.fexpr.signature.parameter.items.get(0).type.pos(): node.fexpr.signature.pos());

                        //String kind_str = node.name.kind == GET_TOKEN ? "Getter" : "Setter";
                        //String otherkind_str = node.name.kind == GET_TOKEN ? "setter" : "getter";
                        node.ref.getSlot(cx,SET_TOKEN);
                        cx.error(pos, kError_AccessorTypesMustMatch);
                    }
                }
            }
            if( node.name.kind == SET_TOKEN )
            {
                Slot s2 = node.ref.getSlot(cx,SET_TOKEN);
                if( s2 != null )
                {
                    TypeInfo rt2 = s2.getType();
                    if( node.fexpr.signature.result != null && rt2.getTypeValue() != cx.voidType() )
                    {
                        int pos = node.fexpr.signature.result.pos();
                        cx.error(pos, kError_BadSetterReturnType);
                    }
View Full Code Here

TOP

Related Classes of macromedia.asc.semantics.Slot

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.