Exemplo n.º 1
0
        public ASTCILNode VisitAtribute(ASTAtributeNode Atribute)
        {
            var atribute = Atribute.SymbolTable.GetObject(Atribute.AttributeName);

            if (Atribute.HasInit)
            {
                return(new ASTCILSetAttributeNode(atribute, (ASTCILExpressionNode)Atribute.Init.Accept(this)));
            }
            if (atribute.Type.Equals(compilationUnit.TypeEnvironment.Int.Name))
            {
                return(new ASTCILSetAttributeNode(atribute,
                                                  new ASTCILIntConstantNode(0)));
            }
            if (atribute.Equals(compilationUnit.TypeEnvironment.String.Name))
            {
                return(new ASTCILSetAttributeNode(atribute,
                                                  new ASTCILStringConstantNode("", labelIlGenerator.GenerateEmptyStringData())));
            }
            if (atribute.Equals(compilationUnit.TypeEnvironment.Bool.Name))
            {
                return(new ASTCILSetAttributeNode(atribute,
                                                  new ASTCILBoolConstantNode(false)));
            }
            return(new ASTCILSetAttributeNode(atribute, new ASTCILVoidNode()));
        }
 public virtual T VisitAtribute(ASTAtributeNode Atribute)
 {
     if (Atribute.HasInit)
     {
         Atribute.Init.Accept(this);
     }
     return(default(T));
 }
Exemplo n.º 3
0
        public override SemanticCheckResult VisitAtribute(ASTAtributeNode Atribute)
        {
            Atribute.SemanticCheckResult.Ensure(!Types.IsSelf(Atribute.AttributeName),
                                                new Lazy <Error>(() => new Error($"Not allowed to use {Atribute.AttributeName}.", ErrorKind.SemanticError, Atribute.Attribute.Line, Atribute.Attribute.Column)));
            var isdef = CompilationUnit.TypeEnvironment.GetTypeDefinition(Atribute.TypeName, Atribute.SymbolTable, out var t);

            Atribute.SemanticCheckResult.Ensure(isdef,
                                                new Lazy <Error> (() => new Error($"Missing declaration for type {Atribute.TypeName}.", ErrorKind.TypeError, Atribute.Type.Line, Atribute.Type.Column)));
            if (isdef && Atribute.HasInit)
            {
                var r = Atribute.Init.Accept(this);
                Atribute.SemanticCheckResult.Ensure(r, r.Type.IsIt(t),
                                                    new Lazy <Error>(() => new Error($"Type {r} does not inherit from type {t}.", ErrorKind.AttributeError, Atribute.Attribute.Line, Atribute.Attribute.Column)));
                Atribute.SemanticCheckResult.EnsureReturnType(t);
            }
            return(Atribute.SemanticCheckResult);;
        }