Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 5 additions & 3 deletions metadata-generator/include/IR.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class MemberDecl {

// Method overloads for TS emission (used to preserve superclass signatures).
std::vector<MemberDecl> overloads;
std::vector<std::string> overloadSignatureKeys;

void addOverloadFrom(const MemberDecl& member);
};
Expand All @@ -248,7 +249,7 @@ class ClassDecl {

ClassDecl(CXCursor cursor);

MemberDecl* getMemberNamed(std::string& name);
MemberDecl* getMemberNamed(const std::string& name);

void postProcessMembers();

Expand Down Expand Up @@ -279,7 +280,7 @@ class ProtocolDecl {

ProtocolDecl(CXCursor cursor);

MemberDecl* getMemberNamed(std::string& name);
MemberDecl* getMemberNamed(const std::string& name);

void postProcessMembers();

Expand Down Expand Up @@ -376,10 +377,11 @@ class MetadataFactory {
std::unordered_set<std::string> referencedProtocols;

std::unordered_set<std::string> renamedProtocols;
std::unordered_set<std::string> missingClasses;
std::unordered_set<std::string> missingClasses;

private:
bool _checkAvailability = false;
std::unordered_map<std::string, bool> shouldProcessCache;

std::unordered_map<std::string, EnumDecl> skippedEnums;
std::unordered_map<std::string, StructDecl> skippedStructs;
Expand Down
15 changes: 9 additions & 6 deletions metadata-generator/include/MetadataWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,22 @@ class MDSection : public std::unordered_map<MDSectionOffset, T> {
size_t section_size;
S serde;
std::unordered_map<std::string, MDSectionOffset> stringToKey;
std::vector<std::pair<MDSectionOffset, T>> orderedEntries;

MDSection(S serde) : section_offset(0), section_size(0), serde(serde) {}

inline MDSectionOffset add(T value, std::string strKey) {
if (stringToKey.contains(strKey)) {
return stringToKey[strKey];
inline MDSectionOffset add(T value, const std::string& strKey) {
auto keyIt = stringToKey.find(strKey);
if (keyIt != stringToKey.end()) {
return keyIt->second;
}
MDSectionOffset key = (MDSectionOffset)section_offset;
size_t valueSize = serde.size(value);
section_offset += valueSize;
section_size += valueSize;
this->insert(std::make_pair(key, value));
stringToKey.insert(std::make_pair(strKey, key));
this->emplace(key, value);
orderedEntries.emplace_back(key, value);
stringToKey.emplace(strKey, key);
return key;
}
};
Expand All @@ -272,7 +275,7 @@ class MDMetadataWriter {
protocols(MDProtocolSerde()), classes(MDClassSerde()),
structs(MDStructSerde()), unions(MDUnionSerde()) {}

MDTypeInfo *getTypeInfo(TypeSpec &type);
MDTypeInfo *getTypeInfo(const TypeSpec &type);

MDMember *memberFromDecl(MemberDecl &decl);

Expand Down
6 changes: 3 additions & 3 deletions metadata-generator/include/TSEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TSLines {
public:
TSLines() {}

void write(std::string value);
void write(const std::string& value);
void newline();
void enter();
void exit();
Expand Down Expand Up @@ -48,7 +48,7 @@ class TSFile {

std::string toString();

inline void import(std::string module) { imports.insert(module); }
inline void import(const std::string& module) { imports.insert(module); }

MetadataFactory *factory = nullptr;

Expand All @@ -72,7 +72,7 @@ class TSEmitter {

void resolveImports(TSFile &file);

void ensureFile(std::string framework);
TSFile& ensureFile(const std::string& framework);

void write();

Expand Down
17 changes: 10 additions & 7 deletions metadata-generator/include/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

namespace metagen {

inline std::string jsifySelector(std::string selector) {
inline std::string jsifySelector(const std::string& selector) {
std::string jsifiedSelector;
jsifiedSelector.reserve(selector.size());
bool nextupper = false;
for (auto c : selector) {
if (c == ':') {
Expand All @@ -21,29 +22,31 @@ inline std::string jsifySelector(std::string selector) {
return jsifiedSelector;
}

inline std::string jsifyName(std::string name) {
inline std::string jsifyName(const std::string& name) {
if (name == "arguments" || name == "function" || name == "DOMException") {
return name + "$";
} else {
return name;
}
}

inline std::vector<std::string> splitCamelCase(std::string value) {
inline std::vector<std::string> splitCamelCase(const std::string& value) {
std::vector<std::string> result;
result.reserve(value.size() / 4 + 1);

std::string current = "";
std::string current;
current.reserve(value.size());
for (auto c : value) {
if (isupper(c)) {
if (current != "") {
if (!current.empty()) {
result.emplace_back(current);
}
current = "";
}
current += c;
}

if (current != "") {
if (!current.empty()) {
result.emplace_back(current);
}

Expand Down Expand Up @@ -117,7 +120,7 @@ inline bool isAvailable(CXCursor cursor) {
availability == CXAvailability_Deprecated;
}

inline bool isSelectorOwned(std::string selectorName) {
inline bool isSelectorOwned(const std::string& selectorName) {
return selectorName.find("copy") == 0 ||
selectorName.find("mutableCopy") == 0 ||
selectorName.find("new") == 0 || selectorName.find("alloc") == 0;
Expand Down
Loading