Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: syzygy/refinery/types/type_repository.h

Issue 1475083002: [Refinery] Introduce TypePropagatorAnalyzer - pointer types. (Closed) Base URL: https://github.com/google/syzygy.git@master
Patch Set: Nits Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 Google Inc. All Rights Reserved. 1 // Copyright 2015 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #ifndef SYZYGY_REFINERY_TYPES_TYPE_REPOSITORY_H_ 15 #ifndef SYZYGY_REFINERY_TYPES_TYPE_REPOSITORY_H_
16 #define SYZYGY_REFINERY_TYPES_TYPE_REPOSITORY_H_ 16 #define SYZYGY_REFINERY_TYPES_TYPE_REPOSITORY_H_
17 17
18 #include <iterator> 18 #include <iterator>
19 #include <map> 19 #include <map>
20 #include <vector> 20 #include <vector>
21 21
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/containers/hash_tables.h" 23 #include "base/containers/hash_tables.h"
24 #include "base/memory/ref_counted.h" 24 #include "base/memory/ref_counted.h"
25 #include "syzygy/pe/pe_file.h"
25 26
26 namespace refinery { 27 namespace refinery {
27 28
28 typedef size_t TypeId; 29 typedef size_t TypeId;
29 class Type; 30 class Type;
30 using TypePtr = scoped_refptr<Type>; 31 using TypePtr = scoped_refptr<Type>;
31 32
32 // Keeps type instances, assigns them an ID and vends them out by ID on demand. 33 // Keeps type instances, assigns them an ID and vends them out by ID on demand.
33 // TODO(manzagop): cleave the interface so as to obtain something immutable. 34 // TODO(manzagop): cleave the interface so as to obtain something immutable.
34 class TypeRepository : public base::RefCounted<TypeRepository> { 35 class TypeRepository : public base::RefCounted<TypeRepository> {
35 public: 36 public:
36 class Iterator; 37 class Iterator;
37 38
38 TypeRepository(); 39 TypeRepository();
40 explicit TypeRepository(const pe::PEFile::Signature& signature);
Sigurður Ásgeirsson 2015/11/26 21:45:12 I think we want to abstract the module ID to somet
manzagop (departed) 2015/11/27 15:20:28 Yes, I was thinking we'd have a Signature interfac
39 41
40 // Retrieve a type by @p id. 42 // Retrieve a type by @p id.
41 TypePtr GetType(TypeId id) const; 43 TypePtr GetType(TypeId id) const;
42 44
43 // Add @p type and get its assigned id. 45 // Add @p type and get its assigned id.
44 // @pre @p type must not be in any repository. 46 // @pre @p type must not be in any repository.
45 TypeId AddType(TypePtr type); 47 TypeId AddType(TypePtr type);
46 48
47 // Add @p type and with @p id if the give id is free. 49 // Add @p type and with @p id if the give id is free.
48 // @pre @p type must not be in any repository and @p id must be free. 50 // @pre @p type must not be in any repository and @p id must be free.
49 // @returns true on success, failure typically means id is already taken. 51 // @returns true on success, failure typically means id is already taken.
50 bool AddTypeWithId(TypePtr type, TypeId id); 52 bool AddTypeWithId(TypePtr type, TypeId id);
51 53
54
55 // Get the signature for the module this type represents.
56 bool GetModuleSignature(pe::PEFile::Signature* signature);
57
52 // @name Accessors. 58 // @name Accessors.
53 // @{ 59 // @{
54 size_t size() const; 60 size_t size() const;
55 Iterator begin() const; 61 Iterator begin() const;
56 Iterator end() const; 62 Iterator end() const;
57 // @} 63 // @}
58 64
59 private: 65 private:
60 friend class base::RefCounted<TypeRepository>; 66 friend class base::RefCounted<TypeRepository>;
61 ~TypeRepository(); 67 ~TypeRepository();
62 68
69 bool is_signature_set_;
70 pe::PEFile::Signature signature_;
63 base::hash_map<TypeId, TypePtr> types_; 71 base::hash_map<TypeId, TypePtr> types_;
64 72
65 DISALLOW_COPY_AND_ASSIGN(TypeRepository); 73 DISALLOW_COPY_AND_ASSIGN(TypeRepository);
66 }; 74 };
67 75
68 class TypeRepository::Iterator 76 class TypeRepository::Iterator
69 : public std::iterator<std::input_iterator_tag, TypePtr> { 77 : public std::iterator<std::input_iterator_tag, TypePtr> {
70 public: 78 public:
71 Iterator() {} 79 Iterator() {}
72 const TypePtr& operator*() const { return it_->second; } 80 const TypePtr& operator*() const { return it_->second; }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 private: 115 private:
108 friend class base::RefCounted<TypeNameIndex>; 116 friend class base::RefCounted<TypeNameIndex>;
109 ~TypeNameIndex(); 117 ~TypeNameIndex();
110 118
111 std::multimap<base::string16, TypePtr> name_index_; 119 std::multimap<base::string16, TypePtr> name_index_;
112 }; 120 };
113 121
114 } // namespace refinery 122 } // namespace refinery
115 123
116 #endif // SYZYGY_REFINERY_TYPES_TYPE_REPOSITORY_H_ 124 #endif // SYZYGY_REFINERY_TYPES_TYPE_REPOSITORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698