public override bool Validate(L1Specializer.Metadata.SymbolTableLight table) { if (Expression == null) return true; bool valid = Expression.Validate(table); return valid; }
public override bool Validate(L1Specializer.Metadata.SymbolTableLight table) { bool valid = Expression.Validate(table); if (valid && !(Expression.ResultType.TypeEnum == VariableTypeEnum.Bool)) { CompilerServices.AddError( Location, "Expression under assert must be type of bool" ); valid = false; } return valid; }
public override bool Validate(L1Specializer.Metadata.SymbolTableLight table) { VariableType type = Definitions[0].VariableType; bool ok = true; foreach (VariableSymbol symbol in Definitions) { if (table.TryGetSymbol(symbol.Name) != null) { CompilerServices.AddError( symbol.Location, "Variable name dublicate!" ); ok = false; } else { bool typeConflict = false; if (symbol.InitExpression != null) { bool validInit = symbol.InitExpression.Validate(table); if (validInit) { if (!CompilerServices.IsAssignable(symbol.VariableType, symbol.InitExpression.ResultType)) { typeConflict = true; } } } if (typeConflict) { CompilerServices.AddError( symbol.Location, "Variable initialization expression has different type!" ); ok = false; } else { table.AddSymbol(new L1Specializer.Metadata.SymbolLight(symbol.Name, type)); } } } return ok; }
public override bool Validate(L1Specializer.Metadata.SymbolTableLight table) { return true; }
public override bool Validate(L1Specializer.Metadata.SymbolTableLight table) { if (DeclareVariable != String.Empty) { if (VariableType.TypeEnum != VariableTypeEnum.Integer && VariableType.TypeEnum != VariableTypeEnum.Char) { CompilerServices.AddError( Location, "Cycle variable must be type of int or char!" ); return false; } if (table.TryGetSymbol(DeclareVariable) != null) { CompilerServices.AddError( Location, "Declared cycle variable already exists!" ); return false; } bool valid = Init.Validate(table); if (valid) { if (!CompilerServices.IsAssignable(VariableType, Init.ResultType)) { CompilerServices.AddError( Location, "Cycle variable initialization expression has different type!" ); return false; } } else return false; } else { if (Init.LeftNode.LeafType != ExpressionLeafType.VariableAccess) { CompilerServices.AddError( Location, "Error in cycle definition: no variable reference presented!" ); return false; } bool valid = Init.Validate(table); if (!valid) return false; } bool validStep = Step.Validate(table); bool validEnd = EndValue.Validate(table); if (validEnd && validStep) { if (Step.ResultType.TypeEnum != VariableTypeEnum.Integer) { CompilerServices.AddError( Location, "Cycle step must be type of int!" ); return false; } if (EndValue.ResultType.TypeEnum != VariableTypeEnum.Integer && EndValue.ResultType.TypeEnum != VariableTypeEnum.Char) { CompilerServices.AddError( Location, "Cycle end value must be type of int or char!" ); return false; } } else return false; SymbolTableLight newTable = new SymbolTableLight(table); if (DeclareVariable != String.Empty) { newTable.AddSymbol(new SymbolLight(DeclareVariable, VariableType)); } bool res = CompilerServices.ValidateStatementList(Statements, newTable); return res; }