public override void CheckSemantics(Semantics.Scope scope, List <Semantics.SemanticError> errors) { //-------------------------------------------------- // Poner Por Defecto Que Hay Errores. //-------------------------------------------------- this.ExpressionType = PredefinedTypes.ErrorType; //-------------------------------------------------- // Buscar El Primer Nodo Hacia La Raiz Que Acepte // Break. //-------------------------------------------------- this.Owner = null; var pathToTheRoot = this.GetAncestors().Reverse(); foreach (var u in pathToTheRoot) { if (u is IBreakableNode) { this.Owner = u as IBreakableNode; break; } if (u is FunctionDeclarationNode) { break; } if (u is ExpressionsBlockNode) { (u as ExpressionsBlockNode).ContainsBreakNodes = true; } } //-------------------------------------------------- // Comprobar Si El Break Está Siendo Usado Fuera // De Un For, While, O Bloque De Expresiones. //-------------------------------------------------- if (this.Owner == null) { errors.Add(SemanticError.InvalidUseOfBreak(this)); } else { this.ExpressionType = PredefinedTypes.VoidType; } }
public override void CheckSemantics(TigerScope scope, Report report) { ContainingScope = scope; IsOK = true; //Check if break is in correct position var nodes = GetNodesToRoot().TakeWhile(x => !(x is MethodDeclarationNode)).ToList(); Owner = (nodes.FirstOrDefault(x => x is IBreakableNode)) as IBreakableNode; if (Owner == null) { report.AddError(SemanticErrors.BreakInIncorrectPostion(this)); return; } //Set containing InstructionSequenceNodes' types to void nodes.TakeWhile(x => !(x is IBreakableNode)).Where(n => n is InstructionSequenceNode).ToList() .ForEach(n => ((InstructionSequenceNode)n).TigerType = TigerType.Void); }