MCPcopy Index your code
hub / github.com/GJDuck/e9patch / parseMetadata

Function parseMetadata

src/e9patch/e9json.cpp:970–1007  ·  view source on GitHub ↗

* Parse instruction metadata. */

Source from the content-addressed store, hash-verified

968 * Parse instruction metadata.
969 */
970static Metadata *parseMetadata(Parser &parser)
971{
972 std::map<const char *, Trampoline *, CStrCmp> entries;
973
974 expectToken(parser, '{');
975 char token = expectToken2(parser, '}', TOKEN_STRING);
976 while (token != '}')
977 {
978 if (parser.s[0] != '$')
979 parse_error(parser, "failed to parse instruction metadata; "
980 "macro name must begin with a `$', found \"%s\"", parser.s);
981 auto i = entries.find(parser.s);
982 if (i != entries.end())
983 parse_error(parser, "failed to parse instruction metadata; "
984 "duplicate entry for \"%s\"", parser.s);
985 const char *name = dupString(parser.s);
986 expectToken(parser, ':');
987 Trampoline *T = parseTrampoline(parser);
988 entries.insert(std::make_pair(name, T));
989 token = expectToken2(parser, ',', '}');
990 if (token == ',')
991 token = getToken(parser);
992 }
993
994 size_t num_entries = entries.size();
995 uint8_t *ptr = new uint8_t[sizeof(Metadata) +
996 num_entries * sizeof(MetaEntry)];
997 Metadata *meta = (Metadata *)ptr;
998 meta->num_entries = num_entries;
999 size_t i = 0;
1000 for (auto pair: entries)
1001 {
1002 meta->entries[i].name = pair.first;
1003 meta->entries[i].T = pair.second;
1004 i++;
1005 }
1006 return meta;
1007}
1008
1009/*
1010 * Parse strings.

Callers 1

parseParamsFunction · 0.85

Calls 8

expectTokenFunction · 0.85
expectToken2Function · 0.85
dupStringFunction · 0.85
getTokenFunction · 0.85
parseTrampolineFunction · 0.70
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected