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); }
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); }
public void ResolveWithTypeContext(PastelCompiler compiler) { Executable.ResolveWithTypeContext(compiler, this.Code); }
public void ResolveNamesAndCullUnusedCode(PastelCompiler compiler) { this.Code = Executable.ResolveNamesAndCullUnusedCodeForBlock(this.Code, compiler).ToArray(); }
internal override Executable ResolveWithTypeContext(PastelCompiler compiler) { this.Condition = this.Condition.ResolveWithTypeContext(compiler); Executable.ResolveWithTypeContext(compiler, this.Code); return(this); }
public override Executable ResolveNamesAndCullUnusedCode(PastelCompiler compiler) { this.Condition = this.Condition.ResolveNamesAndCullUnusedCode(compiler); this.Code = Executable.ResolveNamesAndCullUnusedCodeForBlock(this.Code, compiler).ToArray(); return(this); }
internal override Executable ResolveWithTypeContext(PastelCompiler compiler) { Executable.ResolveWithTypeContext(compiler, this.Executables); return(this); }