Esempio n. 1
0
 public IsExpression(Expression value, Expression compare, TokenPosition position)
     : base(position)
 {
     this.value = value;
     this.compare = compare;
     this.targetType = null;
 }
Esempio n. 2
0
        private void ExpandType(TypeNameMember typeName)
        {
            // Circular references are wrong.
            AstNode typedefNode = typeName.GetTypedefNode();

            if (typeName.IsExpanding)
            {
                Error(typedefNode, "typedef with circular reference.");
            }

            // Ignore expanded types.
            IChelaType type = typeName.GetActualType();

            if (!type.IsIncompleteType())
            {
                return;
            }

            // Set the expanding flag.
            typeName.IsExpanding = true;

            // Expand the dependencies first.
            IncompleteType incomplete = (IncompleteType)type;

            foreach (TypeNameMember dep in incomplete.Dependencies)
            {
                ExpandType(dep);
            }

            // Expand the type name itself.
            ExpandTypeNode((TypedefDefinition)typedefNode, true);

            // Unset the expanding flag.
            typeName.IsExpanding = false;
        }
Esempio n. 3
0
 public SwizzleVariable(IChelaType type, Variable reference, byte mask, int comps)
     : base(type, null)
 {
     this.reference = reference;
     this.mask = mask;
     this.comps = comps;
 }
Esempio n. 4
0
 internal MatrixType(IChelaType primitiveType, int numrows, int numcolumns)
 {
     this.primitiveType = primitiveType;
     this.numrows       = numrows;
     this.numcolumns    = numcolumns;
     this.name          = null;
 }
Esempio n. 5
0
        public override AstNode Visit(FieldDeclaration node)
        {
            // Get the field.
            FieldVariable field = (FieldVariable)node.GetVariable();

            // Get the field type.
            IChelaType fieldType = field.GetVariableType();

            if (!fieldType.IsConstant() || field.IsExternal())
            {
                return(node); // Ignore not constant fields.
            }
            // Get the initializer.
            Expression initializer = node.GetDefaultValue();

            if (initializer == null)
            {
                Error(node, "constants must have initializers.");
            }

            // Don't allow multiple definitions.
            if (constants.ContainsKey(field))
            {
                Error(node, "multiples definitions of a constant.");
            }

            // Store the constant.
            ConstantData data = new ConstantData(field, initializer);

            this.constants.Add(field, data);

            // Return the node.
            return(node);
        }
Esempio n. 6
0
 public IsExpression(Expression value, Expression compare, TokenPosition position)
     : base(position)
 {
     this.value      = value;
     this.compare    = compare;
     this.targetType = null;
 }
Esempio n. 7
0
        public override AstNode Visit(MemberAccess node)
        {
            // This is the same as VariableReference implementation.
            // Get the node type.
            IChelaType variableType = node.GetNodeType();

            // Ignore type references, namespaces and functions.
            if (variableType.IsMetaType() || variableType.IsNamespace() ||
                variableType.IsFunctionGroup() || variableType.IsFunction())
            {
                return(node);
            }

            // The type must be a reference.
            variableType = DeReferenceType(variableType);

            // Now, it must be a constant.
            if (!variableType.IsConstant())
            {
                Error(node, "constant initialization can't reference no constant variables.");
            }

            // The node value, must be the constant variable.
            FieldVariable constantVar = (FieldVariable)node.GetNodeValue();

            // Find the corresponding constant data.
            ConstantData depData;

            if (constants.TryGetValue(constantVar, out depData))
            {
                currentConstant.AddDependency(depData);
            }

            return(node);
        }
Esempio n. 8
0
 public SwizzleVariable(IChelaType type, Variable reference, byte mask, int comps)
     : base(type, null)
 {
     this.reference = reference;
     this.mask      = mask;
     this.comps     = comps;
 }
