Package macromedia.asc.util

Examples of macromedia.asc.util.IntList


        }

        int return_type = type != null ? addClassName(type.getName(cx)) : 0;
       

        IntList param_types = null;
        IntList param_values = null;
        ByteList param_kinds = null;

        {
            ObjectValue obj = cx.scope();
            Slots slots = obj.slots;

            if (slots != null)
            {
                param_types = new IntList(slots.size());
                param_values = new IntList(slots.size()); // default values
                param_kinds = new ByteList(slots.size());
   
                Iterator<Slot> it = slots.iterator();
                //it.next(); // first one is this
                boolean value_required = false;
                for (int i = 1; it.hasNext() && i < max_params; ++i)
                {
                    Slot slot = it.next();
                    int type_index = addClassName(slot.getType().getName(cx));
                    param_types.add(type_index);
   
                    int value_index = 0;
                    byte value_kind = 0;
                    ObjectValue iv = slot.getInitializerValue();
                    if (iv != null)
                    {
                        value_required = true;
                        String value = iv.toString();
                        NumberUsage numberUsage = iv.getNumberUsage();
                        TypeValue defaultValueType = slot.getInitializerValue().type != null ? slot.getInitializerValue().type.getTypeValue() : null;
                        if (defaultValueType == cx.booleanType())
                        {
                            // The index doesn't matter, as long as its non 0
                            // there are no boolean values in any cpool, instead the value will be determined by the kind byte
                            value_index = value.equals("true")?CONSTANT_True:CONSTANT_False;
                            value_kind = value.equals("true")?CONSTANT_True:CONSTANT_False;
                        }
                        else if (defaultValueType == cx.stringType())
                        {
                            value_index = ab.addUtf8Constant(bytecodeFactory.ConstantUtf8Info(value));
                            value_kind = CONSTANT_Utf8;
                        }
                        else if (defaultValueType == cx.intType())
                        {
                            value_index = ab.addIntConstant(bytecodeFactory.ConstantIntegerInfo(getValueOfNumberLiteral(value,new TypeValue[1], numberUsage).intValue()));
                            value_kind = CONSTANT_Integer;
                        }
                        else if ((defaultValueType == cx.doubleType()) || (cx.abcVersion(Features.TARGET_AVM1) && (defaultValueType == cx.uintType())))
                        {
                            value_index = ab.addDoubleConstant(bytecodeFactory.ConstantDoubleInfo(getValueOfNumberLiteral(value,new TypeValue[1], numberUsage).doubleValue()));
                            value_kind = CONSTANT_Double;
                        }
                        else if (defaultValueType == cx.uintType())
                        {
                            value_index = ab.addUintConstant(bytecodeFactory.ConstantUintInfo(getValueOfNumberLiteral(value,new TypeValue[1], numberUsage).uintValue()));
                            value_kind = CONSTANT_UInteger;
                        }
                        else if (cx.statics.es4_numerics && (defaultValueType == cx.decimalType()))
                        {
                            value_index = ab.addDecimalConstant(bytecodeFactory.ConstantDecimalInfo(getValueOfNumberLiteral(value,new TypeValue[1], numberUsage).decimalValue()));
                            value_kind = CONSTANT_Decimal;
                        }
                        else if (defaultValueType == cx.nullType())
                        {
                            // Similar to boolean above, the value will be determined by the kind byte (there is only 1 possible value for null)
                            value_index = CONSTANT_Null;
                            value_kind = CONSTANT_Null;
                        }
                        else if (defaultValueType == cx.voidType())
                        {
                            value_index = 0; // will be undefined at runtime
                            value_kind = 0;
                        }
                        else if (slot.getInitializerValue() instanceof NamespaceValue )
                        {
                            value_index = addNamespace(slot.getInitializerValue());
                            value_kind = CONSTANT_Namespace;
                        }
                    }
                    if (value_required)
                    {
                        param_values.add(value_index);
                        param_kinds.add(value_kind);
                    }
                }
                if (value_required)
                {
                    flags |= METHOD_HasOptional;
                }
            }
        }

        IntList param_names = null;
        if( emit_code_hints && arg_names != null )
        {
            flags |= METHOD_HasParamNames;
            param_names = new IntList(arg_names.length);
            for( int x = 0; x < arg_names.length; ++x )
            {
                param_names.add(ab.addUtf8Constant(bytecodeFactory.ConstantUtf8Info(arg_names[x])));
            }
        }
        // This is modifying the ab->methods table directly and does not need to call
        // addBytesToTable.
        {
View Full Code Here


    protected void addSlotTrait(ObjectValue obj, ObjectList<ByteList> traits, String name, Qualifiers quals)
    {
        Builder bui = obj.builder;

        IntList namespaces = new IntList(quals.size())// will be (*it)->namespaces

        int prev_var_index = -1;
        int var_index = -1;
        int flags = 0;
        Slot prev_slot = null;

        Iterator<Map.Entry<ObjectValue, Integer>> i = quals.entrySet().iterator();       
        Map.Entry<ObjectValue, Integer> qual_it = i.hasNext() ? i.next() : null;

        while( qual_it != null )
        {
            // accumulate namespaces for names that point to the same slot

            int slot_index;
            Slot slot;
            namespaces.clear()// new multiname

            var_index = -1;

            ObjectValue ns = qual_it.getKey();
            slot_index = obj.getSlotIndex(cx,GET_TOKEN,name,ns);
            slot  = obj.getSlot(cx,slot_index);
            var_index = slot.getVarIndex()+bui.var_offset+1 /*zero is special*/;

            if( slot.declaredBy != obj ) // if it is inherited, then skip it
            {
                qual_it = i.hasNext() ? i.next() : null;
                continue;
            }

      /*

      Get the api version the binding was introduced and mark the
      namespace with that version.

      */

            while( true )
            {
                if( ns != null )
                {
                    int ns_index;
          if (doingAPIVersioning) {
            TreeSet<Integer> versions = apiVersionsOfSlot(slot, name, ns);
            ns_index = makeVersionedNamespaceSet(ns, versions);
          }
          else {
            ns_index = addNamespace(ns);
          }
          namespaces.add(ns_index);
                }
                else
                {
                    cx.internalError(pos, "internal error: non object value for namespace");
                }

                qual_it = i.hasNext() ? i.next() : null;
                if( qual_it == null )
                {
                    break;
                }

                prev_var_index = var_index;
                prev_slot = slot;

                ns = qual_it.getKey();
                slot_index = obj.getSlotIndex(cx,GET_TOKEN,name,ns);
                if(slot_index <= 0)
                  continue;
                slot  = obj.getSlot(cx,slot_index);
                var_index = slot.getVarIndex()+bui.var_offset+1// zero is special
                flags &= slot.isFinal() ?TRAIT_FLAG_final:0/*virtual*/;
                flags &= slot.isOverride() ?TRAIT_FLAG_override:0/*new*/;

                if( var_index < 0 || var_index != prev_var_index || slot.declaredBy != prev_slot.declaredBy )
                {
                    var_index = prev_var_index;
                    slot = prev_slot;
                    break; // not an alias of the previous name
                }
            }

            int name_index  = ab.addUtf8Constant(bytecodeFactory.ConstantUtf8Info(name));
            int qname_index;

      if (doingAPIVersioning) {
        qname_index = ab.addMultiNameConstant(bytecodeFactory.ConstantMultiname(name_index,namespaces.back(),false));
      }
      else {
        qname_index = ab.addMultiNameConstant(bytecodeFactory.ConstantQualifiedName(name_index,namespaces.back(),false));
      }

            // Using the last namespace, get the slot for the name

            ObjectValue objval = slot.getInitializerValue();
            int value_index = 0;
            byte value_kind = 0;
            int kind;
            int info;
            if( objval != null && ((objval.builder instanceof ClassBuilder) ? objval.builder : null) != null )
            {
                kind = TRAIT_Class;
                info = GetClassInfo(objval.builder.classname);
            }
//#if 0  // ISSUE: this almost works, but the compiler needs to be smarter about multiple definitions
//            else
//            if( objval && dynamic_cast<FunctionBuilder*>(objval->builder) )
//            {
//                kind = TRAIT_Function;
//                info = GetMethodInfo(objval->name);
//            }
//#endif
            else
            {
                kind = slot.isConst() ? TRAIT_Const : TRAIT_Var;

                if( objval != null )
                {
                    value_index = getValueIndex(objval);
                    value_kind = getValueKind(objval);
                }

                {
                    QName type_name = slot.getType().getName(cx); //slot->type->name;
                    info = addClassName(type_name);
                }

            }

            IntList  metaDataIndices = addMetadata(slot);
            traits.push_back(allocBytes());
            ab.addBytesToTable(traits,bytecodeFactory.TraitInfo(traits.back(),qname_index,kind, obj.canEarlyBind() ? var_index : 0,info,value_index,value_kind,metaDataIndices));
        }
    }
View Full Code Here

        }
        return null;
    }
    protected IntList addMetadata(ArrayList<MetaData> metadata)
    {
        IntList metaDataIndices = null;
        if( metadata != null && metadata.size() > 0 )
        {
            metaDataIndices = new IntList(metadata.size());
            Iterator<MetaData> it = metadata.iterator();
            while( it.hasNext() )
            {
                MetaData entry = it.next();
                String id = entry.id;
                Value[] values = entry.values;
                int metaDataIndex = addMetadataInfo(id, values) ;
                metaDataIndices.add(metaDataIndex);
            }
        }
        return metaDataIndices;
    }
