aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/bookmaker/includeParser.cpp
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/includeParser.cpp
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/includeParser.cpp')
-rw-r--r--tools/bookmaker/includeParser.cpp94
1 files changed, 94 insertions, 0 deletions
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);