Package macromedia.asc.util

Examples of macromedia.asc.util.Context


        ProgramNode program = (ProgramNode) ascUnit.getSyntaxTree();
        ClassDefinitionNode classDefinitionNode = getFirstClassDefinition(program);
        assert classDefinitionNode != null : "could not find a class definition node...";

        CompilerContext context = ascUnit.getContext();
        Context cx = context.getAscContext();

        TypeAnalyzer typeAnalyzer = symbolTable.getTypeAnalyzer();

        program.evaluate(cx, typeAnalyzer);
View Full Code Here


      }
    }

    if (!(do_help || filespecFound))
    {
            Context cx = new Context(new ContextStatics());

      System.err.println(cx.errorString(ErrorConstants.kError_MissingFilespec));
      System.exit(1);
    }
    else if (do_help)
    {
      handleFile("","");
View Full Code Here

    else
    {
      File f = new File(filename.trim());
      if (!f.exists())
      {
                Context cx = new Context(new ContextStatics());
        StringBuilder error_msg = new StringBuilder();
        Context.replaceStringArg(error_msg, cx
            .errorString(ErrorConstants.kError_UnableToOpenFile),
            0, filename);
        System.err.println(error_msg.toString());
        return;
      }
View Full Code Here

        if (debug)
        {
            System.out.print("\n// +FunctionCommonNode");
        }

        Context cx = node.cx; // switch to original context

  // getQualifiedErrorOrigin defaults to getErrorOrigin if
  // the qualified_origin isn't set - this is used to prevent
  // naming conflicts in the debug info for authoring (i.e.,
  // multiple scripts with the name "frame1"
        setOrigin(cx.getQualifiedErrorOrigin());

        if (cx.input != null)
        {
            setPosition(cx.input.getLnNum(node.pos()),cx.input.getColPos(node.pos()),node.pos());
        }

        if (doingMethod())
        {
            boolean anon_with_identifier = node.isNamedInnerFunc();
            if( anon_with_identifier )
            {
                NewObject(0);
                PushWith();
            }
            NewFunctionObject(node.internal_name);
           
            if( anon_with_identifier )
            {
                if ( !node.isVoidResult() ) {
                    Dup();
                }
                GetBaseObject(cx.getScopeDepth()-frame.firstInnerScope);
                Swap();
                SetProperty(node.identifier.name, new Namespaces(cx.publicNamespace()), true, false, false, false);
                PopScope();
            }
            else
            if ( node.isVoidResult() ) {
                Pop();
            }

            return null// defer until the current method is done.
        }

        int savedWithDepth = cx.statics.withDepth;
        if( node.with_depth != -1)
        {
            // FCN was hoisted by an earlier pass
            cx.statics.withDepth = node.with_depth;
        }

        ObjectList<ObjectValue>saved_scopes = null;
        if( node.scope_chain != null )
        {
            saved_scopes = cx.swapScopeChain(node.scope_chain);
        }

        Slot getSlot = node.ref.getSlot(cx, GET_TOKEN);
        Slot setSlot = node.ref.getSlot(cx, SET_TOKEN);
        boolean with_this = getSlot instanceof MethodSlot || setSlot instanceof MethodSlot;

        ObjectValue fun = node.fun;
        cx.pushScope(fun.activation);

        // Do nested functions
        boolean needs_activation = false;

        if( node.fexprs.size() > 0 )
        {
            needs_activation = true;
        }
        if (node.isWithUsed())
        {
                needs_activation = true;
        }
        if (node.isExceptionsUsed())
        {
                needs_activation = true;
        }

/*
        for (int i = (node.fexprs == null) ? -1 : node.fexprs.size() - 1; i >= 0; i--)
        {
            Node fexpr = node.fexprs.get(i);
            fexpr.evaluate(cx, this);
        }
*/

        used_namespaces_sets.push_back(node.used_namespaces);

        for (FunctionCommonNode def : node.fexprs)
        {
            def.evaluate(cx, this);
        }

        // reset debug position.  nested Function evaulation above will have updated it, we need to reset to top of this function.
        if (cx.input != null)
        {
            setPosition(cx.input.getLnNum(node.pos()),cx.input.getColPos(node.pos()),node.pos());
        }

        pushStackFrame();

        frame.functionName = node.internal_name;
        frame.maxParams = node.signature.size();
        frame.maxLocals = node.body != null ? node.var_count : 0;
        frame.maxTemps = node.body != null ? node.temp_count : 0;
        frame.needsArguments = node.needsArguments;

        frame.withThis = with_this;

        frame.firstInnerScope = cx.getScopes().size()-1;
        if (with_this)
        {
            frame.firstInnerScope--;
        }

        // If there are nested functions, this will be true
        frame.activationIsExposed = needs_activation;
        frame.registerScopeIndex = needs_activation ? -1 : (cx.getScopes().size()-1);

        StartMethod(frame.functionName,frame.maxParams,frame.maxLocals,0,needs_activation,node.needsArguments);

        // If this is a constructor, then insert a call to the base constructor,
        // and the instance initializer

        if( "$construct".equals(node.ref.name) && cx.statics.es4_nullability  )
        {
          // Must run property initializers before this, or activation scope is pushed.  Setting properties
          // will be handled with getlocal0, setproperty and arguments will use getlocal since there can be no intervening
          // scopes at this point (even if the method later needs an activation object)
            doCtorSetup(node, cx, needs_activation);
        }
        if (with_this)
        {
            LoadThis();
            PushScope();
        }

        // initialize local variables that are in registers.

        ObjectValue activation = node.fun.activation;
        int firstlocal = node.signature.size();
        if (node.needsArguments != 0)
        {
            firstlocal++;
        }
        int reg_offset = activation.builder.reg_offset;
        int var_offset = activation.builder.var_offset;

        if (needs_activation)
        {
            NewActivation();
            int temp_activation_reg = allocateTemp();
            activation.builder.temp_reg = temp_activation_reg;
            Dup();
            StoreRegister(reg_offset+temp_activation_reg,TYPE_none);
            PushScope();

      // create a 'local' name for the activation object for the debugger to use
      DefineSlotVariable(cx, node.internal_name, node.debug_name, node.pos(), ObjectValue.objectPrototype.type, temp_activation_reg);
        }

        if (activation.slots != null)
        {
            int base_offset = needs_activation ? var_offset : reg_offset;

            for (Slot s: activation.slots)
            {
                int index = base_offset + s.getVarIndex();
                if ( s.needsInit() &&  s.getVarIndex() >= firstlocal)
                {
                    StoreDefaultValue(cx, index, s, needs_activation);
                }
            }
        }

        if (needs_activation)
        {
            // Copy the arguments into the activation object
            int n=frame.maxParams;
            if (node.needsArguments != 0) n++;
            for (int i=0; i<n; i++)
            {
                GetActivationObject(cx.getScopes().size()-1);
                LoadRegister(i+1,TYPE_object);
                StoreVar(i);
            }
        }

        // for debug purposes dump out the list of args
        ParameterListNode parms = node.signature.parameter;
        String[] arg_names = null;
    if (parms != null)
    {
            arg_names = new String[parms.items.size()];
      for(int i = 0; i < parms.items.size(); ++i )
            {
                ParameterNode parm = parms.items.at(i);
        ReferenceValue ref;
        Slot slot;
        if (parm == null)
          ; // no good
        else if ((ref = parm.ref) == null)
          ; // no good
        else if ((slot = ref.getSlot(cx)) == null)
          ; // no good
        else
        {
          TypeInfo expr_type = ref.getType(cx);
          DefineSlotVariable(cx, ref.name, ref.name, pos, expr_type, slot.getVarIndex());
                    arg_names[i] = ref.name;
        }
      }
    }

        if( "$construct".equals(node.ref.name) && !cx.statics.es4_nullability  )
        {
            doCtorSetup(node, cx, needs_activation);
        }

        if( node.body != null)
        {
            if( node.default_dxns != null )
            {
                node.default_dxns.evaluate(cx,this);
            }
            boolean old_in_anonymous_function = this.in_anonymous_function;
            this.in_anonymous_function = (node.isFunctionDefinition() == false); // set flag if we are processing an anonymous function
            node.body.evaluate(cx,this);
            this.in_anonymous_function = old_in_anonymous_function;
        }

        if (cx.input != null)
        {
            setPosition(cx.input.getLnNum(node.signature.pos()),cx.input.getColPos(node.signature.pos()),node.signature.pos());
        }

        // If there is a nested function, then pass the activation object so traits can be emitted
        if (!needs_activation)
            activation = null;
            // ISSUE: this logic can be more subtle. We also might need the activation
            // if there is an embedded eval or with. And we might not need the activation
            // object for all functions with nested functions

    int scope_depth = activation != null ? cx.getScopes().size() : cx.getScopes().size()-1;
    TypeInfo type = node.signature.type;
    ObjectList<TypeInfo> types = node.signature.parameter!=null?node.signature.parameter.types:null;
    node.fun.method_info = FinishMethod(cx,
        frame.functionName,
        type,
        types,
        activation,
        node.needsArguments,
        scope_depth,
        node.debug_name,
        node.isNative(),
        (currentClass instanceof InterfaceDefinitionNode),
                arg_names);

        cx.popScope();
        this.is_ctor = false;
        // We don't need this or the activation builder anymore
        node.fun.activation = null;
        // don't need the FunctionBuilder anymore either
        node.fun.builder = null;
       
        popStackFrame();

        if( saved_scopes != null )
        {
            cx.swapScopeChain(saved_scopes);
        }
        cx.statics.withDepth = savedWithDepth;

        // Call code is compiled as though register 0 is the scope
        // stack, register 1 is the current object, register 2 is the
View Full Code Here

        if (node.attrs != null && node.attrs.hasIntrinsic)
        {
            return null;
        }

        Context cx = node.cx; // switch to original context

        setOrigin(cx.getErrorOrigin());

        if (doingMethod() || doingClass())
        {
            if( node.needs_init )
            {
                ClassDefinitionNode baseClassNode = cx.scope().getDeferredClassMap().get(node.cframe.baseclass);
                if (baseClassNode != null && baseClassNode.needs_init)
                {
                    if (node.name.name.equals("Object") &&
                        baseClassNode.name.name.equals("Class"))
                    {
                        // special case.  do not defer in this case.
                    }
                    else
                    {
                        if (baseClassNode.deferred_subclasses == null)
                        {
                            baseClassNode.deferred_subclasses = new ObjectList<ClassDefinitionNode>();
                        }
                        cx.error(node.baseclass.pos(), kError_ForwardReferenceToBaseClass,baseClassNode.name.name);
                        baseClassNode.deferred_subclasses.add(node);
                        return null;
                    }
                }

                node.needs_init = false;
                node.init.evaluate(cx,this);

                // Initiailize any subclasses that were deferred
                if (node.deferred_subclasses != null)
                {
                    for (Node n : node.deferred_subclasses)
                    {
                        n.evaluate(cx, this);
                    }
                    node.deferred_subclasses = null;
                }

                return null;
            }

            int popCount = 0;

            if( node.baseclass != null)
            {
                // Must push scopes for base classes
                TypeValue cframe = node.cframe;
                popCount = pushStaticScopesHelper(cx, cframe.baseclass);

                node.baseclass.evaluate(cx,this);
            }
            else
            {
                PushNull();
            }
            NewClassObject(node.cframe.builder.classname);

            for (int i=0; i<popCount; i++)
            {
                PopScope();
            }

            return null;
        }

        if( node.pkgdef != null && cx.getScopes().size() == 1 )
        {
            used_namespaces_sets.push_back(node.pkgdef.used_namespaces);
        }

        used_namespaces_sets.push_back(node.used_namespaces);

        /*
         * Interface initializer
         *
         * The class initializer gets the static properties of the class definition.
         */

        cx.pushStaticClassScopes(node);

        {
            // generate nested classes before the outer class
            for (ClassDefinitionNode clsdef : node.clsdefs)
            {
                clsdef.evaluate(cx, this);
                cx.scope().getDeferredClassMap().put(clsdef.cframe,clsdef);
            }
        }

        currentClass = node;

        StartClass(node.ref.name);

        {
            pushStackFrame();

            frame.functionName = node.cframe.builder.classname+"$cinit";
            frame.maxParams = 0;
            frame.maxLocals = 0/*node->var_count*/; // ISSUE: always 0?
            frame.maxTemps = node.temp_count;
            frame.activationIsExposed = false;
            frame.withThis = true;
            frame.firstInnerScope = cx.getScopes().size()-1;
            frame.registerScopeIndex = -1;

            // Generate code for the class and instance initializers.

            StartMethod(frame.functionName, frame.maxParams, frame.maxLocals);

            LoadThis();
            PushScope();

            ClassBuilder bui = (node.cframe.builder instanceof ClassBuilder) ? (ClassBuilder) node.cframe.builder : null;
            if( bui == null )
            {
                cx.internalError("internal error: invalid class builder");
            }

            NewNamespace(node.private_namespace);

            if (node.statements != null)
            {
                node.statements.evaluate(cx, this);
            }

            clearPositionInfo();
            setPosition(0, 0, 0);
            Return(TYPE_void);

      TypeInfo type = null;
      ObjectList<TypeInfo> types = null;
      FinishMethod(cx,frame.functionName,type,types,null/*node->cframe*/,0,cx.getScopes().size(),"",false,false, null);

            {
                for (FunctionCommonNode expr : node.staticfexprs)
                {
                    expr.evaluate(cx, this);
                }
            }

            popStackFrame();
        }

        /*
         * Prototype initializer
         *
         * The prototype initializer sets up the prototype object with the
         * getter and setters for its children.
         */

        cx.pushScope(node.iframe);

        /*{
            fun_name_stack.add(node.iframe.builder.classname + "$iinit");
            max_params_stack.add(0);
            max_locals_stack.add(node.var_count + 1);// ? why +1
            max_temps_stack.add(node.temp_count);

            activation_is_exposed_stack.add(0); // registers not used

            StartMethod(fun_name_stack.last(), max_params_stack.last(), max_locals_stack.last());

            // Generate code for the class and instance initializers.

            // ISSUE: use istmts to capture the instance initializers

            if (node.statements != null)
            {
                node.statements.evaluate(cx, this);
            }

            int scope_depth = cx.getScopes().size() - 1;

            GetBaseObject(scope_depth);
            Return(TYPE_none);
            setPosition(0, 0, 0);

            {
                // $iinit is nested in the constructor and uses the same scope chain as the
                // constructor, so the net scope_depth is zero.
                int scope_depth2 = cx.getScopes().size();
                TypeValue type = node.iframe.type;//make the initializer return type be the object type
                ObjectList<TypeValue> types = null;
                FinishMethod(cx,fun_name_stack.back(),type,types,null,0,scope_depth2,"",false);
            }

            fun_name_stack.removeLast();
            max_params_stack.removeLast();
            max_locals_stack.removeLast();
            max_temps_stack.removeLast();
            activation_is_exposed_stack.removeLast();
        }*/

        /*
         * User defined methods
         */

        for (ListIterator<FunctionCommonNode> it = node.fexprs.listIterator(); it.hasNext(); )
        {
            it.next().evaluate(cx,this);
        }

        boolean is_dynamic = node.attrs != null ? node.attrs.hasDynamic : false;
        boolean is_final = node.attrs != null ? node.attrs.hasFinal : false;

        QName basename = null;
        if( node.cframe.baseclass != null)
        {
            basename = node.cframe.baseclass.builder.classname;
            if ( basename.name.equals("Class") )
                basename = null;
        }
        FinishClass(cx,node.cframe.builder.classname/*node->ref->name*/,basename,is_dynamic, is_final, false, node.cframe.is_nullable);
        cx.popScope()// iframe
        cx.popStaticClassScopes(node);

        used_namespaces_sets.pop_back();

        if( node.pkgdef != null && cx.getScopes().size() == 1 )
        {
            used_namespaces_sets.pop_back();
        }

        if (debug)
View Full Code Here

    public Value evaluate(Context cx, IncludeDirectiveNode node)
    {
        if( !node.in_this_include )
        {
            node.in_this_include = true;
            node.prev_cx = new Context(cx.statics);
            node.prev_cx.switchToContext(cx);

            // DANGER: it may not be obvious that we are setting the
            // the context of the outer statementlistnode here
            cx.switchToContext(node.cx);
View Full Code Here

              }
            }
          }
        }

        context = new Context(context.statics);
        context.setPath("");
        context.setScriptName(generatedName);
        context.setHandler(new flex2.compiler.as3.As3Compiler.CompilerHandler());
        context.statics.handler = context.getHandler();
