Esempio n. 1
0
        /// <summary>
        /// Finds the decl with the given name and type; returning a default version if requested.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <param name="makeDefault"> If true, a default decl of appropriate type will be created.</param>
        /// <returns>Decl with the given name or a default decl of the requested type if not found or null if makeDefault is false.</returns>
        public T FindType <T>(DeclType type, string name, bool makeDefault) where T : idDecl
        {
            if ((name == null) || (name == string.Empty))
            {
                name = "_emptyName";
            }

            idDecl decl = FindTypeWithoutParsing(type, name, makeDefault);

            if (decl == null)
            {
                return(null);
            }

            // if it hasn't been parsed yet, parse it now
            if (decl.State == DeclState.Unparsed)
            {
                decl.ParseLocal();
            }

            // mark it as referenced
            decl.ReferencedThisLevel = true;
            decl.EverReferenced      = true;

            if (_insideLevelLoad == true)
            {
                decl.ParsedOutsideLevelLoad = false;
            }

            return(decl as T);
        }
Esempio n. 2
0
        public int GetDeclCount(DeclType type)
        {
            if (_declsByType[type] == null)
            {
                idConsole.FatalError("idDeclManager::GetDeclCount: bad type: {0}", type);
            }

            return(_declsByType[type].Count);
        }
