Example #1
0
        internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase)
        {
            this.Value.ResolveVariableOrigins(parser, varIds, phase);

            if ((phase & VariableIdAllocPhase.REGISTER) != 0)
            {
                bool isVariableAssigned =
                    // A variable is considered declared if the target is a variable and = is used instead of something like +=
                    this.Target is Variable &&
                    this.Op == Ops.EQUALS;

                if (isVariableAssigned)
                {
                    if (this.CompilationScope.IsStaticallyTyped)
                    {
                        if (this.NullableTypeDeclaration != null)
                        {
                            varIds.RegisterVariable(this.NullableTypeDeclaration, this.TargetAsVariable.Name, false);
                        }
                    }
                    else
                    {
                        varIds.RegisterVariable(AType.Any(this.FirstToken), this.TargetAsVariable.Name);
                    }
                }
            }

            this.Target.ResolveVariableOrigins(parser, varIds, phase);
        }
Example #2
0
        internal void ResolveVariableOrigins(ParserContext parser)
        {
            VariableScope varScope = VariableScope.NewEmptyScope(this.CompilationScope.IsStaticallyTyped);

            this.ArgLocalIds = new VariableId[this.ArgNames.Length];
            for (int i = 0; i < this.ArgNames.Length; ++i)
            {
                this.ArgLocalIds[i] = varScope.RegisterVariable(this.ArgTypes[i], this.ArgNames[i].Value);
            }

            foreach (Expression arg in this.BaseArgs)
            {
                arg.ResolveVariableOrigins(parser, varScope, VariableIdAllocPhase.ALLOC);
            }

            foreach (Executable ex in this.Code)
            {
                ex.ResolveVariableOrigins(parser, varScope, VariableIdAllocPhase.REGISTER_AND_ALLOC);
            }

            Lambda.DoVarScopeIdAllocationForLambdaContainer(parser, varScope, this);

            varScope.FinalizeScopeIds();

            this.LocalScopeSize = varScope.Size;
        }
Example #3
0
        internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase)
        {
            this.IterationExpression.ResolveVariableOrigins(parser, varIds, phase);

            if ((phase & VariableIdAllocPhase.REGISTER) != 0)
            {
                varIds.RegisterVariable(this.IterationType, this.IterationVariable.Value);
                this.IndexLocalId = varIds.RegisterSyntheticVariable(AType.Integer(this.FirstToken));
                this.ListLocalId  = varIds.RegisterSyntheticVariable(AType.Any(this.FirstToken));
            }

            if (phase != VariableIdAllocPhase.REGISTER_AND_ALLOC)
            {
                foreach (Executable ex in this.Code)
                {
                    ex.ResolveVariableOrigins(parser, varIds, phase);
                }
            }
            else
            {
                foreach (Executable ex in this.Code)
                {
                    ex.ResolveVariableOrigins(parser, varIds, VariableIdAllocPhase.REGISTER);
                }

                foreach (Executable ex in this.Code)
                {
                    ex.ResolveVariableOrigins(parser, varIds, VariableIdAllocPhase.ALLOC);
                }
            }

            this.IterationVariableId = varIds.GetVarId(this.IterationVariable);
        }
Example #4
0
        internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase)
        {
            foreach (Executable ex in this.TryBlock)
            {
                ex.ResolveVariableOrigins(parser, varIds, phase);
            }

            foreach (CatchBlock cb in this.CatchBlocks)
            {
                if (cb.ExceptionVariableToken != null)
                {
                    if ((phase & VariableIdAllocPhase.REGISTER) != 0)
                    {
                        // TODO: this is a little flawed. Should find the common base class.
                        AType exceptionType = cb.Types.Length == 1
                            ? AType.ProvideRoot(cb.TypeTokens[0], cb.Types[0])
                            : AType.ProvideRoot(cb.CatchToken, "Core.Exception");
                        varIds.RegisterVariable(exceptionType, cb.ExceptionVariableToken.Value);
                    }

                    if ((phase & VariableIdAllocPhase.ALLOC) != 0)
                    {
                        cb.VariableLocalScopeId = varIds.GetVarId(cb.ExceptionVariableToken);
                    }
                }

                foreach (Executable ex in cb.Code)
                {
                    ex.ResolveVariableOrigins(parser, varIds, phase);
                }
            }

            if (this.FinallyBlock != null)
            {
                foreach (Executable ex in this.FinallyBlock)
                {
                    ex.ResolveVariableOrigins(parser, varIds, phase);
                }
            }
        }