Esempio n. 1
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);
        }
Esempio n. 2
0
        internal static IList <Executable> ResolveNamesAndCullUnusedCodeForBlock(IList <Executable> code, PastelCompiler compiler)
        {
            List <Executable> output = new List <Executable>();

            for (int i = 0; i < code.Count; ++i)
            {
                Executable line = code[i].ResolveNamesAndCullUnusedCode(compiler);
                if (line is ExecutableBatch)
                {
                    // ExecutableBatch is always flattened
                    output.AddRange(((ExecutableBatch)line).Executables);
                }
                else
                {
                    output.Add(line);
                }
            }

            for (int i = 0; i < output.Count - 1; i++)
            {
                Executable ex = output[i];
                if (ex is ReturnStatement || ex is BreakStatement)
                {
                    throw new ParserException(output[i + 1].FirstToken, "Unreachable code detected");
                }

                if (ex is ExpressionAsExecutable)
                {
                    Expression innerExpression = ((ExpressionAsExecutable)ex).Expression;
                    if (!(innerExpression is FunctionInvocation))
                    {
                        throw new ParserException(ex.FirstToken, "This expression isn't allowed here.");
                    }
                }
            }
            return(output);
        }
Esempio n. 3
0
 public void ResolveWithTypeContext(PastelCompiler compiler)
 {
     Executable.ResolveWithTypeContext(compiler, this.Code);
 }
Esempio n. 4
0
 public void ResolveNamesAndCullUnusedCode(PastelCompiler compiler)
 {
     this.Code = Executable.ResolveNamesAndCullUnusedCodeForBlock(this.Code, compiler).ToArray();
 }
Esempio n. 5
0
 internal override Executable ResolveWithTypeContext(PastelCompiler compiler)
 {
     this.Condition = this.Condition.ResolveWithTypeContext(compiler);
     Executable.ResolveWithTypeContext(compiler, this.Code);
     return(this);
 }
Esempio n. 6
0
 public override Executable ResolveNamesAndCullUnusedCode(PastelCompiler compiler)
 {
     this.Condition = this.Condition.ResolveNamesAndCullUnusedCode(compiler);
     this.Code      = Executable.ResolveNamesAndCullUnusedCodeForBlock(this.Code, compiler).ToArray();
     return(this);
 }
Esempio n. 7
0
 internal override Executable ResolveWithTypeContext(PastelCompiler compiler)
 {
     Executable.ResolveWithTypeContext(compiler, this.Executables);
     return(this);
 }