Reflect IndexFuncRef

This commit is contained in:
Fangrui Song 2018-02-04 17:35:16 -08:00
parent 093dbac30c
commit a8fb2264a9
2 changed files with 43 additions and 29 deletions

View File

@ -606,7 +606,7 @@ void OnIndexReference_Function(IndexFile* db,
// static
const int IndexFile::kMajorVersion = 11;
const int IndexFile::kMinorVersion = 0;
const int IndexFile::kMinorVersion = 1;
IndexFile::IndexFile(const std::string& path,
const std::string& contents)
@ -2325,3 +2325,43 @@ void ClangSanityCheck() {
std::string GetClangVersion() {
return ToString(clang_getClangVersion());
}
void Reflect(Reader& visitor, IndexFuncRef& value) {
if (visitor.Format() == SerializeFormat::Json) {
std::string s = visitor.GetString();
const char* str_value = s.c_str();
if (str_value[0] == '~') {
value.is_implicit = true;
++str_value;
}
RawId id = atol(str_value);
const char* loc_string = strchr(str_value, '@') + 1;
value.id = IndexFuncId(id);
value.loc = Range(loc_string);
} else {
Reflect(visitor, value.id);
Reflect(visitor, value.loc);
Reflect(visitor, value.is_implicit);
}
}
void Reflect(Writer& visitor, IndexFuncRef& value) {
if (visitor.Format() == SerializeFormat::Json) {
std::string s;
if (value.is_implicit)
s += "~";
// id.id is unsigned, special case -1 value
if (value.id.HasValue())
s += std::to_string(value.id.id);
else
s += "-1";
s += "@" + value.loc.ToString();
visitor.String(s.c_str());
} else {
Reflect(visitor, value.id);
Reflect(visitor, value.loc);
Reflect(visitor, value.is_implicit);
}
}

View File

@ -99,34 +99,8 @@ struct IndexFuncRef {
}
};
inline void Reflect(Reader& visitor, IndexFuncRef& value) {
std::string s = visitor.GetString();
const char* str_value = s.c_str();
if (str_value[0] == '~') {
value.is_implicit = true;
++str_value;
}
RawId id = atol(str_value);
const char* loc_string = strchr(str_value, '@') + 1;
value.id = IndexFuncId(id);
value.loc = Range(loc_string);
}
inline void Reflect(Writer& visitor, IndexFuncRef& value) {
std::string s;
if (value.is_implicit)
s += "~";
// id.id is unsigned, special case -1 value
if (value.id.HasValue())
s += std::to_string(value.id.id);
else
s += "-1";
s += "@" + value.loc.ToString();
visitor.String(s.c_str());
}
void Reflect(Reader& visitor, IndexFuncRef& value);
void Reflect(Writer& visitor, IndexFuncRef& value);
template <typename TypeId, typename FuncId, typename VarId, typename Range>
struct TypeDefDefinitionData {