public override IRppNode Analyze(SymbolTable scope, Diagnostic diagnostic) { RType thisType = scope.GetEnclosingType(); if (thisType == null) { throw new Exception("Can't find enclosing type for this"); } Type = new ResolvableType(thisType); return this; }
public override IRppNode Analyze(SymbolTable scope, Diagnostic diagnostic) { if (InitExpr is RppEmptyExpr && IsLocalSemantic) { diagnostic.Error(102, "local variable must be initialized"); return this; } // Don't capture variables declared inside closure CanBeCaptured = scope.GetEnclosingType()?.Name != RppClosure.TempClosureTypeName; // We have 2 cases when type is omited, so we need to get it from initializing expression // and when type is specified so we need to resolve it and if there is a closure, propagate that // to init expression if (Type.IsDefined()) { Type.Resolve(scope); InitExpr = TypeInference.ReplaceUndefinedClosureTypesIfNeeded(InitExpr, Type, new List<RType>()); InitExpr = (IRppExpr) InitExpr.Analyze(scope, diagnostic); } else { InitExpr = (IRppExpr) InitExpr.Analyze(scope, diagnostic); Type = InitExpr.Type; } if (IsLocalSemantic) { scope.AddLocalVar(Name, Type.Value, this); } if (!(InitExpr is RppEmptyExpr)) { if (ImplicitCast.CanCast(InitExpr.Type.Value, Type.Value)) { InitExpr = ImplicitCast.CastIfNeeded(InitExpr, Type.Value); } else { throw SemanticExceptionFactory.TypeMismatch(Token, Type.Value.Name, InitExpr.Type.Value.Name); } } return this; }