Esempio n. 9
0
        /// <summary>
        /// Gets the full name.
        /// </summary>
        public override string GetFullName()
        {
            if (fullName == null)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append(returnType.GetFullName());
                builder.Append("(");

                int numargs = arguments.Length;
                for (int i = 0; i < numargs; i++)
                {
                    if (i > 0)
                    {
                        builder.Append(",");
                    }

                    if (IsVariable() && i + 1 == numargs)
                    {
                        builder.Append("params ");
                    }

                    IChelaType arg = arguments[i];
                    builder.Append(arg.GetFullName());
                }
                builder.Append(")");
                fullName = builder.ToString();
            }

            return(fullName);
        }
Esempio n. 10
0
        public static IChelaType DeReferenceType(IChelaType type)
        {
            if(!type.IsReference())
                return type;

            ReferenceType refType = (ReferenceType)type;
            return refType.GetReferencedType();
        }
Esempio n. 11
0
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Get the module.
            ChelaModule module = GetModule();

            // Read the type.
            actualType = module.GetType(reader.ReadUInt());
        }
Esempio n. 12
0
        public static IChelaType DeConstType(IChelaType type)
        {
            if(type == null || !type.IsConstant())
                return type;

            ConstantType constantType = (ConstantType)type;
            return constantType.GetValueType();
        }
Esempio n. 13
0
 public NewExpression(Expression typeExpression, Expression arguments, TokenPosition position)
     : base(position)
 {
     this.typeExpression = typeExpression;
     this.arguments = arguments;
     this.constructor = null;
     this.objectType = null;
 }
Esempio n. 14
0
 public NewExpression(Expression typeExpression, Expression arguments, TokenPosition position)
     : base(position)
 {
     this.typeExpression = typeExpression;
     this.arguments      = arguments;
     this.constructor    = null;
     this.objectType     = null;
 }
Esempio n. 15
0
 public EventVariable(string name, MemberFlags flags, IChelaType type, Scope parentScope)
     : base(type, parentScope.GetModule())
 {
     SetName(name);
     this.flags = flags;
     this.parentScope = parentScope;
     this.associatedField = null;
 }
Esempio n. 16
0
        public static IChelaType DePointerType(IChelaType type)
        {
            if(!type.IsPointer())
                return type;

            PointerType pointerType = (PointerType)type;
            return pointerType.GetPointedType();
        }
Esempio n. 17
0
 internal ReferenceType(IChelaType actualType, ReferenceFlow flow, bool streamReference)
 {
     this.referencedType  = actualType;
     this.name            = null;
     this.fullName        = null;
     this.referenceFlow   = flow;
     this.streamReference = streamReference;
 }
Esempio n. 18
0
 public PropertyVariable(string name, MemberFlags flags, IChelaType type, IChelaType[] indices, Scope parentScope)
     : base(type, parentScope.GetModule())
 {
     SetName(name);
     this.flags       = flags;
     this.indices     = indices;
     this.parentScope = parentScope;
 }
Esempio n. 19
0
 public EventVariable(string name, MemberFlags flags, IChelaType type, Scope parentScope)
     : base(type, parentScope.GetModule())
 {
     SetName(name);
     this.flags           = flags;
     this.parentScope     = parentScope;
     this.associatedField = null;
 }
Esempio n. 20
0
 public PropertyVariable(string name, MemberFlags flags, IChelaType type, IChelaType[] indices, Scope parentScope)
     : base(type, parentScope.GetModule())
 {
     SetName(name);
     this.flags = flags;
     this.indices = indices;
     this.parentScope = parentScope;
 }
Esempio n. 21
0
 internal ArrayType(IChelaType valueType, int dimensions, bool readOnly)
 {
     this.valueType   = valueType;
     this.name        = null;
     this.fullName    = null;
     this.displayName = null;
     this.dimensions  = dimensions;
     this.readOnly    = readOnly;
 }
Esempio n. 22
0
 public TypeNode(TypeKind kind, int numrows, int numcolumns, TokenPosition position)
     : base(position)
 {
     this.kind          = kind;
     this.numcomponents = 0;
     this.numrows       = numrows;
     this.numcolumns    = numcolumns;
     this.otherType     = null;
 }
