示例#1
0
 public CaseLabel(Expression constant, AstNode children, TokenPosition position)
     : base(position)
 {
     this.constant = constant;
     this.children = children;
     this.block = null;
 }
示例#2
0
 public ConstructorInitializer(bool baseCall, AstNode arguments, TokenPosition position)
     : base(position)
 {
     this.baseCall = baseCall;
     this.arguments = arguments;
     this.ctorGroup = null;
 }
示例#3
0
 public ClassDefinition(MemberFlags flags, string name,
                        GenericSignature genericSignature,
                        AstNode bases, AstNode children, TokenPosition position)
     : base(flags, name, genericSignature,
            bases, children, position)
 {
 }
示例#4
0
 public MakeFunctionPointer(Expression returnType, AstNode arguments, MemberFlags flags, TokenPosition position)
     : base(position)
 {
     this.returnType = returnType;
     this.arguments = arguments;
     this.flags = flags;
 }
示例#5
0
 public EnumDefinition(MemberFlags flags, string name, AstNode children,
     Expression typeExpr, TokenPosition position)
     : base(children, position)
 {
     SetName(name);
     this.flags = flags;
     this.typeExpr = typeExpr;
 }
示例#6
0
 public TryStatement(AstNode tryStatement, AstNode catchList,
                      AstNode finallyStatement, TokenPosition position)
     : base(position)
 {
     this.tryStatement = tryStatement;
     this.catchList = catchList;
     this.finallyStatement = finallyStatement;
 }
示例#7
0
 public SwitchStatement(Expression constant, AstNode cases, TokenPosition position)
     : base(position)
 {
     this.constant = constant;
     this.cases = cases;
     this.defaultCase = null;
     this.caseDictionary = new Dictionary<ConstantValue, CaseLabel> ();
 }
示例#8
0
 public FunctionDefinition(FunctionPrototype prototype, AstNode children, TokenPosition position)
     : base(children, position)
 {
     this.prototype = prototype;
     this.function = null;
     this.isGenerator = false;
     this.hasReturns = false;
     this.yields = new List<ReturnStatement> ();
 }
示例#9
0
 public CatchStatement(Expression exceptionType, string name,
                        AstNode children, TokenPosition position)
     : base(children, position)
 {
     SetName(name);
     this.exceptionType = exceptionType;
     this.context = null;
     this.variable = null;
 }
示例#10
0
 public PropertyAccessor(MemberFlags flags, AstNode children, TokenPosition position)
     : base(null, children, position)
 {
     this.flags = flags;
     this.property = null;
     this.selfLocal = null;
     this.indices = null;
     this.indexerVariables = null;
 }
示例#11
0
 public EventAccessorDefinition(MemberFlags flags, string name, AstNode children, TokenPosition position)
     : base(children, position)
 {
     SetName(name);
     this.flags = flags;
     this.eventVariable = null;
     this.function = null;
     this.selfLocal = null;
     this.valueLocal = null;
 }
示例#12
0
 public EventDefinition(MemberFlags flags, Expression eventType,
                         string name, AstNode accessors, TokenPosition position)
     : base(position)
 {
     SetName(name);
     this.flags = flags;
     this.eventType = eventType;
     this.eventVariable = null;
     this.accessors = accessors;
     this.delegateType = null;
 }
示例#13
0
 public PropertyDefinition(MemberFlags flags, Expression propertyType,
                           string name, AstNode indices, AstNode accessors, TokenPosition position)
     : base(position)
 {
     SetName(name);
     this.flags = flags;
     this.propertyType = propertyType;
     this.property = null;
     this.indices = indices;
     this.accessors = accessors;
 }
示例#14
0
 public NewArrayExpression(Expression typeExpression, Expression size,
                            AstNode initializers, int dimensions, TokenPosition position)
     : base(position)
 {
     this.typeExpression = typeExpression;
     this.size = size;
     this.initializers = initializers;
     this.dimensions = dimensions;
     this.objectType = null;
     this.initCoercionType = null;
 }
示例#15
0
 public DelegateDefinition(MemberFlags flags, Expression returnType,
                            AstNode arguments, string name,
                            GenericSignature genericSignature,
                            TokenPosition position)
     : base(position)
 {
     SetName(name);
     this.genericSignature = genericSignature;
     this.flags = flags;
     this.returnType = returnType;
     this.arguments = arguments;
 }
示例#16
0
文件: AstNode.cs 项目: ronsaldo/chela
 public AstNode(TokenPosition position)
 {
     this.position = position;
     this.prev = this;
     this.next = null;
     this.attributes = null;
     this.name = null;
     this.module = null;
     this.nodeType = null;
     this.coercionType = null;
     this.nodeValue = null;
 }
