Beispiel #1
0
        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;
            }
        }