Esempio n. 23
0
        public override AstNode Visit(UsingStatement node)
        {
            // Visit the using member.
            Expression member = node.GetMember();

            member.Accept(this);

            // Cast the pseudo-scope.
            PseudoScope scope = (PseudoScope)node.GetScope();

            // Get the member type.
            IChelaType memberType = member.GetNodeType();

            if (memberType.IsMetaType())
            {
                // Get the actual type.
                MetaType meta = (MetaType)memberType;
                memberType = meta.GetActualType();

                // Only structure relatives.
                if (memberType.IsStructure() || memberType.IsClass() || memberType.IsInterface())
                {
                    scope.AddAlias(memberType.GetName(), (ScopeMember)memberType);
                }
                else
                {
                    Error(node, "unexpected type.");
                }
            }
            else if (memberType.IsReference())
            {
                // Only static members supported.
                ScopeMember theMember     = (ScopeMember)member.GetNodeValue();
                MemberFlags instanceFlags = MemberFlags.InstanceMask & theMember.GetFlags();
                if (instanceFlags != MemberFlags.Static)
                {
                    Error(node, "unexpected member type.");
                }

                // Store the member.
                scope.AddAlias(theMember.GetName(), theMember);
            }
            else if (memberType.IsNamespace())
            {
                // Set the namespace chain.
                Namespace space = (Namespace)member.GetNodeValue();
                scope.SetChainNamespace(space);
            }
            else
            {
                Error(node, "unsupported object to use.");
            }

            base.Visit(node);

            return(node);
        }
Esempio n. 24
0
 public NewRawArrayExpression(Expression typeExpression, Expression size,
                              bool heap, TokenPosition position)
     : base(position)
 {
     this.typeExpression = typeExpression;
     this.size           = size;
     this.heap           = heap;
     this.objectType     = null;
 }
Esempio n. 25
0
 public NewRawArrayExpression(Expression typeExpression, Expression size,
                               bool heap, TokenPosition position)
     : base(position)
 {
     this.typeExpression = typeExpression;
     this.size = size;
     this.heap = heap;
     this.objectType = null;
 }
Esempio n. 26
0
 public TypeNameMember(ChelaModule module)
     : base(module)
 {
     this.name        = string.Empty;
     this.parentScope = null;
     this.typedefNode = null;
     this.actualType  = null;
     this.isExpanding = false;
     this.flags       = MemberFlags.Default;
 }
Esempio n. 27
0
 public BinaryAssignOperation(int operation, Expression variable, Expression value, TokenPosition position)
     : base(position)
 {
     this.operation = operation;
     this.variable = variable;
     this.value = value;
     this.pointerArithmetic = false;
     this.secondCoercion = null;
     this.overload = null;
 }
Esempio n. 28
0
        public ArgumentVariable(int index, string name, LexicalScope parentScope, IChelaType type)
            : base(type, parentScope.GetModule())
        {
            base.SetName(name);
            this.parentScope = parentScope;

            // Add the variable into the scope.
            this.index = index;
            parentScope.AddArgument(this);
        }
Esempio n. 29
0
 public BinaryAssignOperation(int operation, Expression variable, Expression value, TokenPosition position)
     : base(position)
 {
     this.operation         = operation;
     this.variable          = variable;
     this.value             = value;
     this.pointerArithmetic = false;
     this.secondCoercion    = null;
     this.overload          = null;
 }
Esempio n. 30
0
        public ArgumentVariable(int index, string name, LexicalScope parentScope, IChelaType type)
            : base(type, parentScope.GetModule())
        {
            base.SetName(name);
            this.parentScope = parentScope;

            // Add the variable into the scope.
            this.index = index;
            parentScope.AddArgument(this);
        }
Esempio n. 31
0
 protected FunctionType(IChelaType returnType, IChelaType[] arguments, bool variableArguments, MemberFlags flags)
 {
     this.returnType        = returnType;
     this.arguments         = arguments;
     this.variableArguments = variableArguments;
     this.flags             = flags;
     this.name        = null;
     this.displayName = null;
     this.fullName    = null;
 }
