public override IList <Executable> ResolveTypes(ParserContext context, VariableScope varScope) { this.TryCode = Executable.ResolveTypesForCode(this.TryCode, context, new VariableScope(varScope)); foreach (CatchBlock cb in this.CatchBlocks) { ResolvedType exceptionType = this.Parent.DoTypeLookupFailSilently(cb.ExceptionType, context); if (exceptionType == null) { throw new ParserException(cb.ExceptionType.FirstToken, "Exception type not found."); } if (!exceptionType.IsException(context)) { throw new ParserException(cb.ExceptionType.FirstToken, "This type does not extend from System.Exception"); } VariableScope catchVarScope = new VariableScope(varScope); if (cb.ExceptionVariable != null) { catchVarScope.DeclareVariable(cb.ExceptionVariable.Value, exceptionType); } cb.Code = Executable.ResolveTypesForCode(cb.Code, context, catchVarScope); } if (this.FinallyCode != null) { this.FinallyCode = Executable.ResolveTypesForCode(this.FinallyCode, context, new VariableScope(varScope)); } return(Listify(this)); }
public Expression ResolveTypesWithExteriorHint( ParserContext context, VariableScope varScope, ResolvedType[] expectedArgsAndReturnTypes) { VariableScope lambdaScope = new VariableScope(varScope); if (this.Args.Length != expectedArgsAndReturnTypes.Length - 1) { throw new ParserException(this.ArrowToken, "The expected number of args was " + (expectedArgsAndReturnTypes.Length - 1)); } for (int i = 0; i < this.Args.Length; ++i) { lambdaScope.DeclareVariable(this.Args[i].Value, expectedArgsAndReturnTypes[i]); } this.Code = Executable.ResolveTypesForCode(this.Code, context, lambdaScope); ResolvedType returnType = null; if (this.Code.Length == 1 && this.Code[0] is ExpressionAsExecutable) { returnType = ((ExpressionAsExecutable)this.Code[0]).Expression.ResolvedType; } else if (this.Code.Length > 0 && this.Code[this.Code.Length - 1] is ReturnStatement) { ReturnStatement ret = (ReturnStatement)this.Code[this.Code.Length - 1]; if (ret.Value == null) { throw new ParserException(ret.FirstToken, "Return statement in lambda must have a value."); } returnType = ret.Value.ResolvedType; } else { throw new ParserException(this.FirstToken, "Not implemented: the return is hiding in this lambda."); } ResolvedType expectedReturnType = expectedArgsAndReturnTypes[expectedArgsAndReturnTypes.Length - 1]; if (expectedReturnType == null) { expectedReturnType = returnType; } else { if (!returnType.CanBeAssignedTo(expectedReturnType, context)) { throw new ParserException(this.FirstToken, "This lambda does not seem to be returning the expected type."); } } List <ResolvedType> argTypes = new List <ResolvedType>(expectedArgsAndReturnTypes); argTypes.RemoveAt(argTypes.Count - 1); this.ResolvedType = ResolvedType.CreateFunction(expectedReturnType, argTypes.ToArray()); return(this); }
public override IList <Executable> ResolveTypes(ParserContext context, VariableScope varScope) { VariableScope loopScope = new VariableScope(varScope); this.InitCode = Executable.ResolveTypesForCode(this.InitCode, context, loopScope); this.Condition = this.Condition.ResolveTypes(context, loopScope); this.StepCode = Executable.ResolveTypesForCode(this.StepCode, context, loopScope); this.Code = Executable.ResolveTypesForCode(this.Code, context, loopScope); return(Listify(this)); }
public override void ResolveTypesInCode(ParserContext context) { VariableScope varScope = new VariableScope(); for (int i = 0; i < this.ArgNames.Length; ++i) { varScope.DeclareVariable(this.ArgNames[i].Value, this.ResolvedArgTypes[i]); } this.Code = Executable.ResolveTypesForCode(this.Code, context, varScope); }
public override IList <Executable> ResolveTypes(ParserContext context, VariableScope varScope) { this.Condition = this.Condition.ResolveTypes(context, varScope); VariableScope ifScope = new VariableScope(varScope); this.IfCode = Executable.ResolveTypesForCode(this.IfCode, context, ifScope); if (this.ElseCode != null) { VariableScope elseScope = new VariableScope(varScope); this.ElseCode = Executable.ResolveTypesForCode(this.ElseCode, context, elseScope); } return(Listify(this)); }
public override IList <Executable> ResolveTypes(ParserContext context, VariableScope varScope) { this.ListExpression = this.ListExpression.ResolveTypes(context, varScope); VariableScope loopScope = new VariableScope(varScope); ResolvedType itemType = this.ListExpression.ResolvedType.GetEnumerableItemType(); if (itemType == null) { throw new ParserException(this.ListExpression.FirstToken, "This expression is not enumerable."); } loopScope.DeclareVariable(this.VariableToken.Value, itemType); this.Code = Executable.ResolveTypesForCode(this.Code, context, loopScope); return(Listify(this)); }
public override void ResolveTypesInCode(ParserContext context) { PropertyDefinition propertyDef = (PropertyDefinition)this.Parent; VariableScope varScope = new VariableScope(); if (this.IsSetter) { varScope.DeclareVariable("value", propertyDef.ResolvedType); } if (propertyDef.IsIndex) { varScope.DeclareVariable(propertyDef.IndexVariableName.Value, propertyDef.IndexResolvedType); } if (this.Code != null) { this.Code = Executable.ResolveTypesForCode(this.Code, context, varScope); } }
public override IList <Executable> ResolveTypes(ParserContext context, VariableScope varScope) { this.Condition = this.Condition.ResolveTypes(context, varScope); VariableScope switchScope = new VariableScope(varScope); foreach (SwitchStatementChunk chunk in this.Chunks) { for (int i = 0; i < chunk.Cases.Length; ++i) { Expression caseExpr = chunk.Cases[i]; if (caseExpr != null) { chunk.Cases[i] = caseExpr.ResolveTypes(context, switchScope); } } chunk.Code = Executable.ResolveTypesForCode(chunk.Code, context, switchScope); } return(Listify(this)); }