public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); var func = scope.ResolveVarOrFunction(FunctionIdNode.Text); if (!report.Assert(this, func != null, "Undefined function {0}.", FunctionIdNode.Text) || !report.Assert(this, func is FunctionInfo, "Cannot invoke a variable.") || !report.Assert(this, ((FunctionInfo)func).Parameters.Count == ExpressionList.ChildCount, "Calling function with wrong amount of parameters.")) { return; } var functionInfo = (FunctionInfo)func; int i = 0; foreach (var parameter in functionInfo.Parameters) { var paramExpression = (ASTNode)ExpressionList.Children[i++]; report.Assert(paramExpression, paramExpression.ReturnType == parameter.Value, "Function parameter and expression types do not match."); } ReturnType = functionInfo.ReturnType; // Procedures will hold void as a return type. }
public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); if (TypeID == null) { report.Assert(this, InitialValue.ReturnType != TypeInfo.Unknown, "The variable type cannot be inferred from usage. Specify the type explicitly."); report.Assert(this, InitialValue.ReturnType != TypeInfo.Void, "Initialization value expression must return a value."); ReturnType = InitialValue.ReturnType; } else { TypeInfo type = (scope.ResolveType(TypeID.TypeName)); if (report.Assert(this, !ReferenceEquals(type, null), "Cannot find type {0} in variable {1}'s declaration.", TypeID.TypeName, VariableID.Text)) { report.Assert(this, type == InitialValue.ReturnType, "The initial expression type does not match with the specified type {0}.", TypeID.TypeName); ReturnType = type; } } if (report.Assert(this, !scope.IsDefinedInCurrentScopeAsVarOrFunc(VariableID.Text), "A function or variable named {0} is already defined in the current scope.", VariableID.Text)) { scope.DefineVariable(VariableID.Text, ReturnType); } VariableID.CheckSemantics(scope, report); }
public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); report.Assert(this, LeftOperand.ReturnType == TypeInfo.Int, "Left operand must be an integer."); report.Assert(this, RightOperand.ReturnType == TypeInfo.Int, "Right operand must be an integer."); ReturnType = TypeInfo.Int; }
public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); report.Assert(this, IfCondition.ReturnType == TypeInfo.Int, "An if expression must return int."); report.Assert(this, ThenExpression.ReturnType == ElseExpression.ReturnType, "The if and else expression types do not match."); ReturnType = ThenExpression.ReturnType; }
public override void CheckSemantics(Scope scope, ErrorReporter report) { forScope = scope.CreateChildScope(); loopVariable = forScope.DefineVariable(LoopVariableIDNode.Text, TypeInfo.Int, true); base.CheckSemantics(forScope, report); report.Assert(LoopVariableInitExpression, LoopVariableInitExpression.ReturnType == TypeInfo.Int, "The initialization expression of a for loop must return an integer value."); report.Assert(this, LoopVariableUpperLimitExpression.ReturnType == TypeInfo.Int, "The upper bound expression of a for loop must return an integer value."); //report.Assert(DoExpression, DoExpression.ReturnType == TypeInfo.Void, "A for expression cannot return a value."); ReturnType = TypeInfo.Void; }
public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); if (report.Assert(this, CanBeAssignedTo, "Cannot assign a value to {0}. It is a read-only variable or a function.", LValue.Children[0].Text)) { report.Assert(Expression, TypeInfo.IsNull(LValue.ReturnType) || Expression.ReturnType == LValue.ReturnType, "Expression and variable types do not match."); } ReturnType = TypeInfo.Void; }
public override bool ResolveReferencedTypes(ASTNode node, Scope scope, ErrorReporter reporter) { if (ResolutionStatus != TypeResolutionStatus.NotResolved) { return(true); } ResolutionStatus = TypeResolutionStatus.OK; //ResolutionStatus = TypeResolutionStatus.Resolving; foreach (var nameTypeTuple in _preFields) { var tmp = scope.ResolveType(nameTypeTuple.Value); if (!reporter.Assert(node, !IsNull(tmp), "Cannot find type {0} in current context.", nameTypeTuple.Value)) { continue; } if (tmp.ResolutionStatus == TypeResolutionStatus.NotResolved) { tmp.ResolveReferencedTypes(node, scope, reporter); } Fields.Add(nameTypeTuple.Key, tmp); } return(true); }
//protected new TypeInfo Type //{ // get // { // var type = Scope.ResolveType(NewTypeNode.TypeName); // if (type is AliasTypeInfo) // return (type as AliasTypeInfo).TargetType; // return type; // } //} public void ResolveReferencedTypes(Scope scope, ErrorReporter reporter) { var type = scope.ResolveType(NewTypeNode.TypeName); var noCycles = type.ResolveReferencedTypes(this, scope, reporter); reporter.Assert(this, noCycles, "Invalid type detected. Check for invalid type references, or cyclic type definitions."); }
public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); report.Assert((ASTNode)Children[0], Operand.ReturnType == TypeInfo.Int, "The expression of the unary minus must be an integer."); ReturnType = TypeInfo.Int; }
public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); report.Assert(this, (LeftOperand.ReturnType == TypeInfo.Int && RightOperand.ReturnType == TypeInfo.Int) || (RightOperand.ReturnType == TypeInfo.String && LeftOperand.ReturnType == TypeInfo.String), "Return types must be both int or string for comparisons."); ReturnType = TypeInfo.Int; }
public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); var type = scope.ResolveType(NewTypeNode.TypeName); report.Assert(this, TypeInfo.IsNull(type) || !type.IsReadOnly, "Cannot overwrite type {0}. It is read-only.", NewTypeNode.TypeName); NewTypeNode.CheckSemantics(scope, report); }
public override void CheckSemantics(Scope scope, ErrorReporter report) { _letScope = scope.CreateChildScope(); base.CheckSemantics(_letScope, report); ReturnType = ExprSeqNode != null ? ExprSeqNode.ReturnType : TypeInfo.Void; report.Assert(this, _letScope.TypeIsVisibleInSomeParentScope(ReturnType), "The return type of a let expression must be visible in the scope in which it was declared."); }
public static string StringMapToLowerCase(string s) { s = s.Replace("0", "00"); for (char c = 'A'; c <= 'Z'; c++) { s = s.Replace($"{c}", $"0{c}".ToLower()); } foreach (char c in s) { ErrorReporter.Assert('a' <= c && c <= 'z'); } return(s); }
public ViewPriceRequestByCarOwnerPage(Dictionary <string, string> _data) { data = _data; foreach (var f in Enum.GetValues(typeof(NotificationManager.Flags))) { ErrorReporter.Assert(data.ContainsKey($"{f}")); } foreach (var f in Enum.GetValues(typeof(NotificationManager.CarOwnerPriceRequestFlag))) { ErrorReporter.Assert(data.ContainsKey($"{f}")); } InitializeViews(); RegisterEvents(); }
public override void CheckSemantics(Scope scope, ErrorReporter report) { // - Add the function declaration inside this block to the current scope. // - Create a child scope for every function. ParameterTypesNode.CheckSemantics(scope, report); Scope = scope; var func = scope.ResolveVarOrFunction(FunctionName) as FunctionInfo; if (report.Assert(this, func == null || func.IsReadOnly, "Cannot overwrite {0} function.", FunctionName) && report.Assert(this, !scope.IsDefinedInCurrentScopeAsVarOrFunc(FunctionName), "A function or variable named {0} is already defined in the current scope.", FunctionName)) { var newFunc = scope.DefineFunction(FunctionName, FunctionReturnType); foreach (KeyValuePair <string, TypeInfo> info in ParameterTypesNode.Parameters) { newFunc.AddParameter(info.Key, info.Value); } } // The function body semantic check will be done by the parent block. FunctionIDNode.CheckSemantics(scope, report); }
public override bool ResolveReferencedTypes(ASTNode node, Scope scope, ErrorReporter reporter) { if (ResolutionStatus != TypeResolutionStatus.NotResolved) { return(ResolutionStatus == TypeResolutionStatus.OK); } ResolutionStatus = TypeResolutionStatus.Resolving; if (TargetType == null) { TargetType = scope.ResolveType(_targetTypeName); } if (reporter.Assert(node, !IsNull(TargetType), "Unknown type: {0}.", _targetTypeName)) { bool ok = TargetType.ResolveReferencedTypes(node, scope, reporter); ResolutionStatus = ok? TypeResolutionStatus.OK : TypeResolutionStatus.Error; return(ok); } return(false); }
public override bool ResolveReferencedTypes(ASTNode node, Scope scope, ErrorReporter reporter) { if (ResolutionStatus != TypeResolutionStatus.NotResolved) { return(ResolutionStatus == TypeResolutionStatus.OK); } ResolutionStatus = TypeResolutionStatus.Resolving; TargetType = scope.ResolveType(_targetTypeName); if (reporter.Assert(node, !ReferenceEquals(TargetType, null), "Unknown type in the current context: {0}", _targetTypeName)) { if (TargetType.ResolutionStatus == TypeResolutionStatus.NotResolved) { TargetType.ResolveReferencedTypes(node, scope, reporter); } switch (TargetType.ResolutionStatus) { case TypeResolutionStatus.Resolving: case TypeResolutionStatus.Error: ResolutionStatus = TypeResolutionStatus.Error; return(false); case TypeResolutionStatus.OK: TargetType = (TargetType is AliasTypeInfo) ? ((AliasTypeInfo)TargetType).TargetType : TargetType; break; default: throw new ArgumentOutOfRangeException(); } ResolutionStatus = TypeResolutionStatus.OK; return(true); } return(false); }
public static async Task UploadAsync(DataType dataType) { indexRetry :; try { string s = GetJson(dataType); ErrorReporter.Assert(s != null); var blockBlob = await GetBlockBlobForAppDataAsync(dataType); //container.GetBlockBlobReference(dataType.ToString().ToLower()); await blockBlob.UploadTextAsync(s); } catch (StorageException error) { if (error.Message == "An error occurred while sending the request") { if (await App.Current.MainPage.DisplayAlert("無法連線", "資料上傳失敗,請將您的裝置連上網路後再重試一次", "重試", "取消")) { goto indexRetry; } else { throw new OperationCanceledException(); } } else { await new ErrorAlert("StorageException: 使用者資料上傳失敗", error).Show(); throw new OperationCanceledException(); } } catch (Exception error) { await new ErrorAlert("Exception: 使用者資料上傳失敗", error).Show(); throw new OperationCanceledException(); } }
public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); var variableInfo = scope.ResolveVarOrFunction(MainIDNode.Text) as VariableInfo; if (report.Assert(this, variableInfo != null, "Unknown variable for the current scope ({0}).", MainIDNode.Text)) { Debug.Assert(variableInfo != null, "variableInfo != null"); ReturnType = variableInfo.VariableType; for (int i = 1; i < Children.Count; i++) { var tmp = Children[i]; if (tmp is DotNode) { var recordTypeInfo = TypeInfo.RecordFromTypeInfo(ReturnType); if (recordTypeInfo != null) { TypeInfo value; bool memberExists = recordTypeInfo.Fields.TryGetValue(((DotNode)tmp).MemberName, out value); if (memberExists) { ReturnType = value; } else { report.AddError(this, "Unknown member."); ReturnType = null; break; } } else { report.AddError(this, "Dot operator applied to an invalid type."); break; } } else if (tmp is IndexingNode) { if (ReturnType is AliasTypeInfo) { ReturnType = (ReturnType as AliasTypeInfo).TargetType; } if (ReturnType is ArrayTypeInfo) { ReturnType = ((ArrayTypeInfo)ReturnType).TargetType; } else { report.AddError(this, "Trying to index on a non-array type."); break; } } else { throw new ArgumentOutOfRangeException("Invalid child node of LValue detected."); } } } }
public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); report.Assert(this, IndexNode.ReturnType == TypeInfo.Int, "Index is not an integer."); }