Esempio n. 32
0
 public FieldVariable(string name, MemberFlags flags, IChelaType type, Scope parentScope)
     : base(type, parentScope.GetModule())
 {
     SetName(name);
     this.flags       = flags;
     this.parentScope = parentScope;
     this.slot        = -1;
     this.initializer = null;
     this.position    = null;
 }
Esempio n. 33
0
 public FieldVariable(string name, MemberFlags flags, IChelaType type, Scope parentScope)
     : base(type, parentScope.GetModule())
 {
     SetName(name);
     this.flags = flags;
     this.parentScope = parentScope;
     this.slot = -1;
     this.initializer = null;
     this.position = null;
 }
Esempio n. 34
0
 public TypeNameMember(ChelaModule module)
     : base(module)
 {
     this.name = string.Empty;
     this.parentScope = null;
     this.typedefNode = null;
     this.actualType = null;
     this.isExpanding = false;
     this.flags = MemberFlags.Default;
 }
Esempio n. 35
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;
 }
Esempio n. 36
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;
 }
Esempio n. 37
0
        public GenericInstance InstanceFrom(GenericInstance instance, ChelaModule module)
        {
            IChelaType[] instancedTypes = new IChelaType[placeHolders.Length];
            for (int i = 0; i < placeHolders.Length; ++i)
            {
                instancedTypes[i] = placeHolders[i].InstanceGeneric(instance, module);
            }

            GenericInstance res = new GenericInstance(this, instancedTypes);

            return(res);
        }
Esempio n. 38
0
        public override void Dump()
        {
            IChelaType type = GetFunctionType();

            Dumper.Printf("%s method(%d) %s %s", GetFlagsString(), vslot, GetName(),
                          type != null ? type.GetFullName() : "void ()");
            Dumper.Printf("{");
            {
                DumpContent();
            }
            Dumper.Printf("}");
        }
Esempio n. 39
0
 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;
 }
Esempio n. 40
0
 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;
 }
Esempio n. 41
0
        public BinaryOperation(int operation, Expression left, Expression right,
		                        TokenPosition position)
            : base(position)
        {
            this.operation = operation;
            this.left = left;
            this.right = right;
            this.pointerArithmetic = false;
            this.secondCoercion = null;
            this.operationType = null;
            this.overload = null;
            this.matrixMul = false;
        }
Esempio n. 42
0
 public BinaryOperation(int operation, Expression left, Expression right,
                        TokenPosition position)
     : base(position)
 {
     this.operation         = operation;
     this.left              = left;
     this.right             = right;
     this.pointerArithmetic = false;
     this.secondCoercion    = null;
     this.operationType     = null;
     this.overload          = null;
     this.matrixMul         = false;
 }
Esempio n. 43
0
        /// <summary>
        /// Checks for equality with the possibility of ignore some arguments
        /// and maybe the return type.
        /// </summary>
        public bool Equals(FunctionType obj, int ignore, bool noret, bool noflags)
        {
            // Reject comparison with null, make sure the lengths are the same.
            if (obj == null ||
                arguments.Length != obj.arguments.Length ||
                variableArguments != obj.variableArguments)
            {
                return(false);
            }

            // Compare the return type.
            if (!noret && returnType != obj.returnType)
            {
                return(false);
            }

            // Compare the flags.
            if (!noflags && flags != obj.flags)
            {
                return(false);
            }

            // Compare the arguments.
            int size = arguments.Length;

            for (int i = ignore; i < size; ++i)
            {
                IChelaType leftArg  = arguments[i];
                IChelaType rightArg = obj.arguments[i];

                // Handle ref/out equality.
                if (leftArg != rightArg && leftArg != null && rightArg != null &&
                    leftArg.IsReference() && rightArg.IsReference())
                {
                    ReferenceType leftRef  = (ReferenceType)leftArg;
                    ReferenceType rightRef = (ReferenceType)rightArg;
                    leftArg  = leftRef.GetReferencedType();
                    rightArg = rightRef.GetReferencedType();
                }

                // Reject if different.
                if (leftArg != rightArg)
                {
                    return(false);
                }
            }

            // Everything is equal, return true.
            return(true);
        }