View Full Code Here

                  namespaces                  = new HashSet<String>();

        final Map<QName, Map<String, Source>> dependents = new HashMap<QName, Map<String, Source>>();

        Set<Source> swcSources = swcContext.cachedSources();
        Context ascContext = null;

        if (perCompileData != null)
        {
            ascContext = new Context(perCompileData);
        }

        // put all the Source objects together
        final Set<Source> sources = new HashSet<Source>();
        {
            sources.addAll(swcSources);
            if (fileSpec != null)
                sources.addAll(fileSpec.sources());
            if (sourceList != null)
                sources.addAll(sourceList.sources().values());
            if (sourcePath != null)
                sources.addAll(sourcePath.sources().values());
            if (bundlePath != null)
                sources.addAll(bundlePath.sources().values());
            if (includedClasses != null)
                sources.addAll(includedClasses.values());
        }

        // build a dependency graph
        for (Source source : sources)
        {
            if (source.getName() == null)
            {
                continue;
            }

            CompilationUnit u = source.getCompilationUnit();

            if (u == null)
            {
                continue;
            }

            // collect the names of all the update file includes...
            for (Iterator j = source.getUpdatedFileIncludes(); j != null && j.hasNext();)
            {
                VirtualFile f = (VirtualFile) j.next();
                includeUpdated.add(f.getNameForReporting());
            }

            // register QName --> VirtualFile.getName()
            for (QName qName : u.topLevelDefinitions)
            {
                qNames.put(qName, source);
                dependents.put(qName, new HashMap<String, Source>());
            }
        }

        for (Source source : resources.sources().values())
        {
            if (source.getName() == null)
            {
                continue;
            }

            CompilationUnit u = source.getCompilationUnit();

            if (u == null)
            {
                continue;
            }

            // register QName --> VirtualFile.getName()
            for (QName qName : u.topLevelDefinitions)
            {
                qNames.put(qName, source);
            }
        }

        // setup inheritance-based dependencies...
        for (Source source : sources)
        {
            if (source == null) continue;

            CompilationUnit u = source.getCompilationUnit();
            if (u == null) continue;

            addDependents(source, u.inheritance, dependents);
            addDependents(source, u.namespaces, dependents);
            addDependents(source, u.types, dependents);
            addDependents(source, u.expressions, dependents);
        }

        Logger logger = ThreadLocalToolkit.getLogger();

        // if any of the Source objects in ResourceContainer is bad, obsolete the originating Source.
        for (Source source : resources.sources().values())
        {
            CompilationUnit u = source.getCompilationUnit();
            if (source.hasError() ||
                (u != null && !u.isDone() && !u.hasTypeInfo) ||
                source.isUpdated() ||
                (u != null && u.hasAssets() && u.getAssets().isUpdated()))
            {
                resourceDelegates.add(source.getNameForReporting());
                source.removeCompilationUnit();
            }
        }

        reportObsoletedSwcSources(swcContext, l10n, logger);
        reportShadowedSwcSources(swcSources, sourceList, sourcePath, resources, l10n, logger, sources);

        // identify obsolete CompilationUnit
        //   - NotFullyCompiled
        //   - SourceNoLongerExists
        //   - SourceFileUpdated
        //   - AssedUpdated
        for (Iterator<Source> iterator = sources.iterator(); iterator.hasNext();)
        {
            Source s = iterator.next();
            CompilationUnit u = s.getCompilationUnit();

            // Sources for internal classes like Object never reach the done state or have typeInfo.
            if (s.hasError() ||
                (!s.isInternal() && (u != null && !u.isDone() && !u.hasTypeInfo)) ||
                resourceDelegates.contains(s.getName()))
            {
                affected.put(s.getName(), s);
                reasons.put(s.getName(), l10n.getLocalizedTextString(new NotFullyCompiled()));
                iterator.remove();
            }
            else if (!s.exists())
            {
                updated.put(s.getName(), s);
                reasons.put(s.getName(), l10n.getLocalizedTextString(new SourceNoLongerExists()));

                if (u != null)
                {
                    for (QName qName : u.topLevelDefinitions)
                    {
                        namespaces.add(qName.toString());
                        deleted.put(qName, s);
                    }
                }

                iterator.remove();
            }
            else if (s.isUpdated())
            {
                // signature optimization:
                //     read the old signature from the incremental cache
                //     generate a new signature from the current source
                //     compare -- if stable, we don't have to recompile dependencies
                boolean signatureIsStable = false;
                if ((u != null) &&
                    (!configuration.getCompilerConfiguration().getDisableIncrementalOptimizations()) &&
                    // skip MXML sources:
                    //      MXML is too complicated to parse/codegen at this point in
                    //      order to generate and compare a new checksum
                    (!s.getMimeType().equals(MimeMappings.MXML)))
                {
                    final Long persistedCRC = u.getSignatureChecksum();
                    if (persistedCRC != null)
                    {
                        assert (s.getMimeType().equals(MimeMappings.ABC) ||
                                s.getMimeType().equals(MimeMappings.AS));

                        //TODO if we calculate a new checksum that does not match,
                        //     can we store this checksum and not recompute it later?
                        final Long currentCRC = computeSignatureChecksum(configuration, s);
                        signatureIsStable = (currentCRC != null) &&
                                            (persistedCRC.compareTo(currentCRC) == 0);

                        // if (SignatureExtension.debug)
                        // {
                        //     final String name = u.getSource().getName();
                        //     SignatureExtension.debug("*** FILE UPDATED: Signature "
                        //                                    + (signatureIsStable ? "IS" : "IS NOT")
                        //                                    + " stable ***");
                        //     SignatureExtension.debug("PERSISTED CRC32: " + persistedCRC + "\t--> " + name);
                        //     SignatureExtension.debug("CURRENT   CRC32: " + currentCRC   + "\t--> " + name);
                        // }
                    }
                }

                // if the class signature is stable (it has not changed since the last compile)
                // then we can invalidate and recompile the updated unit alone
                // otherwise we default to a chain reaction, invalidating _all_ dependent units
                if (signatureIsStable)
                {
                    updatedWithStableSignature.put(s.getName(), s);
                }
                else
                {
                    updated.put(s.getName(), s);
                }

                reasons.put(s.getName(), l10n.getLocalizedTextString(new SourceFileUpdated()));
                iterator.remove();
            }
            else if (u != null && u.hasAssets() && u.getAssets().isUpdated())
            {
                updated.put(s.getName(), s);
                reasons.put(s.getName(), l10n.getLocalizedTextString(new AssetUpdated()));
                iterator.remove();
            }
        }

        // permanently remove the deleted Source objects from SourcePath
        //
        // Note: this step is currently necessary because the location-updating loop that follows iterates over
        // 'sources', which has had deleted entries remove. So here we iterate directly over the deleted
        // entries. (Note also that 'reasons' already has an entry for this source.)
        //
        for (Source source : deleted.values())
        {
            if (source.isSourcePathOwner())
            {
                SourcePath sp = (SourcePath) source.getOwner();
                sp.removeSource(source);

                if (ascContext != null)
                {
                    CompilationUnit u = source.getCompilationUnit();

                    if (u != null)
                    {
                        for (QName defName : u.topLevelDefinitions)
                        {
                            ascContext.removeUserDefined(defName.toString());
                        }
                    }
                }
            }
        }
View Full Code Here

  public Value evaluate(Context cx, IncludeDirectiveNode node)
  {
        if( !node.in_this_include )
        {
            node.in_this_include = true;
            node.prev_cx = new Context(cx.statics);
            node.prev_cx.switchToContext(cx);

            // DANGER: it may not be obvious that we are setting the
            // the context of the outer statementlistnode here
            cx.switchToContext(node.cx);
View Full Code Here

    }

    public void generate(CompilationUnit compilationUnit, TypeTable typeTable)
    {
        CompilerContext context = compilationUnit.getContext();
        Context cx = context.getAscContext();
        Node node = (Node) compilationUnit.getSyntaxTree();
        DataBindingFirstPassEvaluator dataBindingFirstPassEvaluator =
            new DataBindingFirstPassEvaluator(compilationUnit, typeTable, showBindingWarnings);

        node.evaluate(cx, dataBindingFirstPassEvaluator);
View Full Code Here

TOP

Related Classes of macromedia.asc.util.Context

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.