Esempio n. 1
0
 public StructureInstance(Structure template, GenericInstance instance,
                          ScopeMember factory, ChelaModule module)
     : base(module)
 {
     this.factory = factory;
     Initialize(template, instance);
 }
Esempio n. 2
0
        private void ReadData()
        {
            // Only read once the data.
            if (readedData)
            {
                return;
            }
            readedData = true;

            ModuleReader reader = new ModuleReader(new MemoryStream(rawData));

            // Get the module.
            ChelaModule module = GetModule();

            // Read the template.
            template = (Structure)module.GetMember(reader.ReadUInt());

            // Read the factory.
            factory = (Scope)module.GetMember(reader.ReadUInt());

            // Read the generic instance.
            genericInstance = GenericInstance.Read(template.GetGenericPrototype(), reader, module);

            // Initialize.
            Initialize(template, genericInstance);
            rawData = null;
        }
Esempio n. 3
0
        private void InstanceBases()
        {
            // Only instance once.
            if (instancedBases || template.IncompleteBases)
            {
                return;
            }
            instancedBases = true;

            // Full instance.
            GenericInstance fullInstance = GetFullGenericInstance();

            // Instance the base.
            Structure building = template.GetBase();

            if (building != null)
            {
                baseStructure = (Structure)building.InstanceGeneric(fullInstance, GetModule());
            }

            // Instance the interfaces.
            for (int i = 0; i < template.GetInterfaceCount(); ++i)
            {
                Structure iface = template.GetInterface(i);
                iface = (Structure)iface.InstanceGeneric(fullInstance, GetModule());
                interfaces.Add(iface);
            }
        }
Esempio n. 4
0
        public override IChelaType InstanceGeneric(GenericInstance instance, ChelaModule instanceModule)
        {
            // Instance the instance.
            GenericInstance newInstance = genericInstance.InstanceFrom(instance, instanceModule);

            // Instance the structure.
            return(template.InstanceGeneric(newInstance, instanceModule));
        }
Esempio n. 5
0
        public override ScopeMember InstanceMember(ScopeMember factory, GenericInstance instance)
        {
            // Instance the instance.
            ChelaModule     module      = factory.GetModule();
            GenericInstance newInstance = genericInstance.InstanceFrom(instance, module);

            // Instance the structure.
            return(template.InstanceMember(factory, newInstance));
        }
Esempio n. 6
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. 7
0
        public override IChelaType InstanceGeneric(GenericInstance args, ChelaModule instModule)
        {
            // Instance the return type.
            IChelaType returnType = this.returnType.InstanceGeneric(args, instModule);

            // Instance all of the parameters.
            List <IChelaType> parameters = new List <IChelaType>();

            for (int i = 0; i < arguments.Length; ++i)
            {
                IChelaType arg = arguments[i];
                parameters.Add(arg.InstanceGeneric(args, instModule));
            }

            // Return a function type with the instanced types.
            return(Create(returnType, parameters, variableArguments));
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        private void Initialize(Structure template, GenericInstance instance)
        {
            // Copy the template name and flags.
            this.name  = template.GetName();
            this.flags = template.flags;

            // Store the template and the generic instance.
            this.template        = template;
            this.genericInstance = instance;

            // Copy the prototype if this is not the final instance.
            SetGenericPrototype(template.GetGenericPrototype());

            // Use the factory
            this.parentScope = (Scope)factory;
            template.genericInstanceList.Add(this);

            // Register myself in the module.
            GetModule().RegisterGenericInstance(this);

            // Get the complete instance.
            GetFullGenericInstance();
        }
Esempio n. 11
0
 public FunctionInstance InstanceGeneric(GenericInstance genericInstance, ChelaModule instanceModule)
 {
     return(new FunctionInstance(this, genericInstance, instanceModule));
 }
Esempio n. 12
0
 public override ScopeMember InstanceMember(ScopeMember factory, GenericInstance instance)
 {
     return(null);//new FunctionGroupInstance (this, instance, factory);
 }
Esempio n. 13
0
 public override IChelaType InstanceGeneric(GenericInstance args, ChelaModule instModule)
 {
     return(Create(referencedType.InstanceGeneric(args, instModule), referenceFlow, streamReference));
 }
Esempio n. 14
0
 public virtual ScopeMember InstanceMember(ScopeMember factory, GenericInstance instance)
 {
     return(this);
 }
Esempio n. 15
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);
        }
Esempio n. 16
0
 public override IChelaType InstanceGeneric(GenericInstance args, ChelaModule instModule)
 {
     return(Create(valueType.InstanceGeneric(args, instModule)));
 }
Esempio n. 17
0
 public override ScopeMember InstanceMember(ScopeMember factory, GenericInstance instance)
 {
     return(new PropertyInstance(factory, instance, this));
 }
Esempio n. 18
0
 public override ScopeMember InstanceMember(ScopeMember factory, GenericInstance genericInstance)
 {
     return(new FunctionInstance(this, genericInstance, factory));
 }