OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TOOLS_GN_INPUT_FILE_MANAGER_H_ | 5 #ifndef TOOLS_GN_INPUT_FILE_MANAGER_H_ |
6 #define TOOLS_GN_INPUT_FILE_MANAGER_H_ | 6 #define TOOLS_GN_INPUT_FILE_MANAGER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 Err* err); | 57 Err* err); |
58 | 58 |
59 // Loads and parses the given file synchronously, returning the root block | 59 // Loads and parses the given file synchronously, returning the root block |
60 // corresponding to the parsed result. On error, return NULL and the given | 60 // corresponding to the parsed result. On error, return NULL and the given |
61 // Err is set. | 61 // Err is set. |
62 const ParseNode* SyncLoadFile(const LocationRange& origin, | 62 const ParseNode* SyncLoadFile(const LocationRange& origin, |
63 const BuildSettings* build_settings, | 63 const BuildSettings* build_settings, |
64 const SourceFile& file_name, | 64 const SourceFile& file_name, |
65 Err* err); | 65 Err* err); |
66 | 66 |
| 67 // Creates an entry to manage the memory associated with keeping a parsed |
| 68 // set of code in memory. |
| 69 // |
| 70 // The values pointed to by the parameters will be filled with pointers to |
| 71 // the file, tokens, and parse node that this class created. The calling |
| 72 // code is responsible for populating these values and maintaining |
| 73 // threadsafety. This class' only job is to hold onto the memory and delete |
| 74 // it when the program exits. |
| 75 // |
| 76 // This solves the problem that sometimes we need to execute something |
| 77 // dynamic and save the result, but the values all have references to the |
| 78 // nodes and file that created it. Either we need to reset the origin of |
| 79 // the values and lose context for error reporting, or somehow keep the |
| 80 // associated parse nodes, tokens, and file data in memory. This function |
| 81 // allows the latter. |
| 82 void AddDynamicInput(InputFile** file, |
| 83 std::vector<Token>** tokens, |
| 84 scoped_ptr<ParseNode>** parse_root); |
| 85 |
| 86 // Does not count dynamic input. |
67 int GetInputFileCount() const; | 87 int GetInputFileCount() const; |
68 | 88 |
69 // Fills the vector with all input files. | 89 // Fills the vector with all input files. |
70 void GetAllPhysicalInputFileNames(std::vector<base::FilePath>* result) const; | 90 void GetAllPhysicalInputFileNames(std::vector<base::FilePath>* result) const; |
71 | 91 |
72 private: | 92 private: |
73 friend class base::RefCountedThreadSafe<InputFileManager>; | 93 friend class base::RefCountedThreadSafe<InputFileManager>; |
74 | 94 |
75 struct InputFileData { | 95 struct InputFileData { |
76 InputFileData(const SourceFile& file_name); | 96 InputFileData(const SourceFile& file_name); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 const SourceFile& name, | 131 const SourceFile& name, |
112 InputFile* file, | 132 InputFile* file, |
113 Err* err); | 133 Err* err); |
114 | 134 |
115 mutable base::Lock lock_; | 135 mutable base::Lock lock_; |
116 | 136 |
117 // Maps repo-relative filenames to the corresponding owned pointer. | 137 // Maps repo-relative filenames to the corresponding owned pointer. |
118 typedef base::hash_map<SourceFile, InputFileData*> InputFileMap; | 138 typedef base::hash_map<SourceFile, InputFileData*> InputFileMap; |
119 InputFileMap input_files_; | 139 InputFileMap input_files_; |
120 | 140 |
| 141 // Tracks all dynamic inputs. The data are holders for memory management |
| 142 // purposes and should not be read or modified by this class. The values |
| 143 // will be vended out to the code creating the dynamic input, who is in |
| 144 // charge of the threadsafety requirements. |
| 145 // |
| 146 // See AddDynamicInput(). |
| 147 // |
| 148 // Owning pointers. |
| 149 std::vector<InputFileData*> dynamic_inputs_; |
| 150 |
121 DISALLOW_COPY_AND_ASSIGN(InputFileManager); | 151 DISALLOW_COPY_AND_ASSIGN(InputFileManager); |
122 }; | 152 }; |
123 | 153 |
124 #endif // TOOLS_GN_INPUT_FILE_MANAGER_H_ | 154 #endif // TOOLS_GN_INPUT_FILE_MANAGER_H_ |
OLD | NEW |