Esempio n. 3
0
        /// <summary>
        /// Registers a new decl type.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="allocator"></param>
        public void RegisterDeclType(string name, DeclType type, idDeclAllocatorBase allocator)
        {
            if (_declTypes.ContainsKey(type) == true)
            {
                idConsole.Warning("decl type '{0}' already exists", name);
            }
            else
            {
                idDeclType declType = new idDeclType();
                declType.Name      = name;
                declType.Type      = type;
                declType.Allocator = allocator;

                _declTypes.Add(type, declType);
                _declsByType.Add(type, new List <idDecl>());
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Registers a new folder with decl files.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="extension"></param>
        /// <param name="defaultType"></param>
        public void RegisterDeclFolder(string folder, string extension, DeclType defaultType)
        {
            // check whether this folder / extension combination already exists
            foreach (idDeclFolder tmp in _declFolders)
            {
                if ((StringComparer.InvariantCultureIgnoreCase.Compare(tmp.Folder, folder) == 0) &&
                    (StringComparer.InvariantCultureIgnoreCase.Compare(tmp.Extension, extension) == 0))
                {
                    idConsole.Warning("decl folder '{0}' already exists", folder);
                    return;
                }
            }

            idDeclFolder declFolder = new idDeclFolder();

            declFolder.Folder      = folder;
            declFolder.Extension   = extension;
            declFolder.DefaultType = defaultType;

            _declFolders.Add(declFolder);

            // scan for decl files
            idFileList fileList = idE.FileSystem.GetFiles(declFolder.Folder, declFolder.Extension, true);
            idDeclFile declFile = null;

            // load and parse decl files
            foreach (string file in fileList.Files)
            {
                string fileName = Path.Combine(declFolder.Folder, file);

                // check whether this file has already been loaded
                if (_loadedFiles.ContainsKey(fileName) == true)
                {
                    declFile = _loadedFiles[fileName];
                }
                else
                {
                    declFile = new idDeclFile(fileName, defaultType);
                    _loadedFiles.Add(fileName, declFile);
                }

                declFile.LoadAndParse();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This finds or creates the decl, but does not cause a parse.  This is only used internally.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <param name="makeDefault"></param>
        /// <returns></returns>
        internal idDecl FindTypeWithoutParsing(DeclType type, string name, bool makeDefault)
        {
            if (_declTypes.ContainsKey(type) == false)
            {
                idConsole.FatalError("find type without parsing: bad type {0}", type.ToString().ToLower());
            }
            else
            {
                string canonicalName = name;

                foreach (idDecl decl in _declsByType[type])
                {
                    if (decl.Name.Equals(canonicalName, StringComparison.OrdinalIgnoreCase) == true)
                    {
                        // only print these when decl_show is set to 2, because it can be a lot of clutter
                        if (idE.CvarSystem.GetInteger("decl_show") > 1)
                        {
                            MediaPrint("referencing {0} {1}", type.ToString().ToLower(), name);
                        }

                        return(decl);
                    }
                }

                if (makeDefault == true)
                {
                    idDecl newDecl = _declTypes[type].Allocator.Create();
                    newDecl.Name                   = canonicalName;
                    newDecl.Type                   = type;
                    newDecl.State                  = DeclState.Unparsed;
                    newDecl.SourceFile             = _implicitDecls;
                    newDecl.ParsedOutsideLevelLoad = !_insideLevelLoad;
                    newDecl.Index                  = _declsByType[type].Count;

                    _declsByType[type].Add(newDecl);

                    return(newDecl);
                }
            }

            return(null);
        }
Esempio n. 6
0
        public idDecl DeclByIndex(DeclType type, int index, bool forceParse)
        {
            if (_declTypes.ContainsKey(type) == false)
            {
                idConsole.FatalError("idDeclManager.DeclByIndex: bad type: {0}", type.ToString().ToLower());
            }

            if ((index < 0) || (index >= _declsByType[type].Count))
            {
                idConsole.Error("idDeclManager.DeclByIndex: out of range [{0}: {1} < {2}]", type, index, _declsByType[type].Count);
            }

            idDecl decl = _declsByType[type][index];

            if ((forceParse == true) && (decl.State == DeclState.Unparsed))
            {
                decl.ParseLocal();
            }

            return(decl);
        }
Esempio n. 7
0
 public idDeclFile(string fileName, DeclType defaultType)
 {
     _fileName    = fileName;
     _defaultType = defaultType;
 }
Esempio n. 8
0
 public idDeclFile()
 {
     _fileName    = "<implicit file>";
     _defaultType = DeclType.Unknown;
 }
Esempio n. 9
0
		public idDecl()
		{
			_name = "unnamed";
			_type = DeclType.EntityDef;
			_state = DeclState.Unparsed;
		}
Esempio n. 10
0
 public idDecl()
 {
     _name  = "unnamed";
     _type  = DeclType.EntityDef;
     _state = DeclState.Unparsed;
 }
Esempio n. 11
0
		public idDeclFile(string fileName, DeclType defaultType)
		{
			_fileName = fileName;
			_defaultType = defaultType;
		}
Esempio n. 12
0
		public idDeclFile()
		{
			_fileName = "<implicit file>";
			_defaultType = DeclType.Unknown;
		}
Esempio n. 13
0
 /// <summary>
 /// This finds or creats the decl, but does not cause a parse.  This is only used internally.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 internal idDecl FindTypeWithoutParsing(DeclType type, string name)
 {
     return(FindTypeWithoutParsing(type, name, true));
 }
Esempio n. 14
0
 /// <summary>
 /// Finds the decl with the given name and type; returning a default version if requested.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="name"></param>
 /// <param name="makeDefault"> If true, a default decl of appropriate type will be created.</param>
 /// <returns>Decl with the given name or a default decl of the requested type if not found or null if makeDefault is false.</returns>
 public idDecl FindType(DeclType type, string name, bool makeDefault)
 {
     return(FindType <idDecl>(type, name, makeDefault));
 }
Esempio n. 15
0
 /// <summary>
 /// Finds the decl with the given name and type; returning a default version if not found.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="name"></param>
 /// <returns>Decl with the given name or a default decl of the requested type if not found.</returns>
 public T FindType <T>(DeclType type, string name)  where T : idDecl
 {
     return(FindType <T>(type, name, true));
 }
Esempio n. 16
0
 /// <summary>
 /// Finds the decl with the given name and type; returning a default version if not found.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="name"></param>
 /// <returns>Decl with the given name or a default decl of the requested type if not found.</returns>
 public idDecl FindType(DeclType type, string name)
 {
     return(FindType <idDecl>(type, name));
 }
Esempio n. 17
0
 public idDecl DeclByIndex(DeclType type, int index)
 {
     return(DeclByIndex(type, index, true));
 }