Beispiel #1
0
 internal override Executable ResolveWithTypeContext(PastelCompiler compiler)
 {
     this.Condition = this.Condition.ResolveWithTypeContext(compiler);
     for (int i = 0; i < this.Chunks.Length; ++i)
     {
         SwitchChunk chunk = this.Chunks[i];
         for (int j = 0; j < chunk.Cases.Length; ++j)
         {
             if (chunk.Cases[j] != null)
             {
                 chunk.Cases[j] = chunk.Cases[j].ResolveWithTypeContext(compiler);
             }
         }
         Executable.ResolveWithTypeContext(compiler, chunk.Code);
     }
     return(this);
 }
Beispiel #2
0
        internal override Executable ResolveWithTypeContext(PastelCompiler compiler)
        {
            Executable.ResolveWithTypeContext(compiler, this.InitCode);
            this.Condition = this.Condition.ResolveWithTypeContext(compiler);
            Executable.ResolveWithTypeContext(compiler, this.StepCode);
            Executable.ResolveWithTypeContext(compiler, this.Code);

            // Canonialize the for loop into a while loop.
            List <Executable> loopCode = new List <Executable>(this.Code);

            loopCode.AddRange(this.StepCode);
            WhileLoop whileLoop = new WhileLoop(this.FirstToken, this.Condition, loopCode);

            loopCode = new List <Executable>(this.InitCode);
            loopCode.Add(whileLoop);
            return(new ExecutableBatch(this.FirstToken, loopCode));
        }
Beispiel #3
0
        internal override Executable ResolveWithTypeContext(PastelCompiler compiler)
        {
            this.Condition = this.Condition.ResolveWithTypeContext(compiler);
            Executable.ResolveWithTypeContext(compiler, this.IfCode);
            if (this.ElseCode.Length > 0)
            {
                Executable.ResolveWithTypeContext(compiler, this.ElseCode);
            }

            if (this.Condition is InlineConstant)
            {
                bool condition = (bool)((InlineConstant)this.Condition).Value;
                return(new ExecutableBatch(this.FirstToken, condition ? this.IfCode : this.ElseCode));
            }

            return(this);
        }
Beispiel #4
0
        internal override Executable ResolveWithTypeContext(PastelCompiler compiler)
        {
            this.Condition = this.Condition.ResolveWithTypeContext(compiler);
            HashSet <int> values = new HashSet <int>();

            for (int i = 0; i < this.Chunks.Length; ++i)
            {
                SwitchChunk chunk = this.Chunks[i];
                for (int j = 0; j < chunk.Cases.Length; ++j)
                {
                    if (chunk.Cases[j] != null)
                    {
                        chunk.Cases[j] = chunk.Cases[j].ResolveWithTypeContext(compiler);
                        InlineConstant ic = chunk.Cases[j] as InlineConstant;
                        if (ic == null)
                        {
                            throw new ParserException(chunk.Cases[j].FirstToken, "Only constants may be used as switch cases.");
                        }
                        int value;
                        if (ic.ResolvedType.RootValue == "char")
                        {
                            value = (char)ic.Value;
                        }
                        else
                        {
                            value = (int)ic.Value;
                        }
                        if (values.Contains(value))
                        {
                            throw new ParserException(chunk.Cases[j].FirstToken, "This cases appears multiple times.");
                        }
                        values.Add(value);
                    }
                }
                Executable.ResolveWithTypeContext(compiler, chunk.Code);
            }
            return(this);
        }
 public void ResolveWithTypeContext(PastelCompiler compiler)
 {
     Executable.ResolveWithTypeContext(compiler, this.Code);
 }
Beispiel #6
0
 internal override Executable ResolveWithTypeContext(PastelCompiler compiler)
 {
     this.Condition = this.Condition.ResolveWithTypeContext(compiler);
     Executable.ResolveWithTypeContext(compiler, this.Code);
     return(this);
 }
Beispiel #7
0
 internal override Executable ResolveWithTypeContext(PastelCompiler compiler)
 {
     Executable.ResolveWithTypeContext(compiler, this.Executables);
     return(this);
 }