示例#1
0
 public override SemanticCheckResult VisitNew(ASTNewNode New)
 {
     New.SemanticCheckResult.Ensure(CompilationUnit.TypeEnvironment.GetTypeDefinition(New.TypeName, New.SymbolTable, out var type),
                                    new Lazy <Error>(() => new Error($"Missing declaration for type {New.TypeName}.", ErrorKind.TypeError, New.Type.Line, New.Type.Column)));
     New.SemanticCheckResult.EnsureReturnType(type);
     return(New.SemanticCheckResult);
 }
示例#2
0
        public ASTCILNode VisitNew(ASTNewNode context)
        {
            var type = context.SemanticCheckResult.Type;

            if (context.SemanticCheckResult.Type is SelfType selftype)
            {
                type = selftype.ContextType;
            }
            if (type == compilationUnit.TypeEnvironment.Int)
            {
                return(new ASTCILIntConstantNode(0));
            }
            if (type == compilationUnit.TypeEnvironment.Bool)
            {
                return(new ASTCILBoolConstantNode(false));
            }
            if (type == compilationUnit.TypeEnvironment.String)
            {
                return(new ASTCILStringConstantNode("", labelIlGenerator.GenerateEmptyStringData()));
            }

            return(new ASTCILFuncVirtualCallNode(type, Functions.Init, new[] { new ASTCILAllocateNode(type) }));
        }
 public virtual T VisitNew(ASTNewNode context)
 {
     return(default(T));
 }