View Full Code Here

    {
        String metaDataKey = id;

        int metaNameIndex = id == null ? 0 : ab.addUtf8Constant(bytecodeFactory.ConstantUtf8Info(id));
        int metaValuesCount = values == null ? 0 : values.length;
        IntList metaKeys = new IntList(metaValuesCount);
        IntList metaValues = new IntList(metaValuesCount);
        for( int z = 0; z < metaValuesCount; ++z )
        {
            Value val = values[z];
            String key = null;
            String value = null;
            if( val instanceof MetaDataEvaluator.KeylessValue )
            {
                key = null;
                value = ((MetaDataEvaluator.KeylessValue)val).obj;
            }
            else if( val instanceof MetaDataEvaluator.KeyValuePair )
            {
                MetaDataEvaluator.KeyValuePair pair = (MetaDataEvaluator.KeyValuePair)val;
                key = pair.key;
                value = pair.obj;
            }
            else
            {
                value = val.toString();
            }
            if( key != null )
            {
                metaKeys.add(ab.addUtf8Constant(bytecodeFactory.ConstantUtf8Info(key)));
                metaDataKey += key;
            }
            else
            {
                metaKeys.add(0);
            }
            metaDataKey += value;
            metaValues.add(ab.addUtf8Constant(bytecodeFactory.ConstantUtf8Info(value)));
        }
        int metaDataIndex = GetMetadataInfo(metaDataKey);
        if ( ab.metadata.at(metaDataIndex).size() == 0 )
        {
            // Only add the bytes if they weren't added by a previous trait.  Multiple traits can refer to the
View Full Code Here

        if( "$construct".equals(name) )
        {
            return// ISSUE: experiment. don't define traits for constructors
        }
       
        IntList namespaces = new IntList(quals.size())// will be (*it)->namespaces

        Iterator<ObjectValue> i = quals.keySet().iterator();       

        boolean isInterface = (obj.type != null && obj.type.isInterface());
    
        while (i.hasNext())
        {
            ObjectValue ns = i.next();

            int slot_kind = kind==TRAIT_Setter?SET_TOKEN:GET_TOKEN;

            int slot_index = obj.getSlotIndex(cx,slot_kind,name,ns);
            Slot slot  = obj.getSlot(cx,slot_index);
         
            if( kind == TRAIT_Method )
            {
                int implicit_index = obj.getImplicitIndex(cx,slot_index,EMPTY_TOKEN);
                slot = obj.getSlot(cx,implicit_index);
            }

            if( slot == null || slot.declaredBy != obj || slot.getMethodName().length() == 0 ) // this happens with internal accessors, that are not traits
            {
                continue;
           
           
            ObjectValue slot_value = slot != null? (slot.getValue() instanceof ObjectValue ? (ObjectValue) slot.getValue() : null) : null;
            ArrayList<MetaData> metaData = slot.getMetadata();
           
            // If a name is interface-qualified, emit the trait only if the traits
            // are for an interface definition.  In a class, the VM will automatically
            // add the interface-qualified traits when it sees the public method definition.
            if (!isInterface && ns.isInterface())
            {
                continue;
            }

            boolean is_override = slot.isOverride();
                   
            int flags = 0; // final/virtual & 1, override/new & 2
            flags |= slot.isFinal() ?TRAIT_FLAG_final:0/*virtual*/;
            flags |= is_override?TRAIT_FLAG_override:0/*new*/;

            if( ns != null )
            {
                int ns_index;
        if (doingAPIVersioning) {
          TreeSet<Integer> versions = apiVersionsOfSlot(slot, name, ns);
          ns_index = makeVersionedNamespaceSet(ns, versions);
        }
        else {
          ns_index = addNamespace(ns);
        }
        namespaces.add(ns_index);
            }
            else
            {
                cx.internalError(pos, "internal error: non object value for namespace");
            }

            int method_info = -1;
            int method_id = slot.getMethodID();
            if( method_id >= 0 )
            {       // method
                method_info = GetMethodInfo(slot.getMethodName());
            }
            else
            if( slot_value != null && slot_value.method_info >= 0 )
            {       // function
                method_info = slot_value.method_info;
            }
            else
            {
                cx.internalError("internal error");
                continue;
            }

            int name_index  = ab.addUtf8Constant(bytecodeFactory.ConstantUtf8Info(name));

      int qname_index;
      if (doingAPIVersioning) {
        qname_index = ab.addMultiNameConstant(bytecodeFactory.ConstantMultiname(name_index,namespaces.back(),false));
      }
      else {
        qname_index = ab.addMultiNameConstant(bytecodeFactory.ConstantQualifiedName(name_index,namespaces.back(),false));
      }

            IntList  metaDataIndices = addMetadata(metaData);

            if( method_info >= 0 )
            {
                traits.push_back(allocBytes());
                method_id = method_id<0?0:method_id; // ISSUE: normalize -1 to 0. refactor to make rest of compiler use 0
View Full Code Here

        flushDebugInfo();       

        last_in = IKIND_other;

        IntList fixups = exceptionBlocks.last().finallyAddrs;
        if (fixups.size() > 0)
        {
            int start = getIP();
            Lookupswitch(ab.code)// rework to fit avm+ semantics
   
            // This will be fixed up with end of switch
            Int24(ab.code, 0);
           
              Int(ab.code, fixups.size() - 1);
             
            for (int i = 0, n=fixups.size(); i < n; ++i)
            {
                Int24(ab.code, fixups.get(i) - start);
            }
           
            // Fixup default to jump to here
            int offset = getIP() - start;
            ab.code.set(start+1, (byte) offset);
View Full Code Here

     *
     */

    protected void LabelStatementBegin()
    {
        break_addrs.add(new IntList());
        break_scope_depth.add(cx.getScopeDepth());
        break_temp_count.add(cur_locals);

        // These will never be used, but add because the loop_index for continues
        // as well as breaks were calculated with the LabelStatement incrementing the loop_index
        // so if we don't add these, we get badness later.
        continue_addrs.add(new IntList());
        continue_scope_depth.add(cx.getScopeDepth());
    }
View Full Code Here

            code_out.print("LoopBegin");
        }

        //flushDebugInfo();  Don't flush the debug info - let the first statement in the loop take care of that so the debugging info will be hit on each interation of the loop.
       
        break_addrs.add(new IntList());
        break_scope_depth.add(cx.getScopeDepth());
        break_temp_count.add(cur_locals);
       
        continue_addrs.add(new IntList());
        continue_scope_depth.add(cx.getScopeDepth());
       
        Jump(ab.code);
        loopbegin_addrs.add(getIP() - 3);
View Full Code Here

        flushDebugInfo();       

        // ASSERT(loop_index==break_addrs.size()-1);

        int target = getIP();
        IntList break_addr = break_addrs.removeLast();
        while (break_addr.size() != 0)
        {
            int break_index = break_addr.removeLast();
            int offset = target - break_index + 1 - 4;

            if (bytecodeFactory.show_bytecode)
            {
                code_out.println();
View Full Code Here

        flushDebugInfo();       

        // ASSERT(loop_index==continue_addrs.size()-1);

        int target = getIP();
        IntList continue_addr = continue_addrs.removeLast();
        while (continue_addr.size() != 0)
        {
            int continue_index = continue_addr.removeLast();
            int offset = target - continue_index + 1 - 4;

            if (bytecodeFactory.show_bytecode)
            {
                code_out.println();
View Full Code Here

TOP

Related Classes of macromedia.asc.util.IntList

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.