public Structure Find(GenericPrototype prototype) { TypeGroupName gname = new TypeGroupName(null, prototype); TypeGroupName res = types.Find(gname); if (res != null) { return(res.GetBuilding()); } return(null); }
public GenericInstance(GenericPrototype prototype, IChelaType[] parameters) { if (prototype == null) { throw new ArgumentNullException("prototype"); } this.prototype = prototype; this.parameters = parameters; this.name = null; this.fullName = null; CheckCompletion(); }
public GenericPrototype GetFullGenericPrototype() { // Return the cached generic prototype. if (fullGenericPrototype != null) { return(fullGenericPrototype); } // Get the parent full generic prototype. GenericPrototype parentFull = null; Scope parent = GetParentScope(); if (parent != null) { parentFull = parent.GetFullGenericPrototype(); } // Get my generic prototype. GenericPrototype myPrototype = GetGenericPrototype(); if (myPrototype == null || myPrototype.GetPlaceHolderCount() == 0) { fullGenericPrototype = parentFull; } else if (parentFull == null || parentFull.GetPlaceHolderCount() == 0) { fullGenericPrototype = myPrototype; } else { // Merge both prototypes int parentSize = parentFull.GetPlaceHolderCount(); int mySize = myPrototype.GetPlaceHolderCount(); PlaceHolderType[] newProto = new PlaceHolderType[parentSize + mySize]; // Add the parent prototype components. for (int i = 0; i < parentSize; ++i) { newProto[i] = parentFull.GetPlaceHolder(i); } // Add my prototype components. for (int i = 0; i < mySize; ++i) { newProto[i + parentSize] = myPrototype.GetPlaceHolder(i); } // Store the new complete generic prototype. fullGenericPrototype = new GenericPrototype(newProto); } return(fullGenericPrototype); }
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 GenericInstance(GenericPrototype prototype, List <IChelaType> parameters) { if (prototype == null) { throw new ArgumentNullException("prototype"); } // Check the parameter count. if (parameters.Count != prototype.GetPlaceHolderCount()) { throw new ModuleException("invalid generic parameter count."); } this.prototype = prototype; this.parameters = parameters.ToArray(); CheckCompletion(); }
protected Function(ChelaModule module) : base(module) { this.name = string.Empty; this.flags = MemberFlags.Default; this.parentScope = null; this.basicBlocks = new List <BasicBlock> (); this.lexicalScopes = new List <LexicalScope>(); this.locals = new List <LocalVariable> (); this.position = null; this.exceptionContext = null; this.returnBlock = null; this.returningVar = null; this.returnValueVar = null; this.genericPrototype = GenericPrototype.Empty; this.arguments = null; }
public virtual string GetFullName() { Scope parentScope = GetParentScope(); string ret = string.Empty; if (parentScope != null) { string parentFullname = parentScope.GetFullName(); if (!string.IsNullOrEmpty(parentFullname)) { ret = parentFullname + "." + GetName(); } else { ret = GetName(); } } else { ret = GetName(); } // Add the generic instance. GenericInstance instance = GetGenericInstance(); if (instance != null) { ret += instance.GetFullName(); } // Add the generic prototype. GenericPrototype proto = GetGenericPrototype(); if (proto != null && (instance == null || instance.GetParameterCount() == 0)) { ret += proto.GetFullName(); } return(ret); }
public override IChelaType InstanceGeneric(GenericInstance args, ChelaModule instModule) { GenericPrototype prototype = args.GetPrototype(); for (int i = 0; i < args.GetParameterCount(); ++i) { if (prototype.GetPlaceHolder(i) == this) { IChelaType type = args.GetParameter(i); if (type.IsPassedByReference()) { return(ReferenceType.Create(type)); } else { return(type); } } } return(this); }
internal override void Read(ModuleReader reader, MemberHeader header) { // Read the function header. FunctionHeader fheader = new FunctionHeader(); fheader.Read(reader); // Read the function type. type = (FunctionType)GetModule().GetType(fheader.functionType); // Read the generic prototype. genericPrototype = GenericPrototype.Read(reader, GetModule()); // Read the vslot. if (IsMethod()) { Method method = (Method)this; method.vslot = fheader.vslot; } // Skip the elements. reader.Skip(header.memberSize - FunctionHeader.HeaderSize - genericPrototype.GetSize()); }
public virtual Structure FindType(string name, GenericPrototype prototype) { // Find the member. ScopeMember member = FindMember(name); if (member == null) { return(null); } // Use the matching type in the type group. if (member.IsTypeGroup()) { TypeGroup group = (TypeGroup)member; return(group.Find(prototype)); } else if (!member.IsClass() && !member.IsInterface() && !member.IsStructure()) { throw new ModuleException("found no structural type " + member.GetFullName()); } // Cast the member. return((Structure)member); }
public virtual bool IsGenericImplicit() { GenericPrototype proto = GetGenericPrototype(); return(proto == null || proto.GetPlaceHolderCount() == 0); }
public GenericInstance GetFullGenericInstance() { // Return the cached instance. if (fullGenericInstance != null) { return(fullGenericInstance); } // Get the full prototype. GenericPrototype fullProto = GetFullGenericPrototype(); if (fullProto == null) { return(null); } // Get the parent full generic instance. GenericInstance parentFull = null; Scope parent = GetParentScope(); if (parent != null) { parentFull = parent.GetFullGenericInstance(); } // Get my generic instance. GenericInstance myInstance = GetGenericInstance(); if (myInstance == null || myInstance.GetParameterCount() == 0) { fullGenericInstance = parentFull; } else if (parentFull == null || parentFull.GetParameterCount() == 0) { fullGenericInstance = myInstance; } else { // Merge both instances int parentSize = parentFull.GetParameterCount(); int mySize = myInstance.GetParameterCount(); IChelaType[] newInstance = new IChelaType[parentSize + mySize]; // Add the parent prototype components. for (int i = 0; i < parentSize; ++i) { newInstance[i] = parentFull.GetParameter(i); } // Add my prototype components. for (int i = 0; i < mySize; ++i) { newInstance[i + parentSize] = myInstance.GetParameter(i); } // Store the new complete generic instance. fullGenericInstance = new GenericInstance(fullProto, newInstance); } return(fullGenericInstance); }
public void SetGenericPrototype(GenericPrototype genericPrototype) { this.genericPrototype = genericPrototype; }
public TypeGroupName(Structure building, GenericPrototype prototype) { this.prototype = prototype; this.building = building; this.isNamespaceLevel = false; }