示例#17
0
        public StructDefinition(MemberFlags flags, string name,
                                GenericSignature genericSignature,
		                        AstNode bases, AstNode children,
                                TokenPosition position)
            : base(children, position)
        {
            SetName(name);
            this.flags = flags;
            this.bases = bases;
            this.genericSignature = genericSignature;
            this.defaultConstructor = null;
            this.genericScope = null;
        }
示例#18
0
        public void AddLast(AstNode child)
        {
            if(child == null)
                return;

            if(this.children == null)
            {
                this.children = child;
                return;
            }

            AstNode lastChild = this.children;
            while(lastChild.GetNext() != null)
                lastChild = lastChild.GetNext();
            lastChild.SetNext(child);
        }
示例#19
0
        public void AddFirst(AstNode child)
        {
            if(child == null)
                return;

            if(this.children == null)
            {
                this.children = child;
                return;
            }

            // Add my children to the end of the list.
            AstNode lastChild = child;
            while(lastChild.GetNext() != null)
                lastChild = lastChild.GetNext();
            lastChild.SetNext(children);

            // Set the first.
            children = child;
        }
示例#20
0
 public void SetIndices(AstNode indices)
 {
     this.indices = indices;
 }
示例#21
0
        public void CheckScopeVisibility(AstNode node, Scope scope)
        {
            // Check the parent scope access.
            Scope parentScope = scope.GetParentScope();
            if(parentScope != null)
                CheckScopeVisibility(node, parentScope);

            // Internal scopes module must be the current one.
            if(scope.IsInternal() && scope.GetModule() != currentModule)
                Error(node, "cannot access internal member " + scope.GetFullName() +" of another module.");
        }
示例#22
0
 public NamespaceDefinition(string name, AstNode children, TokenPosition position)
     : base(children, position)
 {
     SetName(name);
     this.nspace = null;
 }
示例#23
0
 public FinallyStatement(AstNode children, TokenPosition position)
     : base(position)
 {
     this.children = children;
     this.context = null;
 }
示例#24
0
        public Structure ExtractClass(AstNode where, ScopeMember member)
        {
            // Make sure its a structure or type group.
            if(!member.IsClass() && !member.IsStructure() &&!member.IsInternal() &&
                !member.IsTypeGroup())
                Error(where, "coudn't load runtime class.");

            // Read the type group.
            if(member.IsTypeGroup())
            {
                TypeGroup group = (TypeGroup)member;
                Structure building = group.GetDefaultType();
                if(building == null)
                    Error(where, "unexpected type group {0}", @group.GetDisplayName());

                // Prevent ambiguity of merged type group.
                building.CheckAmbiguity(where.GetPosition());
                return building;
            }

            return (Structure)member;
        }
示例#25
0
        public void CheckMemberVisibility(AstNode node, ScopeMember member)
        {
            // Ignore placeholder types.
            if(member.IsType())
            {
                IChelaType type = (IChelaType)member;
                if(type.IsPlaceHolderType())
                    return;
            }

            // Special treatment for scope member.
            if(member.IsScope())
            {
                CheckScopeVisibility(node, (Scope)member);
                return;
            }

            // Check the parent scope access.
            Scope parentScope = member.GetParentScope();
            if(parentScope != null)
                CheckScopeVisibility(node, parentScope);

            // Check the actual member visibility.
            if(member.IsPrivate())
            {
                // Walk the scope hierarchy.
                Scope scope = currentScope;
                while(scope != null)
                {
                    // Found the defining scope, stop checking.
                    if(scope == parentScope ||
                       parentScope.IsInstanceOf(scope))
                        return;

                    // Found the scope.
                    scope = scope.GetParentScope();
                }

                // Couldn't find scope, raise error.
                Error(node, "cannot access private member " + member.GetFullName());
            }
            else if(member.IsProtected())
            {
                // The parent scope must be a Structure derivative.
                Structure parentBuilding = (Structure)parentScope;

                // Walk the scope hierarchy.
                Scope scope = currentScope;
                while(scope != null)
                {
                    // Found the defining scope, stop checking.
                    if(scope is Structure)
                    {
                        Structure derived = (Structure)scope;
                        if(derived == parentBuilding ||
                           derived.IsDerivedFrom(parentBuilding))
                            return;
                    }

                    // Found the scope.
                    scope = scope.GetParentScope();
                }

                // Couldn't find scope, raise error.
                Error(node, "cannot access protected member " + member.GetFullName());
            }
            else if(member.IsInternal())
            {
                if(member.GetModule() != currentModule)
                    Error(node, "cannot access internal member " + member.GetFullName() + " of another module.");
            }
        }
示例#26
0
 protected LexicalScope CreateLexicalScope(AstNode where)
 {
     return CreateLexicalScope(where, currentFunction);
 }
示例#27
0
 protected LexicalScope CreateLexicalScope(AstNode where, Function parentFunction)
 {
     LexicalScope ret = new LexicalScope(currentContainer, parentFunction);
     ret.Position = where.GetPosition();
     return ret;
 }
