public IsExpression(Expression value, Expression compare, TokenPosition position) : base(position) { this.value = value; this.compare = compare; this.targetType = null; }
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; }
public SwizzleVariable(IChelaType type, Variable reference, byte mask, int comps) : base(type, null) { this.reference = reference; this.mask = mask; this.comps = comps; }
internal MatrixType(IChelaType primitiveType, int numrows, int numcolumns) { this.primitiveType = primitiveType; this.numrows = numrows; this.numcolumns = numcolumns; this.name = null; }
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); }
public IsExpression(Expression value, Expression compare, TokenPosition position) : base(position) { this.value = value; this.compare = compare; this.targetType = null; }
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); }
public SwizzleVariable(IChelaType type, Variable reference, byte mask, int comps) : base(type, null) { this.reference = reference; this.mask = mask; this.comps = comps; }
/// <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); }
public static IChelaType DeReferenceType(IChelaType type) { if(!type.IsReference()) return type; ReferenceType refType = (ReferenceType)type; return refType.GetReferencedType(); }
internal override void Read(ModuleReader reader, MemberHeader header) { // Get the module. ChelaModule module = GetModule(); // Read the type. actualType = module.GetType(reader.ReadUInt()); }
public static IChelaType DeConstType(IChelaType type) { if(type == null || !type.IsConstant()) return type; ConstantType constantType = (ConstantType)type; return constantType.GetValueType(); }
public NewExpression(Expression typeExpression, Expression arguments, TokenPosition position) : base(position) { this.typeExpression = typeExpression; this.arguments = arguments; this.constructor = null; this.objectType = null; }
public NewExpression(Expression typeExpression, Expression arguments, TokenPosition position) : base(position) { this.typeExpression = typeExpression; this.arguments = arguments; this.constructor = null; this.objectType = null; }
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; }
public static IChelaType DePointerType(IChelaType type) { if(!type.IsPointer()) return type; PointerType pointerType = (PointerType)type; return pointerType.GetPointedType(); }
internal ReferenceType(IChelaType actualType, ReferenceFlow flow, bool streamReference) { this.referencedType = actualType; this.name = null; this.fullName = null; this.referenceFlow = flow; this.streamReference = streamReference; }
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; }
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; }
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; }
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; }
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; }
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); }
public NewRawArrayExpression(Expression typeExpression, Expression size, bool heap, TokenPosition position) : base(position) { this.typeExpression = typeExpression; this.size = size; this.heap = heap; this.objectType = null; }
public NewRawArrayExpression(Expression typeExpression, Expression size, bool heap, TokenPosition position) : base(position) { this.typeExpression = typeExpression; this.size = size; this.heap = heap; this.objectType = null; }
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; }
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; }
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); }
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; }
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); }
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; }
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; }
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; }
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; }
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; }
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; }
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); }
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("}"); }
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; }
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; }
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; }
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; }
/// <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); }
/// <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)); }
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)); }
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; }
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)); }
public void SetObjectType(IChelaType objectType) { this.objectType = objectType; }
public void SetSecondCoercion(IChelaType secondCoercion) { this.secondCoercion = secondCoercion; }
public void SetOperationType(IChelaType operationType) { this.operationType = operationType; }
public void SetIndexCoercions(IChelaType[] indexCoercions) { this.indexCoercions = indexCoercions; }
public static IChelaType ExtractMetaType(IChelaType type) { MetaType metaType = (MetaType) type; return metaType.GetActualType(); }
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; }
public void SetInitCoercionType(IChelaType initCoercionType) { this.initCoercionType = initCoercionType; }
public void SetArrayType(IChelaType arrayType) { this.arrayType = arrayType; }
public ArgumentData(IChelaType argumentType, int index) { this.argumentType = argumentType; this.index = index; }
internal override void Read(ModuleReader reader, MemberHeader header) { // Get the module. ChelaModule module = GetModule(); // Read the type. actualType = module.GetType(reader.ReadUInt()); }
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; }
public void SetActualType(IChelaType actualType) { this.actualType = actualType; }
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; }