[PATCH] D20076: Start porting Type records over to using classes and accessors instead of raw casting
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Mon May 9 12:00:41 PDT 2016
zturner created this revision.
zturner added reviewers: amccarth, rnk.
zturner added a subscriber: llvm-commits.
Work in progress, just want to see if people agree with the general approach
http://reviews.llvm.org/D20076
Files:
include/llvm/DebugInfo/CodeView/TypeRecord.h
Index: include/llvm/DebugInfo/CodeView/TypeRecord.h
===================================================================
--- include/llvm/DebugInfo/CodeView/TypeRecord.h
+++ include/llvm/DebugInfo/CodeView/TypeRecord.h
@@ -313,15 +313,60 @@
};
// LF_STRING_ID
-struct StringId {
- TypeIndex id;
+class StringId {
+public:
+ static ErrorOr<StringId> create(ArrayRef<uint8_t> Data) {
+ if (Data.size() < sizeof(Layout))
+ return object::make_error_code(object::object_error::parse_failed);
+ return StringId(Data);
+ }
+
+ TypeIndex getId() const {
+ return reinterpret_cast<const Layout*>(Buffer.data())->id;
+ }
+
+private:
+ StringId(ArrayRef<uint8_t> Data) : Buffer(Data) {}
+
+ struct Layout {
+ TypeIndex id;
+ };
+
+ ArrayRef<uint8_t> Buffer;
};
// LF_FUNC_ID
-struct FuncId {
- TypeIndex ParentScope;
- TypeIndex FunctionType;
- // Name: The null-terminated name follows.
+class FuncId {
+public:
+ static ErrorOr<FuncId> create(ArrayRef<uint8_t> Data) {
+ if (Data.size() < sizeof(Layout))
+ return object::make_error_code(object::object_error::parse_failed);
+ return FuncId(Data);
+ }
+
+ TypeIndex getParentScope() const {
+ return reinterpret_cast<const Layout*>(Buffer.data())->ParentScope;
+ }
+
+ TypeIndex getFunctionType() const {
+ return reinterpret_cast<const Layout*>(Buffer.data())->FunctionType;
+ }
+
+ StringRef getName() const {
+ const uint8_t *Data = Buffer.data() + sizeof(Layout);
+ return StringRef(reinterpret_cast<const char*>(Data));
+ }
+
+private:
+ FuncId(ArrayRef<uint8_t> Data) : Buffer(Data) {}
+
+ struct Layout {
+ TypeIndex ParentScope;
+ TypeIndex FunctionType;
+ // Name: The null-terminated name follows.
+ };
+
+ ArrayRef<uint8_t> Buffer;
};
// LF_CLASS, LF_STRUCTURE, LF_INTERFACE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20076.56606.patch
Type: text/x-patch
Size: 1812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160509/b8fdaefb/attachment.bin>
More information about the llvm-commits
mailing list