示例#28
0
        protected bool CheckGenericPlaceArgument(AstNode where, PlaceHolderType prototype, PlaceHolderType argument)
        {
            // Check for value type.
            if(prototype.IsValueType() && !argument.IsValueType())
                TryError(where, "expected value type argument.");

            // Get the argument top base.
            Structure topBase = currentModule.GetObjectClass();
            if(argument.IsValueType())
                topBase = currentModule.GetValueTypeClass();

            // Check for the bases.
            for(int i = 0; i < prototype.GetBaseCount(); ++i)
            {
                // Get the prototype base.
                Structure protoBase = prototype.GetBase(i);

                // Check for the top base.
                if(protoBase.IsClass() && (protoBase == topBase ||
                    topBase.IsDerivedFrom(protoBase)))
                    continue;
                else if(protoBase.IsInterface() && topBase.Implements(protoBase))
                    continue;

                // Check the argument bases until hit.
                bool found = false;
                for(int j = 0; j < argument.GetBaseCount(); ++j)
                {
                    // Get the argument base.
                    Structure argBase = argument.GetBase(j);

                    // Check the constraint.
                    if(protoBase == argBase ||
                       (protoBase.IsClass() && argBase.IsDerivedFrom(protoBase)) ||
                       (protoBase.IsInterface() && argBase.Implements(protoBase)))
                    {
                        found = true;
                        break;
                    }
                }

                // Raise the error.
                if(!found)
                    return TryError(where, "argument type {0} doesn't satisfy constraint {1}",
                        argument.GetFullName(), protoBase.GetFullName());
            }

            return true;
        }
示例#29
0
        protected bool CheckGenericArguments(AstNode where, GenericPrototype prototype, IChelaType[] arguments)
        {
            // The argument count must match.
            if(prototype.GetPlaceHolderCount() != arguments.Length)
                return TryError(where, "not matching generic argument count.");

            // Check each argument.
            for(int i = 0; i < arguments.Length; ++i)
            {
                // Get the placeholder and the type.
                PlaceHolderType placeHolder = prototype.GetPlaceHolder(i);
                IChelaType argument = arguments[i];

                // Check for value types.
                if(placeHolder.IsValueType() && !argument.IsFirstClass() && !argument.IsStructure() && !argument.IsPlaceHolderType())
                    return TryError(where, "the generic argument number {0} must be a value type.", i+1);

                // Get the argument structure.
                Structure argumentBuilding = null;
                if(argument.IsClass() || argument.IsStructure() || argument.IsInterface())
                    argumentBuilding = (Structure)argument;
                else if(argument.IsFirstClass())
                    argumentBuilding = currentModule.GetAssociatedClass(argument);
                else if(argument.IsPointer())
                {
                    // TODO: Support pointers.
                    argumentBuilding = currentModule.GetAssociatedClass(ChelaType.GetSizeType());
                }
                else if(argument.IsPlaceHolderType())
                {
                    // Check the place holder.
                    if(CheckGenericPlaceArgument(where, placeHolder, (PlaceHolderType)argument))
                        continue;
                    else
                        return false;
                }
                else
                    return TryError(where, "cannot get class for type {0}", argument.GetDisplayName());

                // Check for constraints.
                for(int j = 0; j < placeHolder.GetBaseCount(); ++j)
                {
                    // Get the base building.
                    Structure baseBuilding = placeHolder.GetBase(j);

                    // If the argument is the base pass.
                    if(argumentBuilding == baseBuilding)
                        continue;

                    // If the base is a class, check for inheritance.
                    if(baseBuilding.IsClass() && argumentBuilding.IsDerivedFrom(baseBuilding))
                        continue;

                    // If the base is a interface, check for implementation.
                    if(baseBuilding.IsInterface() && argumentBuilding.Implements(baseBuilding))
                        continue;

                    // The constraint couldn't be satisfied.
                    return TryError(where, "generic argument {0} of type {1} doesn't support constraint {2}",
                                    i+1, argumentBuilding.GetDisplayName(), baseBuilding.GetDisplayName());
                }
            }

            return true;
        }
示例#30
0
        public IChelaType ExtractActualType(AstNode where, IChelaType type)
        {
            // Extract from the meta type.
            if(!type.IsMetaType())
                Error(where, "expected a type.");
            type = ExtractMetaType(type);

            // Use the default element from the type group.
            if(type.IsTypeGroup())
            {
                TypeGroup group = (TypeGroup)type;
                Structure building = group.GetDefaultType();
                type = building;
                if(building == null)
                    Error(where, "unexpected type group {0}", @group.GetDisplayName());

                // Prevent ambiguity of merged type group.
                building.CheckAmbiguity(where.GetPosition());
            }
            return type;
        }