Example #1
0
 public void PrepareSerialization(ChelaModule module)
 {
     // Register the placeholders
     for (int i = 0; i < placeHolders.Length; ++i)
     {
         PlaceHolderType placeHolder = placeHolders[i];
         module.RegisterType(placeHolder);
     }
 }
Example #2
0
        public void Write(ModuleWriter writer, ChelaModule module)
        {
            // Write the placeholder count.
            writer.Write((byte)placeHolders.Length);

            // Write the placeholders.
            for (int i = 0; i < placeHolders.Length; ++i)
            {
                PlaceHolderType placeHolder = placeHolders[i];
                writer.Write((uint)module.RegisterType(placeHolder));
            }
        }
Example #3
0
        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);
        }
Example #4
0
        public static GenericPrototype Read(ModuleReader reader, ChelaModule module)
        {
            byte count;
            uint placeHolder;

            // Read the place holder count;
            reader.Read(out count);

            // Read the place holders.
            PlaceHolderType[] placeHolders = new PlaceHolderType[count];
            for (int i = 0; i < count; ++i)
            {
                reader.Read(out placeHolder);
                placeHolders[i] = (PlaceHolderType)module.GetType(placeHolder);
            }

            // Return the prototype.
            return(new GenericPrototype(placeHolders));
        }