aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/bookmaker
diff options
context:
space:
mode:
authorGravatar Cary Clark <caryclark@skia.org>2018-04-26 08:32:37 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-26 17:11:53 +0000
commitd98f78cd019d96f902197711c5e7e43afec3c3de (patch)
tree376d0bae10124bc51f150a8834c1e54d989d6a7e /tools/bookmaker
parentba37e5b1c9bd24a86584a3e80347a82175a2403a (diff)
alternative no anonymous enums
Anonymous enums play havoc with documentation; there's no name to refer to. It may be that all enums may either be named or replaced with constexpr without breaking anything. Try replacing all anonymous enums in include/core to see what happens. This names SkCanvas::SaveLayerFlagsSet but leaves SkCanvas::SaveLayerFlags as a uint32_t, to reduce risk as compared to review.skia.org/123584. There's also some chance that external linkage will break if some client refers to anonymous enum in a way that could require its address: see https://stackoverflow.com/questions/22867654/enum-vs-constexpr-for-actual-static-constants-inside-classes (This CL does not require definitions + declarations) Brought bookmaker docs in line with this change. This also tripped over missing code in bookmaker handling constexpr so added that as well. R=reed@google.com,bsalomon@google.com Docs-Preview: https://skia.org/?cl=123920 Docs-Preview: https://skia.org/?cl=123584 Bug: skia:6898 Change-Id: I14a342edcfd59e139ef9e4501f562417c4c60391 Reviewed-on: https://skia-review.googlesource.com/123920 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Cary Clark <caryclark@skia.org>
Diffstat (limited to 'tools/bookmaker')
-rw-r--r--tools/bookmaker/bookmaker.h6
-rw-r--r--tools/bookmaker/includeParser.cpp94
-rw-r--r--tools/bookmaker/includeWriter.cpp2
3 files changed, 100 insertions, 2 deletions
diff --git a/tools/bookmaker/bookmaker.h b/tools/bookmaker/bookmaker.h
index 62f2faa34b..7e09d41afd 100644
--- a/tools/bookmaker/bookmaker.h
+++ b/tools/bookmaker/bookmaker.h
@@ -1010,6 +1010,7 @@ private:
};
struct IClassDefinition : public Definition {
+ unordered_map<string, Definition*> fConsts;
unordered_map<string, Definition*> fDefines;
unordered_map<string, Definition*> fEnums;
unordered_map<string, Definition*> fMembers;
@@ -1478,7 +1479,7 @@ public:
, { nullptr, MarkType::kCode }
, { nullptr, MarkType::kColumn }
, { nullptr, MarkType::kComment }
- , { nullptr, MarkType::kConst }
+ , { &fIConstMap, MarkType::kConst }
, { &fIDefineMap, MarkType::kDefine }
, { nullptr, MarkType::kDefinedBy }
, { nullptr, MarkType::kDeprecated }
@@ -1603,6 +1604,7 @@ public:
bool parseComment(string filename, const char* start, const char* end, int lineCount,
Definition* markupDef);
bool parseClass(Definition* def, IsStruct);
+ bool parseConst(Definition* child, Definition* markupDef);
bool parseDefine(Definition* child, Definition* markupDef);
bool parseEnum(Definition* child, Definition* markupDef);
@@ -1830,6 +1832,7 @@ protected:
unordered_map<string, Definition> fIncludeMap;
list<Definition> fGlobals;
unordered_map<string, IClassDefinition> fIClassMap;
+ unordered_map<string, Definition*> fIConstMap;
unordered_map<string, Definition*> fIDefineMap;
unordered_map<string, Definition*> fIEnumMap;
unordered_map<string, Definition*> fIFunctionMap;
@@ -2326,3 +2329,4 @@ private:
bool SelfCheck(const BmhParser& );
#endif
+
diff --git a/tools/bookmaker/includeParser.cpp b/tools/bookmaker/includeParser.cpp
index 982f7b3a78..ebc2384d61 100644
--- a/tools/bookmaker/includeParser.cpp
+++ b/tools/bookmaker/includeParser.cpp
@@ -466,6 +466,14 @@ bool IncludeParser::crossCheck(BmhParser& bmhParser) {
fFailed = true;
}
break;
+ case MarkType::kConst:
+ if (def) {
+ def->fVisited = true;
+ } else if (!root->fDeprecated) {
+ SkDebugf("const missing from bmh: %s\n", fullName.c_str());
+ fFailed = true;
+ }
+ break;
default:
SkASSERT(0); // unhandled
break;
@@ -1420,6 +1428,50 @@ bool IncludeParser::parseComment(string filename, const char* start, const char*
return true;
}
+bool IncludeParser::parseConst(Definition* child, Definition* markupDef) {
+ // todo: hard code to constexpr for now
+ TextParser constParser(child);
+ if (!constParser.skipExact("static")) {
+ return false;
+ }
+ constParser.skipWhiteSpace();
+ if (!constParser.skipExact("constexpr")) {
+ return false;
+ }
+ constParser.skipWhiteSpace();
+ const char* typeStart = constParser.fChar;
+ constParser.skipToSpace();
+ KeyWord constType = FindKey(typeStart, constParser.fChar);
+ if (KeyWord::kNone == constType) {
+ // todo: this could be a non-keyword, ... do we need to look for type?
+ return false;
+ }
+ constParser.skipWhiteSpace();
+ const char* nameStart = constParser.fChar;
+ constParser.skipToSpace();
+ string nameStr = string(nameStart, constParser.fChar - nameStart);
+ if (!markupDef) {
+ fGlobals.emplace_back(MarkType::kConst, child->fContentStart, child->fContentEnd,
+ child->fLineCount, fParent, '\0');
+ Definition* globalMarkupChild = &fGlobals.back();
+ string globalUniqueName = this->uniqueName(fIConstMap, nameStr);
+ globalMarkupChild->fName = globalUniqueName;
+ if (!this->findComments(*child, globalMarkupChild)) {
+ return false;
+ }
+ fIConstMap[globalUniqueName] = globalMarkupChild;
+ return true;
+ }
+ markupDef->fTokens.emplace_back(MarkType::kConst, child->fContentStart, child->fContentEnd,
+ child->fLineCount, markupDef, '\0');
+ Definition* markupChild = &markupDef->fTokens.back();
+ markupChild->fName = nameStr;
+ markupChild->fTerminator = markupChild->fContentEnd;
+ IClassDefinition& classDef = fIClassMap[markupDef->fName];
+ classDef.fConsts[nameStr] = markupChild;
+ return true;
+}
+
bool IncludeParser::parseDefine(Definition* child, Definition* markupDef) {
TextParser parser(child);
if (!parser.skipExact("#define")) {
@@ -1902,6 +1954,11 @@ bool IncludeParser::parseObject(Definition* child, Definition* markupDef) {
return false;
}
break;
+ case KeyWord::kStatic:
+ if (!this->parseConst(child, markupDef)) {
+ return child->reportError<bool>("failed to parse const or constexpr");
+ }
+ break;
case KeyWord::kEnum:
if (!this->parseEnum(child, markupDef)) {
return child->reportError<bool>("failed to parse enum");
@@ -2468,6 +2525,43 @@ bool IncludeParser::parseChar() {
fPriorEnum = priorEnum;
}
}
+ } else { // check for static constexpr not following an enum
+ // find first token on line
+ auto backTokenWalker = fParent->fTokens.end();
+ while (fParent->fTokens.begin() != backTokenWalker
+ && (fParent->fTokens.end() == backTokenWalker
+ || backTokenWalker->fStart > fLine)) {
+ std::advance(backTokenWalker, -1);
+ }
+ if (fParent->fTokens.end() != backTokenWalker
+ && backTokenWalker->fStart < fLine) {
+ std::advance(backTokenWalker, 1);
+ }
+ // look for static constexpr
+ Definition* start = &*backTokenWalker;
+ bool foundExpected = true;
+ for (KeyWord expected : {KeyWord::kStatic, KeyWord::kConstExpr}){
+ const Definition* test = &*backTokenWalker;
+ if (expected != test->fKeyWord) {
+ foundExpected = false;
+ break;
+ }
+ if (backTokenWalker == fParent->fTokens.end()) {
+ break;
+ }
+ std::advance(backTokenWalker, 1);
+ }
+ if (foundExpected) {
+ std::advance(backTokenWalker, 1);
+ const char* nameStart = backTokenWalker->fStart;
+ std::advance(backTokenWalker, 1);
+ TextParser parser(fFileName, nameStart, backTokenWalker->fStart, fLineCount);
+ parser.skipToNonAlphaNum();
+ start->fMarkType = MarkType::kConst;
+ start->fName = string(nameStart, parser.fChar - nameStart);
+ start->fContentEnd = backTokenWalker->fContentEnd;
+ fParent->fChildren.emplace_back(start);
+ }
}
}
this->addPunctuation(Punctuation::kSemicolon);
diff --git a/tools/bookmaker/includeWriter.cpp b/tools/bookmaker/includeWriter.cpp
index daf4c36145..e2ba6c67b8 100644
--- a/tools/bookmaker/includeWriter.cpp
+++ b/tools/bookmaker/includeWriter.cpp
@@ -1435,7 +1435,7 @@ bool IncludeWriter::populate(Definition* def, ParentPair* prevPair, RootDefiniti
default:
SkASSERT(0);
}
- if (KeyWord::kUint8_t == child.fKeyWord) {
+ if (KeyWord::kUint8_t == child.fKeyWord || KeyWord::kUint32_t == child.fKeyWord) {
continue;
} else {
if (fInEnum && KeyWord::kClass == child.fChildren[0]->fKeyWord) {