Esempio n. 44
0
        /// <summary>
        /// Create a function type with the specified parameters.
        /// </summary>
        public static FunctionType Create(IChelaType ret, IChelaType[] arguments, bool variable, MemberFlags flags)
        {
            // Use an empty array when the arguments are null.
            if (arguments == null)
            {
                arguments = new IChelaType[] {}
            }
            ;

            // First create a new function.
            FunctionType function = new FunctionType(ret, arguments, variable, flags & MemberFlags.LanguageMask);

            // Try to add it into the set.
            return(functionTypes.GetOrAdd(function));
        }
Esempio n. 45
0
        public static GenericInstance Read(GenericPrototype prototype, ModuleReader reader, ChelaModule module)
        {
            // Read the type count.
            int count = reader.ReadByte();

            // Read the types.
            IChelaType[] types = new IChelaType[count];
            for (int i = 0; i < count; ++i)
            {
                types[i] = module.GetType(reader.ReadUInt());
            }

            // Create the readed instance.
            return(new GenericInstance(prototype, types));
        }
Esempio n. 46
0
        public LocalVariable(string name, LexicalScope parentScope, IChelaType type, bool pseudoLocal)
            : base(type, parentScope.GetModule())
        {
            base.SetName(name);
            this.parentScope = parentScope;

            // Add the variable into this.
            this.isPseudoLocal = pseudoLocal;
            this.index = parentScope.AddLocal(this);
            this.argumentIndex = -1;
            this.position = null;

            // Check for generated locals.
            if(name.StartsWith("._gsym"))
                localType = LocalType.Generated;
        }
Esempio n. 47
0
        public static IChelaType Create(IChelaType primitiveType, int numcomponents)
        {
            if (numcomponents == 1)
            {
                return(primitiveType);
            }
            else if (numcomponents < 1)
            {
                throw new ModuleException("invalid vector number of components.");
            }

            // Create a new vector type.
            VectorType vector = new VectorType(primitiveType, numcomponents);

            return(vectorTypes.GetOrAdd(vector));
        }
Esempio n. 48
0
 public void SetObjectType(IChelaType objectType)
 {
     this.objectType = objectType;
 }
Esempio n. 49
0
 public void SetSecondCoercion(IChelaType secondCoercion)
 {
     this.secondCoercion = secondCoercion;
 }
Esempio n. 50
0
 public void SetOperationType(IChelaType operationType)
 {
     this.operationType = operationType;
 }
Esempio n. 51
0
 public void SetIndexCoercions(IChelaType[] indexCoercions)
 {
     this.indexCoercions = indexCoercions;
 }
Esempio n. 52
0
 public static IChelaType ExtractMetaType(IChelaType type)
 {
     MetaType metaType = (MetaType) type;
     return metaType.GetActualType();
 }
Esempio n. 53
0
        protected IChelaType FilterGenericParameter(IChelaType genericParameter)
        {
            // Remove reference.
            genericParameter = DeReferenceType(genericParameter);

            // Remove constant.
            genericParameter = DeConstType(genericParameter);

            // Remove reference, again.
            genericParameter = DeReferenceType(genericParameter);

            // Remove constant, again.
            genericParameter = DeConstType(genericParameter);

            // Return the filtered parameter.
            return genericParameter;
        }
Esempio n. 54
0
 public void SetInitCoercionType(IChelaType initCoercionType)
 {
     this.initCoercionType = initCoercionType;
 }
Esempio n. 55
0
 public void SetArrayType(IChelaType arrayType)
 {
     this.arrayType = arrayType;
 }
Esempio n. 56
0
 public ArgumentData(IChelaType argumentType, int index)
 {
     this.argumentType = argumentType;
     this.index = index;
 }
Esempio n. 57
0
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Get the module.
            ChelaModule module = GetModule();

            // Read the type.
            actualType = module.GetType(reader.ReadUInt());
        }
Esempio n. 58
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;
        }
Esempio n. 59
0
 public void SetActualType(IChelaType actualType)
 {
     this.actualType = actualType;
 }
Esempio n. 60
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;
        }