| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // http://code.google.com/p/protobuf/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| 11 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 ValidationErrorCollector(SourceTreeDescriptorDatabase* owner); | 114 ValidationErrorCollector(SourceTreeDescriptorDatabase* owner); |
| 115 ~ValidationErrorCollector(); | 115 ~ValidationErrorCollector(); |
| 116 | 116 |
| 117 // implements ErrorCollector --------------------------------------- | 117 // implements ErrorCollector --------------------------------------- |
| 118 void AddError(const string& filename, | 118 void AddError(const string& filename, |
| 119 const string& element_name, | 119 const string& element_name, |
| 120 const Message* descriptor, | 120 const Message* descriptor, |
| 121 ErrorLocation location, | 121 ErrorLocation location, |
| 122 const string& message); | 122 const string& message); |
| 123 | 123 |
| 124 virtual void AddWarning(const string& filename, |
| 125 const string& element_name, |
| 126 const Message* descriptor, |
| 127 ErrorLocation location, |
| 128 const string& message); |
| 129 |
| 124 private: | 130 private: |
| 125 SourceTreeDescriptorDatabase* owner_; | 131 SourceTreeDescriptorDatabase* owner_; |
| 126 }; | 132 }; |
| 127 friend class ValidationErrorCollector; | 133 friend class ValidationErrorCollector; |
| 128 | 134 |
| 129 bool using_validation_error_collector_; | 135 bool using_validation_error_collector_; |
| 130 SourceLocationTable source_locations_; | 136 SourceLocationTable source_locations_; |
| 131 ValidationErrorCollector validation_error_collector_; | 137 ValidationErrorCollector validation_error_collector_; |
| 132 }; | 138 }; |
| 133 | 139 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 159 // separate Importer object to import each one (but use the same | 165 // separate Importer object to import each one (but use the same |
| 160 // DescriptorPool so that they can be cross-linked). | 166 // DescriptorPool so that they can be cross-linked). |
| 161 const FileDescriptor* Import(const string& filename); | 167 const FileDescriptor* Import(const string& filename); |
| 162 | 168 |
| 163 // The DescriptorPool in which all imported FileDescriptors and their | 169 // The DescriptorPool in which all imported FileDescriptors and their |
| 164 // contents are stored. | 170 // contents are stored. |
| 165 inline const DescriptorPool* pool() const { | 171 inline const DescriptorPool* pool() const { |
| 166 return &pool_; | 172 return &pool_; |
| 167 } | 173 } |
| 168 | 174 |
| 175 void AddUnusedImportTrackFile(const string& file_name); |
| 176 void ClearUnusedImportTrackFiles(); |
| 177 |
| 169 private: | 178 private: |
| 170 SourceTreeDescriptorDatabase database_; | 179 SourceTreeDescriptorDatabase database_; |
| 171 DescriptorPool pool_; | 180 DescriptorPool pool_; |
| 172 | 181 |
| 173 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer); | 182 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer); |
| 174 }; | 183 }; |
| 175 | 184 |
| 176 // If the importer encounters problems while trying to import the proto files, | 185 // If the importer encounters problems while trying to import the proto files, |
| 177 // it reports them to a MultiFileErrorCollector. | 186 // it reports them to a MultiFileErrorCollector. |
| 178 class LIBPROTOBUF_EXPORT MultiFileErrorCollector { | 187 class LIBPROTOBUF_EXPORT MultiFileErrorCollector { |
| 179 public: | 188 public: |
| 180 inline MultiFileErrorCollector() {} | 189 inline MultiFileErrorCollector() {} |
| 181 virtual ~MultiFileErrorCollector(); | 190 virtual ~MultiFileErrorCollector(); |
| 182 | 191 |
| 183 // Line and column numbers are zero-based. A line number of -1 indicates | 192 // Line and column numbers are zero-based. A line number of -1 indicates |
| 184 // an error with the entire file (e.g. "not found"). | 193 // an error with the entire file (e.g. "not found"). |
| 185 virtual void AddError(const string& filename, int line, int column, | 194 virtual void AddError(const string& filename, int line, int column, |
| 186 const string& message) = 0; | 195 const string& message) = 0; |
| 187 | 196 |
| 197 virtual void AddWarning(const string& filename, int line, int column, |
| 198 const string& message) {} |
| 199 |
| 188 private: | 200 private: |
| 189 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultiFileErrorCollector); | 201 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultiFileErrorCollector); |
| 190 }; | 202 }; |
| 191 | 203 |
| 192 // Abstract interface which represents a directory tree containing proto files. | 204 // Abstract interface which represents a directory tree containing proto files. |
| 193 // Used by the default implementation of Importer to resolve import statements | 205 // Used by the default implementation of Importer to resolve import statements |
| 194 // Most users will probably want to use the DiskSourceTree implementation, | 206 // Most users will probably want to use the DiskSourceTree implementation, |
| 195 // below. | 207 // below. |
| 196 class LIBPROTOBUF_EXPORT SourceTree { | 208 class LIBPROTOBUF_EXPORT SourceTree { |
| 197 public: | 209 public: |
| 198 inline SourceTree() {} | 210 inline SourceTree() {} |
| 199 virtual ~SourceTree(); | 211 virtual ~SourceTree(); |
| 200 | 212 |
| 201 // Open the given file and return a stream that reads it, or NULL if not | 213 // Open the given file and return a stream that reads it, or NULL if not |
| 202 // found. The caller takes ownership of the returned object. The filename | 214 // found. The caller takes ownership of the returned object. The filename |
| 203 // must be a path relative to the root of the source tree and must not | 215 // must be a path relative to the root of the source tree and must not |
| 204 // contain "." or ".." components. | 216 // contain "." or ".." components. |
| 205 virtual io::ZeroCopyInputStream* Open(const string& filename) = 0; | 217 virtual io::ZeroCopyInputStream* Open(const string& filename) = 0; |
| 206 | 218 |
| 219 // If Open() returns NULL, calling this method immediately will return an |
| 220 // description of the error. |
| 221 // Subclasses should implement this method and return a meaningful value for |
| 222 // better error reporting. |
| 223 // TODO(xiaofeng): change this to a pure virtual function. |
| 224 virtual string GetLastErrorMessage(); |
| 225 |
| 207 private: | 226 private: |
| 208 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); | 227 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); |
| 209 }; | 228 }; |
| 210 | 229 |
| 211 // An implementation of SourceTree which loads files from locations on disk. | 230 // An implementation of SourceTree which loads files from locations on disk. |
| 212 // Multiple mappings can be set up to map locations in the DiskSourceTree to | 231 // Multiple mappings can be set up to map locations in the DiskSourceTree to |
| 213 // locations in the physical filesystem. | 232 // locations in the physical filesystem. |
| 214 class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { | 233 class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { |
| 215 public: | 234 public: |
| 216 DiskSourceTree(); | 235 DiskSourceTree(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 DiskFileToVirtualFile(const string& disk_file, | 285 DiskFileToVirtualFile(const string& disk_file, |
| 267 string* virtual_file, | 286 string* virtual_file, |
| 268 string* shadowing_disk_file); | 287 string* shadowing_disk_file); |
| 269 | 288 |
| 270 // Given a virtual path, find the path to the file on disk. | 289 // Given a virtual path, find the path to the file on disk. |
| 271 // Return true and update disk_file with the on-disk path if the file exists. | 290 // Return true and update disk_file with the on-disk path if the file exists. |
| 272 // Return false and leave disk_file untouched if the file doesn't exist. | 291 // Return false and leave disk_file untouched if the file doesn't exist. |
| 273 bool VirtualFileToDiskFile(const string& virtual_file, string* disk_file); | 292 bool VirtualFileToDiskFile(const string& virtual_file, string* disk_file); |
| 274 | 293 |
| 275 // implements SourceTree ------------------------------------------- | 294 // implements SourceTree ------------------------------------------- |
| 276 io::ZeroCopyInputStream* Open(const string& filename); | 295 virtual io::ZeroCopyInputStream* Open(const string& filename); |
| 296 |
| 297 virtual string GetLastErrorMessage(); |
| 277 | 298 |
| 278 private: | 299 private: |
| 279 struct Mapping { | 300 struct Mapping { |
| 280 string virtual_path; | 301 string virtual_path; |
| 281 string disk_path; | 302 string disk_path; |
| 282 | 303 |
| 283 inline Mapping(const string& virtual_path_param, | 304 inline Mapping(const string& virtual_path_param, |
| 284 const string& disk_path_param) | 305 const string& disk_path_param) |
| 285 : virtual_path(virtual_path_param), disk_path(disk_path_param) {} | 306 : virtual_path(virtual_path_param), disk_path(disk_path_param) {} |
| 286 }; | 307 }; |
| 287 vector<Mapping> mappings_; | 308 vector<Mapping> mappings_; |
| 309 string last_error_message_; |
| 288 | 310 |
| 289 // Like Open(), but returns the on-disk path in disk_file if disk_file is | 311 // Like Open(), but returns the on-disk path in disk_file if disk_file is |
| 290 // non-NULL and the file could be successfully opened. | 312 // non-NULL and the file could be successfully opened. |
| 291 io::ZeroCopyInputStream* OpenVirtualFile(const string& virtual_file, | 313 io::ZeroCopyInputStream* OpenVirtualFile(const string& virtual_file, |
| 292 string* disk_file); | 314 string* disk_file); |
| 293 | 315 |
| 294 // Like Open() but given the actual on-disk path. | 316 // Like Open() but given the actual on-disk path. |
| 295 io::ZeroCopyInputStream* OpenDiskFile(const string& filename); | 317 io::ZeroCopyInputStream* OpenDiskFile(const string& filename); |
| 296 | 318 |
| 297 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); | 319 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); |
| 298 }; | 320 }; |
| 299 | 321 |
| 300 } // namespace compiler | 322 } // namespace compiler |
| 301 } // namespace protobuf | 323 } // namespace protobuf |
| 302 | 324 |
| 303 } // namespace google | 325 } // namespace google |
| 304 #endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ | 326 #endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ |
| OLD | NEW |