Beispiel #1
0
        /// <summary>
        /// Creates a new MutationCodeScope using the scope information provided.
        /// </summary>
        /// <param name="@namespace">Full type name for the code scope</param>
        /// <param name="parentNamepace">Full type name of the parent type/namespace including the namespace</param>
        /// <param name="definitionAddress">Guerilla definition address that corresponds to this code scope</param>
        /// <param name="scopeType">Type of code scope</param>
        public MutationCodeScope(string @namespace, string parentNamepace, int definitionAddress, MutationCodeScopeType scopeType)
        {
            // Initialize fields.
            this.Namespace         = @namespace;
            this.ParentNamespace   = parentNamepace;
            this.DefinitionAddress = definitionAddress;
            this.Type = scopeType;

            // Initialize field/type lists.
            this.Fields = new HashSet <string>();
            this.Types  = new Dictionary <string, MutationCodeScope>();
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new code scope for a type is one does not already exist, else it turns the existing scope for the type.
        /// </summary>
        /// <param name="typeName">Name of the type</param>
        /// <param name="definitionAddress">Guerilla definition address for the type</param>
        /// <param name="scopeType">Type of code scope to be created</param>
        /// <returns>The code scope for the type.</returns>
        public MutationCodeScope CreateCodeScopeForType(string typeName, int definitionAddress, MutationCodeScopeType scopeType)
        {
            // Check if there is an entry in the Types list with the same definition address.
            MutationCodeScope codeScope = FindExistingCodeScope(definitionAddress);

            if (codeScope != null)
            {
                // There is an existing code scope for this type so just return that.
                return(codeScope);
            }

            // Create a code safe type name for the new type.
            string            newTypeName, displayName, units, tooltip;
            EditorMarkUpFlags markupFlags;

            MutationCodeFormatter.ProcessFieldName(typeName, out newTypeName, out displayName, out units, out tooltip, out markupFlags);
            if (newTypeName == "" || MutationCodeFormatter.IsValidFieldName(newTypeName) == false)
            {
                // For now we will create a no name type for it, and I will create a preprocessing function later on.
                newTypeName = this.CreateNoNameType();
            }

            // Check if the type is an enum or flags and append the corresponding character.
            if (scopeType == MutationCodeScopeType.Bitmask)
            {
                // Append 'b' for bitmask.
                newTypeName = newTypeName.Insert(0, char.IsUpper(newTypeName[0]) == true ? "b" : "b_");
            }
            else if (scopeType == MutationCodeScopeType.Enum)
            {
                // Append 'e' for enum.
                newTypeName = newTypeName.Insert(0, char.IsUpper(newTypeName[0]) == true ? "e" : "e_");
            }

            // Check if the type name is unique or if it already exists.
            if (this.Types.Keys.Contains(newTypeName) == true)
            {
                string tempTypeName = "";

                // This shouldn't really happen, but if it does loop until we have a valid type name.
                int uniqueInt = 1;
                do
                {
                    // Append an integer to the type name to try and make it unique.
                    tempTypeName = string.Format("{0}{1}", newTypeName, uniqueInt++);
                }while (this.Types.Keys.Contains(tempTypeName) == true);

                // Save the temp type name.
                newTypeName = tempTypeName;
            }

            // Create a new code scope for this type.
            codeScope = new MutationCodeScope(newTypeName, this.Namespace, definitionAddress, scopeType);

            // Add the new type to the types dictionary.
            this.Types.Add(newTypeName, codeScope);

            // Return the new code scope for the type.
            return(codeScope);
        }