2017-07-28 15:04:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bookmaker.h"
|
2018-01-26 17:56:22 +00:00
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkOSPath.h"
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-03-19 13:04:10 +00:00
|
|
|
const char IncludeParser::gAttrDeprecated[] = "SK_ATTR_DEPRECATED";
|
|
|
|
const size_t IncludeParser::kAttrDeprecatedLen = sizeof(gAttrDeprecated) - 1;
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
const IncludeKey kKeyWords[] = {
|
|
|
|
{ "", KeyWord::kNone, KeyProperty::kNone },
|
2017-08-29 21:36:51 +00:00
|
|
|
{ "SK_API", KeyWord::kSK_API, KeyProperty::kModifier },
|
2017-10-26 11:58:48 +00:00
|
|
|
{ "SK_BEGIN_REQUIRE_DENSE", KeyWord::kSK_BEGIN_REQUIRE_DENSE, KeyProperty::kModifier },
|
2018-08-10 17:09:13 +00:00
|
|
|
{ "alignas", KeyWord::kAlignAs, KeyProperty::kModifier },
|
2017-07-28 15:04:54 +00:00
|
|
|
{ "bool", KeyWord::kBool, KeyProperty::kNumber },
|
|
|
|
{ "char", KeyWord::kChar, KeyProperty::kNumber },
|
|
|
|
{ "class", KeyWord::kClass, KeyProperty::kObject },
|
|
|
|
{ "const", KeyWord::kConst, KeyProperty::kModifier },
|
|
|
|
{ "constexpr", KeyWord::kConstExpr, KeyProperty::kModifier },
|
|
|
|
{ "define", KeyWord::kDefine, KeyProperty::kPreprocessor },
|
|
|
|
{ "double", KeyWord::kDouble, KeyProperty::kNumber },
|
|
|
|
{ "elif", KeyWord::kElif, KeyProperty::kPreprocessor },
|
|
|
|
{ "else", KeyWord::kElse, KeyProperty::kPreprocessor },
|
|
|
|
{ "endif", KeyWord::kEndif, KeyProperty::kPreprocessor },
|
|
|
|
{ "enum", KeyWord::kEnum, KeyProperty::kObject },
|
2018-01-26 17:56:22 +00:00
|
|
|
{ "error", KeyWord::kError, KeyProperty::kPreprocessor },
|
2017-07-28 15:04:54 +00:00
|
|
|
{ "float", KeyWord::kFloat, KeyProperty::kNumber },
|
|
|
|
{ "friend", KeyWord::kFriend, KeyProperty::kModifier },
|
|
|
|
{ "if", KeyWord::kIf, KeyProperty::kPreprocessor },
|
|
|
|
{ "ifdef", KeyWord::kIfdef, KeyProperty::kPreprocessor },
|
|
|
|
{ "ifndef", KeyWord::kIfndef, KeyProperty::kPreprocessor },
|
|
|
|
{ "include", KeyWord::kInclude, KeyProperty::kPreprocessor },
|
|
|
|
{ "inline", KeyWord::kInline, KeyProperty::kModifier },
|
|
|
|
{ "int", KeyWord::kInt, KeyProperty::kNumber },
|
|
|
|
{ "operator", KeyWord::kOperator, KeyProperty::kFunction },
|
|
|
|
{ "private", KeyWord::kPrivate, KeyProperty::kClassSection },
|
|
|
|
{ "protected", KeyWord::kProtected, KeyProperty::kClassSection },
|
|
|
|
{ "public", KeyWord::kPublic, KeyProperty::kClassSection },
|
|
|
|
{ "signed", KeyWord::kSigned, KeyProperty::kNumber },
|
|
|
|
{ "size_t", KeyWord::kSize_t, KeyProperty::kNumber },
|
|
|
|
{ "static", KeyWord::kStatic, KeyProperty::kModifier },
|
|
|
|
{ "struct", KeyWord::kStruct, KeyProperty::kObject },
|
|
|
|
{ "template", KeyWord::kTemplate, KeyProperty::kObject },
|
|
|
|
{ "typedef", KeyWord::kTypedef, KeyProperty::kObject },
|
2018-06-07 13:59:07 +00:00
|
|
|
{ "typename", KeyWord::kTypename, KeyProperty::kObject },
|
2017-09-14 15:25:39 +00:00
|
|
|
{ "uint16_t", KeyWord::kUint16_t, KeyProperty::kNumber },
|
2017-07-28 15:04:54 +00:00
|
|
|
{ "uint32_t", KeyWord::kUint32_t, KeyProperty::kNumber },
|
2017-09-14 15:25:39 +00:00
|
|
|
{ "uint64_t", KeyWord::kUint64_t, KeyProperty::kNumber },
|
|
|
|
{ "uint8_t", KeyWord::kUint8_t, KeyProperty::kNumber },
|
2018-05-21 15:56:57 +00:00
|
|
|
{ "uintptr_t", KeyWord::kUintPtr_t, KeyProperty::kNumber },
|
2017-07-28 15:04:54 +00:00
|
|
|
{ "union", KeyWord::kUnion, KeyProperty::kObject },
|
|
|
|
{ "unsigned", KeyWord::kUnsigned, KeyProperty::kNumber },
|
|
|
|
{ "void", KeyWord::kVoid, KeyProperty::kNumber },
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t kKeyWordCount = SK_ARRAY_COUNT(kKeyWords);
|
|
|
|
|
|
|
|
KeyWord IncludeParser::FindKey(const char* start, const char* end) {
|
|
|
|
int ch = 0;
|
|
|
|
for (size_t index = 0; index < kKeyWordCount; ) {
|
|
|
|
if (start[ch] > kKeyWords[index].fName[ch]) {
|
|
|
|
++index;
|
|
|
|
if (ch > 0 && kKeyWords[index - 1].fName[ch - 1] < kKeyWords[index].fName[ch - 1]) {
|
|
|
|
return KeyWord::kNone;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (start[ch] < kKeyWords[index].fName[ch]) {
|
|
|
|
return KeyWord::kNone;
|
|
|
|
}
|
|
|
|
++ch;
|
|
|
|
if (start + ch >= end) {
|
2017-08-03 21:14:08 +00:00
|
|
|
if (end - start < (int) strlen(kKeyWords[index].fName)) {
|
|
|
|
return KeyWord::kNone;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
return kKeyWords[index].fKeyWord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return KeyWord::kNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeParser::ValidateKeyWords() {
|
|
|
|
for (size_t index = 1; index < kKeyWordCount; ++index) {
|
|
|
|
SkASSERT((int) kKeyWords[index - 1].fKeyWord + 1
|
|
|
|
== (int) kKeyWords[index].fKeyWord);
|
|
|
|
SkASSERT(0 > strcmp(kKeyWords[index - 1].fName, kKeyWords[index].fName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeParser::addKeyword(KeyWord keyWord) {
|
2018-03-05 18:26:16 +00:00
|
|
|
fParent->fTokens.emplace_back(keyWord, fIncludeWord, fChar, fLineCount, fParent, '\0');
|
2017-07-28 15:04:54 +00:00
|
|
|
fIncludeWord = nullptr;
|
|
|
|
if (KeyProperty::kObject == kKeyWords[(int) keyWord].fProperty) {
|
|
|
|
Definition* def = &fParent->fTokens.back();
|
|
|
|
this->addDefinition(def);
|
|
|
|
if (KeyWord::kEnum == fParent->fKeyWord) {
|
|
|
|
fInEnum = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-09 19:45:33 +00:00
|
|
|
void IncludeParser::checkForMissingParams(const vector<string>& methodParams,
|
2017-07-28 15:04:54 +00:00
|
|
|
const vector<string>& foundParams) {
|
|
|
|
for (auto& methodParam : methodParams) {
|
|
|
|
bool found = false;
|
|
|
|
for (auto& foundParam : foundParams) {
|
|
|
|
if (methodParam == foundParam) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2017-10-26 11:58:48 +00:00
|
|
|
this->writeIncompleteTag("Param", methodParam, 2);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto& foundParam : foundParams) {
|
|
|
|
bool found = false;
|
|
|
|
for (auto& methodParam : methodParams) {
|
|
|
|
if (methodParam == foundParam) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
this->reportError("doxygen param does not match method declaration");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::checkForWord() {
|
|
|
|
if (!fIncludeWord) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
KeyWord keyWord = FindKey(fIncludeWord, fChar);
|
2018-06-27 15:00:21 +00:00
|
|
|
if (KeyWord::kClass == keyWord || KeyWord::kStruct == keyWord) {
|
|
|
|
Bracket bracket = this->topBracket();
|
|
|
|
if (Bracket::kParen == bracket) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (KeyWord::kNone != keyWord) {
|
|
|
|
if (KeyProperty::kPreprocessor != kKeyWords[(int) keyWord].fProperty) {
|
|
|
|
this->addKeyword(keyWord);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this->addWord();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Definition* poundDef = fParent;
|
|
|
|
if (!fParent) {
|
|
|
|
return reportError<bool>("expected parent");
|
|
|
|
}
|
|
|
|
if (Definition::Type::kBracket != poundDef->fType) {
|
|
|
|
return reportError<bool>("expected bracket");
|
|
|
|
}
|
|
|
|
if (Bracket::kPound != poundDef->fBracket) {
|
|
|
|
return reportError<bool>("expected preprocessor");
|
|
|
|
}
|
|
|
|
if (KeyWord::kNone != poundDef->fKeyWord) {
|
|
|
|
return reportError<bool>("already found keyword");
|
|
|
|
}
|
|
|
|
poundDef->fKeyWord = keyWord;
|
|
|
|
fIncludeWord = nullptr;
|
|
|
|
switch (keyWord) {
|
|
|
|
// these do not link to other # directives
|
|
|
|
case KeyWord::kDefine:
|
2018-04-16 12:37:38 +00:00
|
|
|
if (!fInBrace) {
|
|
|
|
SkASSERT(!fInDefine);
|
|
|
|
fInDefine = true;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kInclude:
|
2018-01-26 17:56:22 +00:00
|
|
|
case KeyWord::kError:
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
// these start a # directive link
|
|
|
|
case KeyWord::kIf:
|
|
|
|
case KeyWord::kIfdef:
|
|
|
|
case KeyWord::kIfndef:
|
|
|
|
break;
|
|
|
|
// these continue a # directive link
|
|
|
|
case KeyWord::kElif:
|
|
|
|
case KeyWord::kElse: {
|
|
|
|
this->popObject(); // pop elif
|
|
|
|
if (Bracket::kPound != fParent->fBracket) {
|
|
|
|
return this->reportError<bool>("expected preprocessor directive");
|
|
|
|
}
|
|
|
|
this->popBracket(); // pop if
|
|
|
|
poundDef->fParent = fParent;
|
|
|
|
this->addDefinition(poundDef); // push elif back
|
|
|
|
} break;
|
|
|
|
// this ends a # directive link
|
|
|
|
case KeyWord::kEndif:
|
|
|
|
// FIXME : should this be calling popBracket() instead?
|
|
|
|
this->popObject(); // pop endif
|
|
|
|
if (Bracket::kPound != fParent->fBracket) {
|
|
|
|
return this->reportError<bool>("expected preprocessor directive");
|
|
|
|
}
|
|
|
|
this->popBracket(); // pop if/else
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
string IncludeParser::className() const {
|
|
|
|
string name(fParent->fName);
|
|
|
|
size_t slash = name.find_last_of("/");
|
|
|
|
if (string::npos == slash) {
|
|
|
|
slash = name.find_last_of("\\");
|
|
|
|
}
|
|
|
|
SkASSERT(string::npos != slash);
|
|
|
|
string result = name.substr(slash);
|
|
|
|
result = result.substr(1, result.size() - 3);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-10-11 14:37:52 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
bool IncludeParser::crossCheck(BmhParser& bmhParser) {
|
|
|
|
for (auto& classMapper : fIClassMap) {
|
2017-10-11 14:37:52 +00:00
|
|
|
string className = classMapper.first;
|
|
|
|
auto finder = bmhParser.fClassMap.find(className);
|
|
|
|
if (bmhParser.fClassMap.end() == finder) {
|
|
|
|
SkASSERT(string::npos != className.find("::"));
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-10-11 14:37:52 +00:00
|
|
|
RootDefinition* root = &finder->second;
|
|
|
|
root->clearVisited();
|
|
|
|
}
|
|
|
|
for (auto& classMapper : fIClassMap) {
|
|
|
|
string className = classMapper.first;
|
|
|
|
std::istringstream iss(className);
|
|
|
|
string classStr;
|
|
|
|
string classBase;
|
|
|
|
RootDefinition* root = nullptr;
|
|
|
|
while (std::getline(iss, classStr, ':')) {
|
|
|
|
if (root) {
|
|
|
|
if (!classStr.length()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
classBase += "::" + classStr;
|
|
|
|
auto finder = root->fBranches.find(classBase);
|
|
|
|
if (root->fBranches.end() != finder) {
|
|
|
|
root = finder->second;
|
|
|
|
} else {
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
classBase = classStr;
|
|
|
|
auto finder = bmhParser.fClassMap.find(classBase);
|
|
|
|
if (bmhParser.fClassMap.end() != finder) {
|
|
|
|
root = &finder->second;
|
|
|
|
} else {
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
auto& classMap = classMapper.second;
|
|
|
|
auto& tokens = classMap.fTokens;
|
|
|
|
for (const auto& token : tokens) {
|
|
|
|
if (token.fPrivate) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
string fullName = classMapper.first + "::" + token.fName;
|
2017-09-01 19:51:02 +00:00
|
|
|
const Definition* def = root->find(fullName, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
switch (token.fMarkType) {
|
|
|
|
case MarkType::kMethod: {
|
2018-04-16 12:37:38 +00:00
|
|
|
if (this->isInternalName(token)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!def) {
|
|
|
|
string paramName = className + "::";
|
|
|
|
paramName += string(token.fContentStart,
|
|
|
|
token.fContentEnd - token.fContentStart);
|
2018-06-28 12:50:35 +00:00
|
|
|
if (string::npos != paramName.find('\n')) {
|
|
|
|
paramName.erase(std::remove(paramName.begin(), paramName.end(), '\n'),
|
|
|
|
paramName.end());
|
|
|
|
}
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(paramName, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!def && 0 == token.fName.find("operator")) {
|
|
|
|
string operatorName = className + "::";
|
|
|
|
TextParser oper("", token.fStart, token.fContentEnd, 0);
|
|
|
|
const char* start = oper.strnstr("operator", token.fContentEnd);
|
|
|
|
SkASSERT(start);
|
|
|
|
oper.skipTo(start);
|
|
|
|
oper.skipToEndBracket('(');
|
|
|
|
int parens = 0;
|
|
|
|
do {
|
|
|
|
if ('(' == oper.peek()) {
|
|
|
|
++parens;
|
|
|
|
} else if (')' == oper.peek()) {
|
|
|
|
--parens;
|
|
|
|
}
|
|
|
|
} while (!oper.eof() && oper.next() && parens > 0);
|
|
|
|
operatorName += string(start, oper.fChar - start);
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(operatorName, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!def) {
|
|
|
|
int skip = !strncmp(token.fContentStart, "explicit ", 9) ? 9 : 0;
|
|
|
|
skip = !strncmp(token.fContentStart, "virtual ", 8) ? 8 : skip;
|
2018-07-12 20:24:53 +00:00
|
|
|
const char* tokenEnd = token.methodEnd();
|
2017-07-28 15:04:54 +00:00
|
|
|
string constructorName = className + "::";
|
|
|
|
constructorName += string(token.fContentStart + skip,
|
2018-07-12 20:24:53 +00:00
|
|
|
tokenEnd - token.fContentStart - skip);
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(constructorName, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (!def && 0 == token.fName.find("SK_")) {
|
|
|
|
string incName = token.fName + "()";
|
|
|
|
string macroName = className + "::" + incName;
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(macroName, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (def) {
|
|
|
|
if (def->fName == incName) {
|
|
|
|
def->fVisited = true;
|
|
|
|
if ("SK_TO_STRING_NONVIRT" == token.fName) {
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(className + "::toString",
|
|
|
|
RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (def) {
|
|
|
|
def->fVisited = true;
|
|
|
|
} else {
|
|
|
|
SkDebugf("missing toString bmh: %s\n", fullName.c_str());
|
2017-12-20 19:53:21 +00:00
|
|
|
fFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
SkDebugf("method macro differs from bmh: %s\n", fullName.c_str());
|
2017-12-20 19:53:21 +00:00
|
|
|
fFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!def) {
|
|
|
|
bool allLower = true;
|
|
|
|
for (size_t index = 0; index < token.fName.length(); ++index) {
|
|
|
|
if (!islower(token.fName[index])) {
|
|
|
|
allLower = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allLower) {
|
|
|
|
string lowerName = className + "::" + token.fName + "()";
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(lowerName, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-29 21:36:51 +00:00
|
|
|
if (!def) {
|
2018-03-19 13:04:10 +00:00
|
|
|
if (gAttrDeprecated == token.fName) {
|
|
|
|
fAttrDeprecated = &token;
|
2017-08-29 21:36:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (0 == token.fName.find("SkDEBUGCODE")) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!def) {
|
|
|
|
// simple method names inside nested classes have a bug and are missing trailing parens
|
|
|
|
string withParens = fullName + "()"; // FIXME: this shouldn't be necessary
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(withParens, RootDefinition::AllowParens::kNo);
|
2017-08-29 21:36:51 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!def) {
|
2018-02-08 19:45:18 +00:00
|
|
|
if (!root->fDeprecated) {
|
|
|
|
SkDebugf("method missing from bmh: %s\n", fullName.c_str());
|
|
|
|
fFailed = true;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-08-29 21:36:51 +00:00
|
|
|
if (def->crossCheck2(token)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
def->fVisited = true;
|
2018-03-19 13:04:10 +00:00
|
|
|
if (token.fDeprecated && !def->fDeprecated) {
|
|
|
|
fFailed = !def->reportError<bool>("expect bmh to be marked deprecated");
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
|
|
|
SkDebugf("method differs from bmh: %s\n", fullName.c_str());
|
2017-12-20 19:53:21 +00:00
|
|
|
fFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case MarkType::kComment:
|
|
|
|
break;
|
2017-08-24 16:59:48 +00:00
|
|
|
case MarkType::kEnumClass:
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kEnum: {
|
|
|
|
if (!def) {
|
|
|
|
// work backwards from first word to deduce #Enum name
|
|
|
|
TextParser firstMember("", token.fStart, token.fContentEnd, 0);
|
|
|
|
SkAssertResult(firstMember.skipName("enum"));
|
|
|
|
SkAssertResult(firstMember.skipToEndBracket('{'));
|
|
|
|
firstMember.next();
|
|
|
|
firstMember.skipWhiteSpace();
|
|
|
|
SkASSERT('k' == firstMember.peek());
|
|
|
|
const char* savePos = firstMember.fChar;
|
2018-04-16 12:37:38 +00:00
|
|
|
firstMember.skipToNonName();
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* wordEnd = firstMember.fChar;
|
2017-10-09 19:45:33 +00:00
|
|
|
firstMember.fChar = savePos;
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* lastUnderscore = nullptr;
|
|
|
|
do {
|
|
|
|
if (!firstMember.skipToEndBracket('_')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (firstMember.fChar > wordEnd) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lastUnderscore = firstMember.fChar;
|
|
|
|
} while (firstMember.next());
|
|
|
|
if (lastUnderscore) {
|
|
|
|
++lastUnderscore;
|
2017-10-09 19:45:33 +00:00
|
|
|
string anonName = className + "::" + string(lastUnderscore,
|
2017-07-28 15:04:54 +00:00
|
|
|
wordEnd - lastUnderscore) + 's';
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(anonName, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (!def) {
|
2018-02-08 19:45:18 +00:00
|
|
|
if (!root->fDeprecated) {
|
|
|
|
SkDebugf("enum missing from bmh: %s\n", fullName.c_str());
|
|
|
|
fFailed = true;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
def->fVisited = true;
|
|
|
|
for (auto& child : def->fChildren) {
|
|
|
|
if (MarkType::kCode == child->fMarkType) {
|
|
|
|
def = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (MarkType::kCode != def->fMarkType) {
|
2018-02-08 19:45:18 +00:00
|
|
|
if (!root->fDeprecated) {
|
|
|
|
SkDebugf("enum code missing from bmh: %s\n", fullName.c_str());
|
|
|
|
fFailed = true;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (def->crossCheck(token)) {
|
|
|
|
def->fVisited = true;
|
|
|
|
} else {
|
2017-12-20 19:53:21 +00:00
|
|
|
SkDebugf("enum differs from bmh: %s\n", def->fName.c_str());
|
|
|
|
fFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
for (auto& child : token.fChildren) {
|
2017-08-24 16:59:48 +00:00
|
|
|
string constName = MarkType::kEnumClass == token.fMarkType ?
|
|
|
|
fullName : className;
|
|
|
|
constName += "::" + child->fName;
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(constName, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!def) {
|
|
|
|
string innerName = classMapper.first + "::" + child->fName;
|
2017-09-01 19:51:02 +00:00
|
|
|
def = root->find(innerName, RootDefinition::AllowParens::kYes);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (!def) {
|
|
|
|
if (string::npos == child->fName.find("Legacy_")) {
|
2018-02-08 19:45:18 +00:00
|
|
|
if (!root->fDeprecated) {
|
|
|
|
SkDebugf("const missing from bmh: %s\n", constName.c_str());
|
|
|
|
fFailed = true;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
def->fVisited = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case MarkType::kMember:
|
|
|
|
if (def) {
|
|
|
|
def->fVisited = true;
|
2018-02-08 19:45:18 +00:00
|
|
|
} else if (!root->fDeprecated) {
|
2017-07-28 15:04:54 +00:00
|
|
|
SkDebugf("member missing from bmh: %s\n", fullName.c_str());
|
2017-12-20 19:53:21 +00:00
|
|
|
fFailed = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-12-11 21:03:17 +00:00
|
|
|
case MarkType::kTypedef:
|
|
|
|
if (def) {
|
|
|
|
def->fVisited = true;
|
2018-02-08 19:45:18 +00:00
|
|
|
} else if (!root->fDeprecated) {
|
2017-12-11 21:03:17 +00:00
|
|
|
SkDebugf("typedef missing from bmh: %s\n", fullName.c_str());
|
2017-12-20 19:53:21 +00:00
|
|
|
fFailed = true;
|
2017-12-11 21:03:17 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-04-26 12:32:37 +00:00
|
|
|
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;
|
2017-07-28 15:04:54 +00:00
|
|
|
default:
|
2017-10-09 19:45:33 +00:00
|
|
|
SkASSERT(0); // unhandled
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
int crossChecks = 0;
|
|
|
|
string firstCheck;
|
2017-10-11 14:37:52 +00:00
|
|
|
for (auto& classMapper : fIClassMap) {
|
|
|
|
string className = classMapper.first;
|
|
|
|
auto finder = bmhParser.fClassMap.find(className);
|
|
|
|
if (bmhParser.fClassMap.end() == finder) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
RootDefinition* root = &finder->second;
|
2018-01-05 17:10:09 +00:00
|
|
|
if (!root->dumpUnVisited()) {
|
2017-12-20 19:53:21 +00:00
|
|
|
fFailed = true;
|
2017-10-11 14:37:52 +00:00
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
if (crossChecks) {
|
|
|
|
SkDebugf(".");
|
|
|
|
} else {
|
|
|
|
SkDebugf("cross-check");
|
|
|
|
firstCheck = className;
|
|
|
|
}
|
|
|
|
++crossChecks;
|
|
|
|
}
|
|
|
|
if (crossChecks) {
|
|
|
|
if (1 == crossChecks) {
|
2018-02-08 19:45:18 +00:00
|
|
|
SkDebugf(" %s", firstCheck.c_str());
|
2018-01-04 21:11:51 +00:00
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-09-14 15:25:39 +00:00
|
|
|
bmhParser.fWroteOut = true;
|
2017-12-20 19:53:21 +00:00
|
|
|
return !fFailed;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IClassDefinition* IncludeParser::defineClass(const Definition& includeDef,
|
2018-04-16 12:37:38 +00:00
|
|
|
string name) {
|
2017-07-28 15:04:54 +00:00
|
|
|
string className;
|
|
|
|
const Definition* test = fParent;
|
|
|
|
while (Definition::Type::kFileType != test->fType) {
|
|
|
|
if (Definition::Type::kMark == test->fType && KeyWord::kClass == test->fKeyWord) {
|
|
|
|
className = test->fName + "::";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
test = test->fParent;
|
|
|
|
}
|
2017-10-09 19:45:33 +00:00
|
|
|
className += name;
|
2017-07-28 15:04:54 +00:00
|
|
|
unordered_map<string, IClassDefinition>& map = fIClassMap;
|
|
|
|
IClassDefinition& markupDef = map[className];
|
|
|
|
if (markupDef.fStart) {
|
|
|
|
typedef IClassDefinition* IClassDefPtr;
|
|
|
|
return INHERITED::reportError<IClassDefPtr>("class already defined");
|
|
|
|
}
|
|
|
|
markupDef.fFileName = fFileName;
|
|
|
|
markupDef.fStart = includeDef.fStart;
|
|
|
|
markupDef.fContentStart = includeDef.fStart;
|
|
|
|
markupDef.fName = className;
|
|
|
|
markupDef.fContentEnd = includeDef.fContentEnd;
|
|
|
|
markupDef.fTerminator = includeDef.fTerminator;
|
|
|
|
markupDef.fParent = fParent;
|
|
|
|
markupDef.fLineCount = fLineCount;
|
|
|
|
markupDef.fMarkType = KeyWord::kStruct == includeDef.fKeyWord ?
|
|
|
|
MarkType::kStruct : MarkType::kClass;
|
|
|
|
markupDef.fKeyWord = includeDef.fKeyWord;
|
|
|
|
markupDef.fType = Definition::Type::kMark;
|
|
|
|
fParent = &markupDef;
|
|
|
|
return &markupDef;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeParser::dumpClassTokens(IClassDefinition& classDef) {
|
|
|
|
auto& tokens = classDef.fTokens;
|
|
|
|
for (auto& token : tokens) {
|
|
|
|
if (Definition::Type::kMark == token.fType && MarkType::kComment == token.fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (MarkType::kMember != token.fMarkType) {
|
2018-04-16 12:37:38 +00:00
|
|
|
this->writeBlockSeparator();
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
switch (token.fMarkType) {
|
2018-06-27 15:00:21 +00:00
|
|
|
case MarkType::kConst:
|
|
|
|
this->dumpConst(token, classDef.fName);
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case MarkType::kEnum:
|
2017-11-27 15:44:06 +00:00
|
|
|
case MarkType::kEnumClass:
|
2018-01-26 17:56:22 +00:00
|
|
|
this->dumpEnum(token, token.fName);
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
case MarkType::kMethod:
|
2018-04-16 12:37:38 +00:00
|
|
|
this->dumpMethod(token, classDef.fName);
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
case MarkType::kMember:
|
2017-09-19 21:39:32 +00:00
|
|
|
this->dumpMember(token);
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
break;
|
2018-08-10 17:09:13 +00:00
|
|
|
case MarkType::kTypedef:
|
|
|
|
this->dumpTypedef(token, classDef.fName);
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
this->dumpCommonTail(token);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
void IncludeParser::dumpComment(const Definition& token) {
|
|
|
|
fLineCount = token.fLineCount;
|
|
|
|
fChar = fLine = token.fContentStart;
|
|
|
|
fEnd = token.fContentEnd;
|
2017-07-28 15:04:54 +00:00
|
|
|
bool sawParam = false;
|
|
|
|
bool multiline = false;
|
|
|
|
bool sawReturn = false;
|
|
|
|
bool sawComment = false;
|
|
|
|
bool methodHasReturn = false;
|
|
|
|
vector<string> methodParams;
|
|
|
|
vector<string> foundParams;
|
|
|
|
Definition methodName;
|
2017-09-19 21:39:32 +00:00
|
|
|
TextParser methodParser(token.fFileName, token.fContentStart, token.fContentEnd,
|
|
|
|
token.fLineCount);
|
2018-01-26 17:56:22 +00:00
|
|
|
bool debugCode = methodParser.skipExact("SkDEBUGCODE(");
|
2017-09-19 21:39:32 +00:00
|
|
|
if (MarkType::kMethod == token.fMarkType) {
|
2018-01-26 17:56:22 +00:00
|
|
|
methodName.fName = debugCode ? token.fName : string(token.fContentStart,
|
2017-09-19 21:39:32 +00:00
|
|
|
(int) (token.fContentEnd - token.fContentStart));
|
2017-07-28 15:04:54 +00:00
|
|
|
methodHasReturn = !methodParser.startsWith("void ")
|
2017-11-27 15:44:06 +00:00
|
|
|
&& !methodParser.startsWith("static void ")
|
2017-07-28 15:04:54 +00:00
|
|
|
&& !methodParser.strnchr('~', methodParser.fEnd);
|
|
|
|
const char* paren = methodParser.strnchr('(', methodParser.fEnd);
|
|
|
|
const char* nextEnd = paren;
|
|
|
|
do {
|
|
|
|
string paramName;
|
|
|
|
methodParser.fChar = nextEnd + 1;
|
|
|
|
methodParser.skipSpace();
|
|
|
|
if (!methodName.nextMethodParam(&methodParser, &nextEnd, ¶mName)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
methodParams.push_back(paramName);
|
|
|
|
} while (')' != nextEnd[0]);
|
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
for (const auto& child : token.fTokens) {
|
|
|
|
if (Definition::Type::kMark == child.fType && MarkType::kMember == child.fMarkType) {
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (Definition::Type::kMark == child.fType && MarkType::kComment == child.fMarkType) {
|
2017-09-19 21:39:32 +00:00
|
|
|
if (child.fPrivate) {
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if ('@' == child.fContentStart[0]) {
|
|
|
|
TextParser parser(&child);
|
|
|
|
do {
|
|
|
|
parser.next();
|
|
|
|
if (parser.startsWith("param ")) {
|
|
|
|
parser.skipWord("param");
|
|
|
|
const char* parmStart = parser.fChar;
|
|
|
|
parser.skipToSpace();
|
|
|
|
string parmName = string(parmStart, (int) (parser.fChar - parmStart));
|
|
|
|
parser.skipWhiteSpace();
|
|
|
|
do {
|
|
|
|
size_t nextComma = parmName.find(',');
|
|
|
|
string piece;
|
|
|
|
if (string::npos == nextComma) {
|
|
|
|
piece = parmName;
|
|
|
|
parmName = "";
|
|
|
|
} else {
|
|
|
|
piece = parmName.substr(0, nextComma);
|
|
|
|
parmName = parmName.substr(nextComma + 1);
|
|
|
|
}
|
|
|
|
if (sawParam) {
|
|
|
|
if (multiline) {
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(1);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeEndTag();
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
|
|
|
if (sawComment) {
|
|
|
|
this->nl();
|
|
|
|
}
|
|
|
|
this->lf(2);
|
|
|
|
}
|
|
|
|
foundParams.emplace_back(piece);
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeTag("Param", piece);
|
|
|
|
this->writeSpace(2);
|
|
|
|
this->writeBlock(parser.fEnd - parser.fChar, parser.fChar);
|
|
|
|
this->lf(1);
|
2017-07-28 15:04:54 +00:00
|
|
|
sawParam = true;
|
|
|
|
sawComment = false;
|
|
|
|
} while (parmName.length());
|
|
|
|
parser.skipTo(parser.fEnd);
|
|
|
|
} else if (parser.startsWith("return ") || parser.startsWith("returns ")) {
|
|
|
|
parser.skipWord("return");
|
|
|
|
if ('s' == parser.peek()) {
|
|
|
|
parser.next();
|
|
|
|
}
|
|
|
|
if (sawParam) {
|
|
|
|
if (multiline) {
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(1);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeEndTag();
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
this->checkForMissingParams(methodParams, foundParams);
|
|
|
|
sawParam = false;
|
|
|
|
sawComment = false;
|
|
|
|
multiline = false;
|
|
|
|
this->lf(2);
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeTag("Return");
|
|
|
|
this->writeSpace(2);
|
|
|
|
this->writeBlock(parser.fEnd - parser.fChar, parser.fChar);
|
|
|
|
this->lf(1);
|
2017-07-28 15:04:54 +00:00
|
|
|
sawReturn = true;
|
|
|
|
parser.skipTo(parser.fEnd);
|
|
|
|
} else {
|
|
|
|
this->reportError("unexpected doxygen directive");
|
|
|
|
}
|
|
|
|
} while (!parser.eof());
|
2017-09-19 21:39:32 +00:00
|
|
|
} else if (child.length() > 1) {
|
|
|
|
const char* start = child.fContentStart;
|
|
|
|
ptrdiff_t length = child.fContentEnd - start;
|
|
|
|
SkASSERT(length >= 0);
|
|
|
|
while (length && '/' == start[0]) {
|
|
|
|
start += 1;
|
|
|
|
--length;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
while (length && '/' == start[length - 1]) {
|
|
|
|
length -= 1;
|
|
|
|
if (length && '*' == start[length - 1]) {
|
|
|
|
length -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (length) {
|
|
|
|
this->lfAlways(sawComment || sawParam || sawReturn ? 1 : 2);
|
|
|
|
if (sawParam || sawReturn) {
|
|
|
|
this->indentToColumn(8);
|
|
|
|
}
|
|
|
|
this->writeBlock(length, start);
|
|
|
|
this->writeSpace();
|
|
|
|
sawComment = true;
|
|
|
|
if (sawParam || sawReturn) {
|
|
|
|
multiline = true;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sawParam || sawReturn) {
|
|
|
|
if (multiline) {
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(1);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeEndTag();
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (!sawReturn) {
|
|
|
|
if (!sawParam) {
|
|
|
|
if (sawComment) {
|
|
|
|
this->nl();
|
|
|
|
}
|
|
|
|
this->lf(2);
|
|
|
|
}
|
|
|
|
this->checkForMissingParams(methodParams, foundParams);
|
|
|
|
}
|
|
|
|
if (methodHasReturn != sawReturn) {
|
|
|
|
if (!methodHasReturn) {
|
|
|
|
this->reportError("unexpected doxygen return");
|
|
|
|
} else {
|
|
|
|
if (sawComment) {
|
|
|
|
this->nl();
|
|
|
|
}
|
|
|
|
this->lf(2);
|
2017-10-26 11:58:48 +00:00
|
|
|
this->writeIncompleteTag("Return");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
void IncludeParser::dumpCommonTail(const Definition& token) {
|
|
|
|
this->lf(2);
|
|
|
|
this->writeTag("Example");
|
|
|
|
this->lf(1);
|
|
|
|
this->writeString("// incomplete");
|
|
|
|
this->lf(1);
|
|
|
|
this->writeEndTag();
|
|
|
|
this->lf(2);
|
|
|
|
this->writeTag("SeeAlso");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString("incomplete");
|
|
|
|
this->lf(2);
|
|
|
|
this->writeEndTag(BmhParser::kMarkProps[(int) token.fMarkType].fName);
|
|
|
|
this->lf(2);
|
|
|
|
}
|
|
|
|
|
2018-06-27 15:00:21 +00:00
|
|
|
void IncludeParser::dumpConst(const Definition& token, string className) {
|
|
|
|
this->writeTag("Const");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(token.fName);
|
|
|
|
this->writeTagTable("Line", "incomplete");
|
|
|
|
this->lf(2);
|
|
|
|
this->dumpComment(token);
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
void IncludeParser::dumpDefine(const Definition& token) {
|
|
|
|
this->writeTag("Define", token.fName);
|
|
|
|
this->lf(2);
|
|
|
|
this->writeTag("Code");
|
|
|
|
this->lfAlways(1);
|
|
|
|
this->writeString("###$");
|
|
|
|
this->lfAlways(1);
|
|
|
|
this->indentToColumn(4);
|
|
|
|
this->writeBlock(token.fTerminator - token.fStart, token.fStart);
|
|
|
|
this->lf(1);
|
|
|
|
this->indentToColumn(0);
|
|
|
|
this->writeString("$$$#");
|
|
|
|
|
|
|
|
this->writeEndTag();
|
|
|
|
this->lf(2);
|
|
|
|
this->dumpComment(token);
|
|
|
|
for (auto& child : token.fTokens) {
|
|
|
|
if (MarkType::kComment == child.fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
this->writeTag("Param", child.fName);
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString("incomplete");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString("##");
|
|
|
|
this->lf(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeParser::dumpEnum(const Definition& token, string name) {
|
2018-01-26 17:56:22 +00:00
|
|
|
this->writeTag("Enum", name);
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(2);
|
2018-04-16 12:37:38 +00:00
|
|
|
this->writeTag("Code");
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lfAlways(1);
|
|
|
|
this->indentToColumn(4);
|
|
|
|
this->writeString("enum");
|
|
|
|
this->writeSpace();
|
|
|
|
if ("_anonymous" != token.fName.substr(0, 10)) {
|
|
|
|
this->writeString(token.fName);
|
|
|
|
this->writeSpace();
|
|
|
|
}
|
|
|
|
this->writeString("{");
|
|
|
|
this->lfAlways(1);
|
|
|
|
for (auto& child : token.fChildren) {
|
|
|
|
this->indentToColumn(8);
|
|
|
|
this->writeString(child->fName);
|
|
|
|
if (child->length()) {
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeBlock(child->length(), child->fContentStart);
|
|
|
|
}
|
|
|
|
if (',' != fLastChar) {
|
|
|
|
this->writeString(",");
|
|
|
|
}
|
|
|
|
this->lfAlways(1);
|
|
|
|
}
|
|
|
|
this->indentToColumn(4);
|
|
|
|
this->writeString("};");
|
|
|
|
this->lf(1);
|
|
|
|
this->writeString("##");
|
|
|
|
this->lf(2);
|
|
|
|
this->dumpComment(token);
|
|
|
|
for (auto& child : token.fChildren) {
|
|
|
|
// start here;
|
|
|
|
// get comments before
|
|
|
|
// or after const values
|
2018-04-16 12:37:38 +00:00
|
|
|
this->writeTag("Const");
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(child->fName);
|
|
|
|
TextParser val(child);
|
|
|
|
if (!val.eof()) {
|
|
|
|
if ('=' == val.fStart[0] || ',' == val.fStart[0]) {
|
|
|
|
val.next();
|
|
|
|
val.skipSpace();
|
|
|
|
const char* valEnd = val.anyOf(",\n");
|
|
|
|
if (!valEnd) {
|
|
|
|
valEnd = val.fEnd;
|
|
|
|
}
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeBlock(valEnd - val.fStart, val.fStart);
|
|
|
|
} else {
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeDefinition(*child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->lf(1);
|
|
|
|
for (auto comment : child->fChildren) {
|
|
|
|
if (MarkType::kComment == comment->fMarkType) {
|
|
|
|
TextParser parser(comment);
|
|
|
|
parser.skipExact("*");
|
|
|
|
parser.skipExact("*");
|
|
|
|
while (!parser.eof() && parser.skipWhiteSpace()) {
|
|
|
|
parser.skipExact("*");
|
|
|
|
parser.skipWhiteSpace();
|
|
|
|
const char* start = parser.fChar;
|
|
|
|
parser.skipToEndBracket('\n');
|
|
|
|
this->lf(1);
|
|
|
|
this->writeBlock(parser.fChar - start, start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->writeEndTag();
|
|
|
|
}
|
|
|
|
this->lf(2);
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:09:13 +00:00
|
|
|
bool IncludeParser::dumpGlobals(string* globalFileName, long int* globalTell) {
|
|
|
|
bool hasGlobals = !fIDefineMap.empty() || !fIFunctionMap.empty() || !fIEnumMap.empty()
|
|
|
|
|| !fITemplateMap.empty()|| !fITypedefMap.empty() || !fIUnionMap.empty();
|
|
|
|
if (!hasGlobals) {
|
2018-06-27 15:00:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
size_t lastBSlash = fFileName.rfind('\\');
|
|
|
|
size_t lastSlash = fFileName.rfind('/');
|
|
|
|
size_t lastDotH = fFileName.rfind(".h");
|
|
|
|
SkASSERT(string::npos != lastDotH);
|
|
|
|
if (string::npos != lastBSlash && (string::npos == lastSlash
|
|
|
|
|| lastBSlash < lastSlash)) {
|
|
|
|
lastSlash = lastBSlash;
|
|
|
|
} else if (string::npos == lastSlash) {
|
|
|
|
lastSlash = -1;
|
|
|
|
}
|
|
|
|
lastSlash += 1;
|
|
|
|
string globalsName = fFileName.substr(lastSlash, lastDotH - lastSlash);
|
|
|
|
string fileName = globalsName + "_Reference.bmh";
|
2018-08-10 17:09:13 +00:00
|
|
|
*globalFileName = fileName;
|
2018-04-16 12:37:38 +00:00
|
|
|
fOut = fopen(fileName.c_str(), "wb");
|
|
|
|
if (!fOut) {
|
|
|
|
SkDebugf("could not open output file %s\n", globalsName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
string prefixName = globalsName.substr(0, 2);
|
|
|
|
string topicName = globalsName.length() > 2 && isupper(globalsName[2]) &&
|
|
|
|
("Sk" == prefixName || "Gr" == prefixName) ? globalsName.substr(2) : globalsName;
|
|
|
|
this->writeTagNoLF("Topic", topicName);
|
2018-06-27 15:00:21 +00:00
|
|
|
this->writeEndTag("Alias", topicName + "_Reference");
|
2018-04-16 12:37:38 +00:00
|
|
|
this->lf(2);
|
|
|
|
this->writeTag("Subtopic", "Overview");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
|
|
|
this->lf(2);
|
|
|
|
if (!fIDefineMap.empty()) {
|
|
|
|
this->writeTag("Subtopic", "Define");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(2);
|
2018-04-16 12:37:38 +00:00
|
|
|
}
|
|
|
|
if (!fIFunctionMap.empty()) {
|
|
|
|
this->writeTag("Subtopic", "Function");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(2);
|
2018-04-16 12:37:38 +00:00
|
|
|
}
|
|
|
|
if (!fIEnumMap.empty()) {
|
|
|
|
this->writeTag("Subtopic", "Enum");
|
|
|
|
this->writeTag("Populate");
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeEndTag();
|
|
|
|
this->lf(2);
|
2018-04-16 12:37:38 +00:00
|
|
|
}
|
|
|
|
if (!fITemplateMap.empty()) {
|
|
|
|
this->writeTag("Subtopic", "Template");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(2);
|
2018-04-16 12:37:38 +00:00
|
|
|
}
|
|
|
|
if (!fITypedefMap.empty()) {
|
|
|
|
this->writeTag("Subtopic", "Typedef");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(2);
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (!fIUnionMap.empty()) {
|
|
|
|
this->writeTag("Subtopic", "Union");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
|
|
|
this->lf(2);
|
|
|
|
}
|
|
|
|
std::map<int, Definition*> sortedDefs;
|
|
|
|
for (const auto& entry : fIDefineMap) {
|
|
|
|
sortedDefs[entry.second->fLineCount] = entry.second;
|
|
|
|
}
|
|
|
|
for (const auto& entry : fIFunctionMap) {
|
|
|
|
sortedDefs[entry.second->fLineCount] = entry.second;
|
|
|
|
}
|
|
|
|
for (const auto& entry : fIEnumMap) {
|
|
|
|
sortedDefs[entry.second->fLineCount] = entry.second;
|
|
|
|
}
|
|
|
|
for (const auto& entry : fITemplateMap) {
|
|
|
|
sortedDefs[entry.second->fLineCount] = entry.second;
|
|
|
|
}
|
|
|
|
for (const auto& entry : fITypedefMap) {
|
|
|
|
sortedDefs[entry.second->fLineCount] = entry.second;
|
|
|
|
}
|
|
|
|
for (const auto& entry : fIUnionMap) {
|
|
|
|
sortedDefs[entry.second->fLineCount] = entry.second;
|
|
|
|
}
|
|
|
|
for (const auto& entry : sortedDefs) {
|
|
|
|
const Definition* def = entry.second;
|
|
|
|
this->writeBlockSeparator();
|
|
|
|
switch (def->fMarkType) {
|
|
|
|
case MarkType::kDefine:
|
|
|
|
this->dumpDefine(*def);
|
|
|
|
break;
|
|
|
|
case MarkType::kMethod:
|
|
|
|
this->dumpMethod(*def, globalsName);
|
|
|
|
break;
|
|
|
|
case MarkType::kEnum:
|
|
|
|
case MarkType::kEnumClass:
|
|
|
|
this->dumpEnum(*def, globalsName);
|
|
|
|
break;
|
|
|
|
case MarkType::kTemplate:
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
break;
|
|
|
|
case MarkType::kTypedef: {
|
|
|
|
this->writeTag("Typedef");
|
|
|
|
this->writeSpace();
|
|
|
|
TextParser parser(def);
|
|
|
|
if (!parser.skipExact("typedef")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!parser.skipSpace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this->writeBlock(parser.fEnd - parser.fChar, parser.fChar);
|
|
|
|
this->lf(2);
|
|
|
|
this->dumpComment(*def);
|
|
|
|
this->writeEndTag(BmhParser::kMarkProps[(int) entry.second->fMarkType].fName);
|
|
|
|
this->lf(2);
|
|
|
|
} continue;
|
|
|
|
case MarkType::kUnion:
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
}
|
|
|
|
this->dumpCommonTail(*def);
|
|
|
|
}
|
2018-08-10 17:09:13 +00:00
|
|
|
*globalTell = ftell(fOut);
|
2018-04-16 12:37:38 +00:00
|
|
|
this->writeEndTag("Topic", topicName);
|
|
|
|
this->lfAlways(1);
|
2018-08-10 17:09:13 +00:00
|
|
|
// fclose(fOut); // defer closing in case class needs to be also written here
|
2018-04-16 12:37:38 +00:00
|
|
|
SkDebugf("wrote %s\n", fileName.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::isClone(const Definition& token) {
|
|
|
|
string name = token.fName;
|
|
|
|
return name[name.length() - 2] == '_' && isdigit(name[name.length() - 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::isConstructor(const Definition& token, string className) {
|
|
|
|
string name = token.fName;
|
|
|
|
return 0 == name.find(className) || '~' == name[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::isInternalName(const Definition& token) {
|
|
|
|
string name = token.fName;
|
|
|
|
// exception for this SkCanvas function .. for now
|
|
|
|
if (0 == token.fName.find("androidFramework_setDeviceClipRestriction")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return name.substr(0, 7) == "android"
|
|
|
|
|| 0 == token.fName.find("internal_")
|
|
|
|
|| 0 == token.fName.find("Internal_")
|
|
|
|
|| 0 == token.fName.find("legacy_")
|
|
|
|
|| 0 == token.fName.find("temporary_")
|
|
|
|
|| 0 == token.fName.find("private_");
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:09:13 +00:00
|
|
|
bool IncludeParser::isMember(const Definition& token) const {
|
|
|
|
if ('f' == token.fStart[0] && isupper(token.fStart[1])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!islower(token.fStart[0])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// make an exception for SkTextBlob::RunBuffer, sole struct with members not in fXxxx format
|
|
|
|
if (string::npos != token.fFileName.find("SkTextBlob.h")) {
|
|
|
|
const Definition* structToken = token.fParent;
|
|
|
|
if (!structToken) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (KeyWord::kStruct != structToken->fKeyWord) {
|
|
|
|
structToken = token.fParent->fParent;
|
|
|
|
if (!structToken) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (KeyWord::kStruct != structToken->fKeyWord) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkASSERT(structToken->fTokens.size() > 0);
|
|
|
|
const Definition& child = structToken->fTokens.front();
|
|
|
|
string structName(child.fContentStart, child.length());
|
|
|
|
if ("RunBuffer" != structName) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
string tokenName(token.fContentStart, token.length());
|
|
|
|
string allowed[] = { "glyphs", "pos", "utf8text", "clusters" };
|
|
|
|
for (auto allow : allowed) {
|
|
|
|
if (allow == tokenName) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
bool IncludeParser::isOperator(const Definition& token) {
|
|
|
|
return "operator" == token.fName.substr(0, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeParser::dumpMethod(const Definition& token, string className) {
|
|
|
|
this->writeTag("Method");
|
|
|
|
this->writeSpace();
|
|
|
|
|
|
|
|
string name = string(token.fStart ? token.fStart : token.fContentStart,
|
|
|
|
token.length());
|
|
|
|
if (this->isOperator(token)) {
|
|
|
|
string spaceConst(" const");
|
|
|
|
size_t constPos = name.rfind(spaceConst);
|
|
|
|
if (name.length() - spaceConst.length() == constPos) {
|
|
|
|
name = name.substr(0, constPos) + "_const";
|
|
|
|
}
|
|
|
|
}
|
2018-06-27 15:00:21 +00:00
|
|
|
this->writeBlock((int) name.size(), name.c_str());
|
2018-04-16 12:37:38 +00:00
|
|
|
string inType;
|
|
|
|
if (this->isConstructor(token, className)) {
|
|
|
|
inType = "Constructor";
|
|
|
|
} else if (this->isOperator(token)) {
|
|
|
|
inType = "Operator";
|
|
|
|
} else {
|
|
|
|
inType = "incomplete";
|
|
|
|
}
|
|
|
|
this->writeTag("In", inType);
|
2018-06-27 15:00:21 +00:00
|
|
|
this->writeTagTable("Line", "incomplete");
|
2018-04-16 12:37:38 +00:00
|
|
|
this->lf(2);
|
2017-09-19 21:39:32 +00:00
|
|
|
this->dumpComment(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeParser::dumpMember(const Definition& token) {
|
|
|
|
this->writeTag("Member");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeDefinition(token, token.fName, 2);
|
|
|
|
lf(1);
|
|
|
|
for (auto child : token.fChildren) {
|
|
|
|
this->writeDefinition(*child);
|
|
|
|
}
|
|
|
|
this->writeEndTag();
|
|
|
|
lf(2);
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
bool IncludeParser::dumpTokens() {
|
2018-08-10 17:09:13 +00:00
|
|
|
string globalFileName;
|
|
|
|
long int globalTell = 0;
|
|
|
|
if (!this->dumpGlobals(&globalFileName, &globalTell)) {
|
2018-04-16 12:37:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
for (const auto& member : fIClassMap) {
|
|
|
|
if (string::npos != member.first.find("::")) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-10 17:09:13 +00:00
|
|
|
if (!this->dumpTokens(member.first, globalFileName, &globalTell)) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-08-10 17:09:13 +00:00
|
|
|
if (globalTell) {
|
|
|
|
fclose(fOut);
|
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-09 19:45:33 +00:00
|
|
|
// dump equivalent markup
|
2018-08-10 17:09:13 +00:00
|
|
|
bool IncludeParser::dumpTokens(string skClassName, string globalFileName, long int* globalTell) {
|
2018-04-16 12:37:38 +00:00
|
|
|
string fileName = skClassName + "_Reference.bmh";
|
2018-08-10 17:09:13 +00:00
|
|
|
if (globalFileName != fileName) {
|
|
|
|
fOut = fopen(fileName.c_str(), "wb");
|
|
|
|
if (!fOut) {
|
|
|
|
SkDebugf("could not open output file %s\n", fileName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fseek(fOut, *globalTell, SEEK_SET);
|
|
|
|
this->lf(2);
|
|
|
|
this->writeBlockSeparator();
|
|
|
|
*globalTell = 0;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
string prefixName = skClassName.substr(0, 2);
|
|
|
|
string topicName = skClassName.length() > 2 && isupper(skClassName[2]) &&
|
|
|
|
("Sk" == prefixName || "Gr" == prefixName) ? skClassName.substr(2) : skClassName;
|
2018-08-10 17:09:13 +00:00
|
|
|
if (globalFileName != fileName) {
|
|
|
|
this->writeTagNoLF("Topic", topicName);
|
|
|
|
this->writeEndTag("Alias", topicName + "_Reference");
|
|
|
|
this->lf(2);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
auto& classMap = fIClassMap[skClassName];
|
2017-11-27 15:44:06 +00:00
|
|
|
SkASSERT(KeyWord::kClass == classMap.fKeyWord || KeyWord::kStruct == classMap.fKeyWord);
|
|
|
|
const char* containerType = KeyWord::kClass == classMap.fKeyWord ? "Class" : "Struct";
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeTag(containerType, skClassName);
|
|
|
|
this->lf(2);
|
2017-07-28 15:04:54 +00:00
|
|
|
auto& tokens = classMap.fTokens;
|
|
|
|
for (auto& token : tokens) {
|
|
|
|
if (Definition::Type::kMark != token.fType || MarkType::kComment != token.fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeDefinition(token);
|
|
|
|
this->lf(1);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
this->lf(2);
|
2018-04-16 12:37:38 +00:00
|
|
|
bool hasClass = false;
|
|
|
|
bool hasConst = !fIEnumMap.empty();
|
|
|
|
bool hasConstructor = false;
|
|
|
|
bool hasMember = false;
|
|
|
|
bool hasOperator = false;
|
2018-06-27 15:00:21 +00:00
|
|
|
bool hasStruct = false;
|
2017-07-28 15:04:54 +00:00
|
|
|
for (const auto& oneClass : fIClassMap) {
|
|
|
|
if (skClassName + "::" != oneClass.first.substr(0, skClassName.length() + 2)) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
hasClass = true;
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-06-27 15:00:21 +00:00
|
|
|
for (const auto& oneStruct : fIStructMap) {
|
|
|
|
if (skClassName + "::" != oneStruct.first.substr(0, skClassName.length() + 2)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
hasStruct = true;
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
for (const auto& token : classMap.fTokens) {
|
|
|
|
if (Definition::Type::kMark != token.fType || MarkType::kMethod != token.fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (this->isInternalName(token)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (this->isConstructor(token, skClassName)) {
|
|
|
|
hasConstructor = true;
|
2017-09-19 21:39:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (this->isOperator(token)) {
|
|
|
|
hasOperator = true;
|
2017-09-19 21:39:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (this->isClone(token)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
hasMember = true;
|
2018-01-26 17:56:22 +00:00
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
this->writeTag("Subtopic", "Overview");
|
|
|
|
this->writeTag("Populate");
|
2018-01-26 17:56:22 +00:00
|
|
|
this->writeEndTag();
|
|
|
|
this->lf(2);
|
2018-04-16 12:37:38 +00:00
|
|
|
|
|
|
|
if (hasClass) {
|
2018-06-27 15:00:21 +00:00
|
|
|
this->writeTag("Subtopic", "Class");
|
2018-04-16 12:37:38 +00:00
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
2018-01-26 17:56:22 +00:00
|
|
|
this->lf(2);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (hasConst) {
|
|
|
|
this->writeTag("Subtopic", "Constant");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
2018-01-26 17:56:22 +00:00
|
|
|
this->lf(2);
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (hasConstructor) {
|
|
|
|
this->writeTag("Subtopic", "Constructor");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(2);
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (hasOperator) {
|
|
|
|
this->writeTag("Subtopic", "Operator");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(2);
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (hasMember) {
|
|
|
|
this->writeTag("Subtopic", "Member_Function");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
2018-01-26 17:56:22 +00:00
|
|
|
this->lf(2);
|
2017-09-19 21:39:32 +00:00
|
|
|
}
|
2018-06-27 15:00:21 +00:00
|
|
|
if (hasStruct) {
|
|
|
|
this->writeTag("Subtopic", "Struct");
|
|
|
|
this->writeTag("Populate");
|
|
|
|
this->writeEndTag();
|
|
|
|
this->lf(2);
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
for (auto& oneEnum : fIEnumMap) {
|
2018-04-16 12:37:38 +00:00
|
|
|
this->writeBlockSeparator();
|
|
|
|
this->dumpEnum(*oneEnum.second, oneEnum.first);
|
2018-01-26 17:56:22 +00:00
|
|
|
this->lf(2);
|
|
|
|
this->writeTag("Example");
|
|
|
|
this->lfcr();
|
|
|
|
this->writeString("// incomplete");
|
|
|
|
this->writeEndTag();
|
|
|
|
this->lf(2);
|
|
|
|
this->writeTag("SeeAlso", "incomplete");
|
|
|
|
this->lf(2);
|
|
|
|
this->writeEndTag("Enum", oneEnum.first);
|
|
|
|
this->lf(2);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
for (auto& oneClass : fIClassMap) {
|
|
|
|
if (skClassName + "::" != oneClass.first.substr(0, skClassName.length() + 2)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
string innerName = oneClass.first.substr(skClassName.length() + 2);
|
2018-04-16 12:37:38 +00:00
|
|
|
this->writeBlockSeparator();
|
2017-11-27 15:44:06 +00:00
|
|
|
KeyWord keyword = oneClass.second.fKeyWord;
|
|
|
|
SkASSERT(KeyWord::kClass == keyword || KeyWord::kStruct == keyword);
|
|
|
|
const char* containerType = KeyWord::kClass == keyword ? "Class" : "Struct";
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeTag(containerType, innerName);
|
2018-06-27 15:00:21 +00:00
|
|
|
this->writeTagTable("Line", "incomplete");
|
2017-09-19 21:39:32 +00:00
|
|
|
this->lf(2);
|
|
|
|
this->writeTag("Code");
|
|
|
|
this->writeEndTag("ToDo", "fill this in manually");
|
|
|
|
this->writeEndTag();
|
|
|
|
this->lf(2);
|
2017-07-28 15:04:54 +00:00
|
|
|
for (auto& token : oneClass.second.fTokens) {
|
|
|
|
if (Definition::Type::kMark != token.fType || MarkType::kComment != token.fMarkType) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeDefinition(token);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
this->lf(2);
|
|
|
|
this->dumpClassTokens(oneClass.second);
|
|
|
|
this->lf(2);
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeEndTag(containerType, innerName);
|
|
|
|
this->lf(2);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
this->dumpClassTokens(classMap);
|
2017-09-19 21:39:32 +00:00
|
|
|
this->writeEndTag(containerType, skClassName);
|
|
|
|
this->lf(2);
|
|
|
|
this->writeEndTag("Topic", topicName);
|
|
|
|
this->lfAlways(1);
|
2017-07-28 15:04:54 +00:00
|
|
|
fclose(fOut);
|
2017-09-14 15:25:39 +00:00
|
|
|
SkDebugf("wrote %s\n", fileName.c_str());
|
|
|
|
return true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 17:09:13 +00:00
|
|
|
void IncludeParser::dumpTypedef(const Definition& token, string className) {
|
|
|
|
this->writeTag("Typedef");
|
|
|
|
this->writeSpace();
|
|
|
|
this->writeString(token.fName);
|
|
|
|
this->writeTagTable("Line", "incomplete");
|
|
|
|
this->lf(2);
|
|
|
|
this->dumpComment(token);
|
|
|
|
}
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
bool IncludeParser::findComments(const Definition& includeDef, Definition* markupDef) {
|
|
|
|
// add comment preceding class, if any
|
|
|
|
const Definition* parent = includeDef.fParent;
|
|
|
|
int index = includeDef.fParentIndex;
|
|
|
|
auto wordIter = parent->fTokens.begin();
|
|
|
|
std::advance(wordIter, index);
|
|
|
|
SkASSERT(&*wordIter == &includeDef);
|
|
|
|
while (parent->fTokens.begin() != wordIter) {
|
|
|
|
auto testIter = std::prev(wordIter);
|
|
|
|
if (Definition::Type::kWord != testIter->fType
|
|
|
|
&& Definition::Type::kKeyWord != testIter->fType
|
|
|
|
&& (Definition::Type::kBracket != testIter->fType
|
|
|
|
|| Bracket::kAngle != testIter->fBracket)
|
|
|
|
&& (Definition::Type::kPunctuation != testIter->fType
|
|
|
|
|| Punctuation::kAsterisk != testIter->fPunctuation)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wordIter = testIter;
|
|
|
|
}
|
|
|
|
auto commentIter = wordIter;
|
|
|
|
while (parent->fTokens.begin() != commentIter) {
|
|
|
|
auto testIter = std::prev(commentIter);
|
|
|
|
bool isComment = Definition::Type::kBracket == testIter->fType
|
|
|
|
&& (Bracket::kSlashSlash == testIter->fBracket
|
|
|
|
|| Bracket::kSlashStar == testIter->fBracket);
|
|
|
|
if (!isComment) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
commentIter = testIter;
|
|
|
|
}
|
|
|
|
while (commentIter != wordIter) {
|
|
|
|
if (!this->parseComment(commentIter->fFileName, commentIter->fContentStart,
|
|
|
|
commentIter->fContentEnd, commentIter->fLineCount, markupDef)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
commentIter = std::next(commentIter);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-07 13:59:07 +00:00
|
|
|
Definition* IncludeParser::findIncludeObject(const Definition& includeDef, MarkType markType,
|
|
|
|
string typeName) {
|
|
|
|
typedef Definition* DefinitionPtr;
|
|
|
|
auto mapIter = std::find_if(fMaps.begin(), fMaps.end(),
|
|
|
|
[markType](DefinitionMap& defMap){ return markType == defMap.fMarkType; } );
|
|
|
|
if (mapIter == fMaps.end()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (mapIter->fInclude->end() == mapIter->fInclude->find(typeName)) {
|
|
|
|
return reportError<DefinitionPtr>("invalid mark type");
|
|
|
|
}
|
|
|
|
string name = this->uniqueName(*mapIter->fInclude, typeName);
|
|
|
|
Definition& markupDef = *(*mapIter->fInclude)[name];
|
|
|
|
if (markupDef.fStart) {
|
|
|
|
return reportError<DefinitionPtr>("definition already defined");
|
|
|
|
}
|
|
|
|
markupDef.fFileName = fFileName;
|
|
|
|
markupDef.fStart = includeDef.fStart;
|
|
|
|
markupDef.fContentStart = includeDef.fStart;
|
|
|
|
markupDef.fName = name;
|
|
|
|
markupDef.fContentEnd = includeDef.fContentEnd;
|
|
|
|
markupDef.fTerminator = includeDef.fTerminator;
|
|
|
|
markupDef.fParent = fParent;
|
|
|
|
markupDef.fLineCount = includeDef.fLineCount;
|
|
|
|
markupDef.fMarkType = markType;
|
|
|
|
markupDef.fKeyWord = includeDef.fKeyWord;
|
|
|
|
markupDef.fType = Definition::Type::kMark;
|
|
|
|
return &markupDef;
|
|
|
|
}
|
|
|
|
|
2018-06-27 15:00:21 +00:00
|
|
|
Definition* IncludeParser::parentBracket(Definition* parent) const {
|
|
|
|
while (parent && Definition::Type::kBracket != parent->fType) {
|
|
|
|
parent = parent->fParent;
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bracket IncludeParser::grandParentBracket() const {
|
|
|
|
Definition* parent = parentBracket(fParent);
|
|
|
|
parent = parentBracket(parent ? parent->fParent : nullptr);
|
|
|
|
return parent ? parent->fBracket : Bracket::kNone;
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:09:13 +00:00
|
|
|
bool IncludeParser::inAlignAs() const {
|
|
|
|
if (fParent->fTokens.size() < 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto reverseIter = fParent->fTokens.end();
|
|
|
|
bool checkForBracket = true;
|
|
|
|
while (fParent->fTokens.begin() != reverseIter) {
|
|
|
|
std::advance(reverseIter, -1);
|
|
|
|
if (checkForBracket) {
|
|
|
|
if (Definition::Type::kBracket != reverseIter->fType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Bracket::kParen != reverseIter->fBracket) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
checkForBracket = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kKeyWord != reverseIter->fType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return KeyWord::kAlignAs == reverseIter->fKeyWord;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-30 13:21:49 +00:00
|
|
|
// caller just returns, so report error here
|
2017-07-28 15:04:54 +00:00
|
|
|
bool IncludeParser::parseClass(Definition* includeDef, IsStruct isStruct) {
|
|
|
|
SkASSERT(includeDef->fTokens.size() > 0);
|
|
|
|
// parse class header
|
|
|
|
auto iter = includeDef->fTokens.begin();
|
|
|
|
if (!strncmp(iter->fStart, "SK_API", iter->fContentEnd - iter->fStart)) {
|
|
|
|
// todo : documentation is ignoring this for now
|
|
|
|
iter = std::next(iter);
|
|
|
|
}
|
2018-08-10 17:09:13 +00:00
|
|
|
bool hasAlignAs = iter->fKeyWord == KeyWord::kAlignAs;
|
|
|
|
if (hasAlignAs) {
|
|
|
|
iter = std::next(iter);
|
|
|
|
if (Definition::Type::kBracket != iter->fType || Bracket::kParen != iter->fBracket) {
|
|
|
|
return includeDef->reportError<bool>("expected alignas argument");
|
|
|
|
}
|
|
|
|
iter = std::next(iter);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
string nameStr(iter->fStart, iter->fContentEnd - iter->fStart);
|
|
|
|
includeDef->fName = nameStr;
|
2017-09-19 21:39:32 +00:00
|
|
|
iter = std::next(iter);
|
|
|
|
if (iter == includeDef->fTokens.end()) {
|
|
|
|
return true; // forward declaration only
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
do {
|
|
|
|
if (iter == includeDef->fTokens.end()) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return includeDef->reportError<bool>("unexpected end");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if ('{' == iter->fStart[0] && Definition::Type::kPunctuation == iter->fType) {
|
|
|
|
break;
|
2017-10-09 19:45:33 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
} while (static_cast<void>(iter = std::next(iter)), true);
|
|
|
|
if (Punctuation::kLeftBrace != iter->fPunctuation) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return iter->reportError<bool>("expected left brace");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
IClassDefinition* markupDef = this->defineClass(*includeDef, nameStr);
|
|
|
|
if (!markupDef) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return iter->reportError<bool>("expected markup definition");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
markupDef->fStart = iter->fStart;
|
|
|
|
if (!this->findComments(*includeDef, markupDef)) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return iter->reportError<bool>("find comments failed");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
// if (1 != includeDef->fChildren.size()) {
|
|
|
|
// return false; // fix me: SkCanvasClipVisitor isn't correctly parsed
|
|
|
|
// }
|
2018-08-10 17:09:13 +00:00
|
|
|
auto includeDefIter = includeDef->fChildren.begin();
|
|
|
|
if (hasAlignAs) {
|
|
|
|
SkASSERT(includeDef->fChildren.end() != includeDefIter);
|
|
|
|
SkASSERT(Bracket::kParen == (*includeDefIter)->fBracket);
|
|
|
|
std::advance(includeDefIter, 1);
|
|
|
|
}
|
|
|
|
if (includeDef->fChildren.end() != includeDefIter
|
|
|
|
&& Bracket::kAngle == (*includeDefIter)->fBracket) {
|
|
|
|
std::advance(includeDefIter, 1);
|
|
|
|
}
|
|
|
|
includeDef = *includeDefIter;
|
|
|
|
SkASSERT(Bracket::kBrace == includeDef->fBracket);
|
2017-07-28 15:04:54 +00:00
|
|
|
iter = includeDef->fTokens.begin();
|
|
|
|
// skip until public
|
|
|
|
int publicIndex = 0;
|
|
|
|
if (IsStruct::kNo == isStruct) {
|
|
|
|
const char* publicName = kKeyWords[(int) KeyWord::kPublic].fName;
|
|
|
|
size_t publicLen = strlen(publicName);
|
|
|
|
while (iter != includeDef->fTokens.end()
|
|
|
|
&& (publicLen != (size_t) (iter->fContentEnd - iter->fStart)
|
|
|
|
|| strncmp(iter->fStart, publicName, publicLen))) {
|
2018-05-30 13:21:49 +00:00
|
|
|
iter->fPrivate = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
iter = std::next(iter);
|
|
|
|
++publicIndex;
|
|
|
|
}
|
|
|
|
}
|
2017-10-11 14:37:52 +00:00
|
|
|
int keyIndex = publicIndex;
|
|
|
|
KeyWord currentKey = KeyWord::kPublic;
|
|
|
|
const char* publicName = kKeyWords[(int) KeyWord::kPublic].fName;
|
|
|
|
size_t publicLen = strlen(publicName);
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* protectedName = kKeyWords[(int) KeyWord::kProtected].fName;
|
|
|
|
size_t protectedLen = strlen(protectedName);
|
|
|
|
const char* privateName = kKeyWords[(int) KeyWord::kPrivate].fName;
|
|
|
|
size_t privateLen = strlen(privateName);
|
2018-05-30 13:21:49 +00:00
|
|
|
auto childIter = includeDef->fChildren.begin();
|
2018-08-10 17:09:13 +00:00
|
|
|
while (includeDef->fChildren.end() != childIter && (*childIter)->fPrivate) {
|
2018-06-15 09:11:24 +00:00
|
|
|
std::advance(childIter, 1);
|
|
|
|
}
|
2017-10-11 14:37:52 +00:00
|
|
|
while (childIter != includeDef->fChildren.end()) {
|
2017-07-28 15:04:54 +00:00
|
|
|
Definition* child = *childIter;
|
2017-10-11 14:37:52 +00:00
|
|
|
while (child->fParentIndex > keyIndex && iter != includeDef->fTokens.end()) {
|
2018-05-30 13:21:49 +00:00
|
|
|
iter->fPrivate = KeyWord::kPublic != currentKey;
|
2017-10-11 14:37:52 +00:00
|
|
|
const char* testStart = iter->fStart;
|
|
|
|
size_t testLen = (size_t) (iter->fContentEnd - testStart);
|
|
|
|
iter = std::next(iter);
|
|
|
|
++keyIndex;
|
|
|
|
if (publicLen == testLen && !strncmp(testStart, publicName, testLen)) {
|
|
|
|
currentKey = KeyWord::kPublic;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (protectedLen == testLen && !strncmp(testStart, protectedName, testLen)) {
|
|
|
|
currentKey = KeyWord::kProtected;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (privateLen == testLen && !strncmp(testStart, privateName, testLen)) {
|
|
|
|
currentKey = KeyWord::kPrivate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fLastObject = nullptr;
|
|
|
|
if (KeyWord::kPublic == currentKey) {
|
|
|
|
if (!this->parseObject(child, markupDef)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2017-08-29 21:36:51 +00:00
|
|
|
fLastObject = child;
|
2017-07-28 15:04:54 +00:00
|
|
|
childIter = std::next(childIter);
|
|
|
|
}
|
2018-05-30 13:21:49 +00:00
|
|
|
while (iter != includeDef->fTokens.end()) {
|
|
|
|
iter->fPrivate = KeyWord::kPublic != currentKey;
|
|
|
|
iter = std::next(iter);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(fParent->fParent);
|
|
|
|
fParent = fParent->fParent;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
bool IncludeParser::parseComment(string filename, const char* start, const char* end,
|
2017-07-28 15:04:54 +00:00
|
|
|
int lineCount, Definition* markupDef) {
|
|
|
|
TextParser parser(filename, start, end, lineCount);
|
|
|
|
// parse doxygen if present
|
|
|
|
if (parser.startsWith("**")) {
|
|
|
|
parser.next();
|
|
|
|
parser.next();
|
|
|
|
parser.skipWhiteSpace();
|
|
|
|
if ('\\' == parser.peek()) {
|
|
|
|
parser.next();
|
2018-04-16 12:37:38 +00:00
|
|
|
// Doxygen tag may be "file" or "fn" in addition to "class", "enum", "struct"
|
|
|
|
if (parser.skipExact("file")) {
|
|
|
|
if (Definition::Type::kFileType != fParent->fType) {
|
|
|
|
return reportError<bool>("expected parent is file");
|
|
|
|
}
|
|
|
|
string filename = markupDef->fileName();
|
|
|
|
if (!parser.skipWord(filename.c_str())) {
|
|
|
|
return reportError<bool>("missing object type");
|
|
|
|
}
|
|
|
|
} else if (parser.skipExact("fn")) {
|
|
|
|
SkASSERT(0); // incomplete
|
|
|
|
} else {
|
|
|
|
if (!parser.skipWord(kKeyWords[(int) markupDef->fKeyWord].fName)) {
|
|
|
|
return reportError<bool>("missing object type");
|
|
|
|
}
|
|
|
|
if (!parser.skipWord(markupDef->fName.c_str()) &&
|
|
|
|
KeyWord::kEnum != markupDef->fKeyWord) {
|
|
|
|
return reportError<bool>("missing object name");
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// remove leading '*' if present
|
|
|
|
Definition* parent = markupDef->fTokens.size() ? &markupDef->fTokens.back() : markupDef;
|
|
|
|
while (!parser.eof() && parser.skipWhiteSpace()) {
|
|
|
|
while ('*' == parser.peek()) {
|
|
|
|
parser.next();
|
|
|
|
if (parser.eof()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parser.skipWhiteSpace();
|
|
|
|
}
|
|
|
|
if (parser.eof()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const char* lineEnd = parser.trimmedLineEnd();
|
2017-10-09 19:45:33 +00:00
|
|
|
markupDef->fTokens.emplace_back(MarkType::kComment, parser.fChar, lineEnd,
|
2018-03-05 18:26:16 +00:00
|
|
|
parser.fLineCount, parent, '\0');
|
2017-07-28 15:04:54 +00:00
|
|
|
parser.skipToEndBracket('\n');
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-26 12:32:37 +00:00
|
|
|
bool IncludeParser::parseConst(Definition* child, Definition* markupDef) {
|
|
|
|
if (!markupDef) {
|
|
|
|
fGlobals.emplace_back(MarkType::kConst, child->fContentStart, child->fContentEnd,
|
|
|
|
child->fLineCount, fParent, '\0');
|
|
|
|
Definition* globalMarkupChild = &fGlobals.back();
|
2018-06-07 13:59:07 +00:00
|
|
|
string globalUniqueName = this->uniqueName(fIConstMap, child->fName);
|
2018-04-26 12:32:37 +00:00
|
|
|
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();
|
2018-06-07 13:59:07 +00:00
|
|
|
markupChild->fName = child->fName;
|
2018-04-26 12:32:37 +00:00
|
|
|
markupChild->fTerminator = markupChild->fContentEnd;
|
|
|
|
IClassDefinition& classDef = fIClassMap[markupDef->fName];
|
2018-06-07 13:59:07 +00:00
|
|
|
classDef.fConsts[child->fName] = markupChild;
|
2018-04-26 12:32:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
bool IncludeParser::parseDefine(Definition* child, Definition* markupDef) {
|
|
|
|
TextParser parser(child);
|
|
|
|
if (!parser.skipExact("#define")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!parser.skipSpace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const char* nameStart = parser.fChar;
|
|
|
|
parser.skipToNonAlphaNum(); // FIXME: just want to skip isalnum() and '_'
|
|
|
|
if (parser.eof()) {
|
|
|
|
return true; // do nothing if #define doesn't define anything
|
|
|
|
}
|
|
|
|
string nameStr(nameStart, parser.fChar - nameStart);
|
|
|
|
struct Param {
|
|
|
|
const char* fStart;
|
|
|
|
const char* fEnd;
|
|
|
|
};
|
|
|
|
vector<Param> params;
|
|
|
|
if ('(' == parser.peek()) {
|
|
|
|
parser.next();
|
|
|
|
if (!parser.skipSpace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
const char* paramStart = parser.fChar;
|
|
|
|
if (!parser.skipExact("...")) {
|
|
|
|
parser.skipToNonAlphaNum();
|
|
|
|
}
|
|
|
|
if (parser.eof()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
params.push_back({paramStart, parser.fChar});
|
|
|
|
if (!parser.skipSpace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (')' == parser.peek()) {
|
|
|
|
parser.next();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (',' != parser.next()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!parser.skipSpace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
if (!parser.skipSpace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!markupDef) {
|
|
|
|
fGlobals.emplace_back(MarkType::kDefine, nameStart, child->fContentEnd,
|
|
|
|
child->fLineCount, fParent, '\0');
|
|
|
|
Definition* globalMarkupChild = &fGlobals.back();
|
|
|
|
string globalUniqueName = this->uniqueName(fIDefineMap, nameStr);
|
|
|
|
globalMarkupChild->fName = globalUniqueName;
|
|
|
|
globalMarkupChild->fTerminator = child->fContentEnd;
|
|
|
|
if (!this->findComments(*child, globalMarkupChild)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fIDefineMap[globalUniqueName] = globalMarkupChild;
|
|
|
|
for (Param param : params) {
|
|
|
|
globalMarkupChild->fTokens.emplace_back(MarkType::kParam, param.fStart, param.fEnd,
|
|
|
|
child->fLineCount, globalMarkupChild, '\0');
|
|
|
|
Definition* paramChild = &globalMarkupChild->fTokens.back();
|
|
|
|
paramChild->fName = string(param.fStart, param.fEnd - param.fStart);
|
|
|
|
paramChild->fTerminator = param.fEnd;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
markupDef->fTokens.emplace_back(MarkType::kDefine, 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];
|
|
|
|
if (!this->findComments(*child, markupChild)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
classDef.fDefines[nameStr] = markupChild;
|
2017-07-28 15:04:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::parseEnum(Definition* child, Definition* markupDef) {
|
2018-01-26 17:56:22 +00:00
|
|
|
TextParser parser(child);
|
|
|
|
parser.skipToEndBracket('{');
|
|
|
|
if (parser.eof()) {
|
|
|
|
return true; // if enum is a forward declaration, do nothing
|
|
|
|
}
|
|
|
|
parser.next();
|
|
|
|
string nameStr;
|
2017-07-28 15:04:54 +00:00
|
|
|
if (child->fTokens.size() > 0) {
|
|
|
|
auto token = child->fTokens.begin();
|
|
|
|
if (Definition::Type::kKeyWord == token->fType && KeyWord::kClass == token->fKeyWord) {
|
|
|
|
token = token->fTokens.begin();
|
|
|
|
}
|
|
|
|
if (Definition::Type::kWord == token->fType) {
|
|
|
|
nameStr += string(token->fStart, token->fContentEnd - token->fStart);
|
|
|
|
}
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
Definition* markupChild;
|
|
|
|
if (!markupDef) {
|
2018-04-16 12:37:38 +00:00
|
|
|
fGlobals.emplace_back(MarkType::kEnum, child->fContentStart, child->fContentEnd,
|
|
|
|
child->fLineCount, fParent, '\0');
|
|
|
|
markupChild = &fGlobals.back();
|
|
|
|
string globalUniqueName = this->uniqueName(fIEnumMap, nameStr);
|
|
|
|
markupChild->fName = globalUniqueName;
|
|
|
|
markupChild->fTerminator = child->fContentEnd;
|
|
|
|
fIEnumMap[globalUniqueName] = markupChild;
|
2018-01-26 17:56:22 +00:00
|
|
|
} else {
|
|
|
|
markupDef->fTokens.emplace_back(MarkType::kEnum, child->fContentStart, child->fContentEnd,
|
2018-03-05 18:26:16 +00:00
|
|
|
child->fLineCount, markupDef, '\0');
|
2018-01-26 17:56:22 +00:00
|
|
|
markupChild = &markupDef->fTokens.back();
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
SkASSERT(KeyWord::kNone == markupChild->fKeyWord);
|
|
|
|
markupChild->fKeyWord = KeyWord::kEnum;
|
|
|
|
TextParser enumName(child);
|
|
|
|
enumName.skipExact("enum ");
|
2018-01-26 17:56:22 +00:00
|
|
|
enumName.skipWhiteSpace();
|
2017-08-03 21:14:08 +00:00
|
|
|
if (enumName.skipExact("class ")) {
|
2018-01-26 17:56:22 +00:00
|
|
|
enumName.skipWhiteSpace();
|
2017-08-03 21:14:08 +00:00
|
|
|
markupChild->fMarkType = MarkType::kEnumClass;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* nameStart = enumName.fChar;
|
|
|
|
enumName.skipToSpace();
|
2018-01-26 17:56:22 +00:00
|
|
|
if (markupDef) {
|
2018-03-20 19:53:27 +00:00
|
|
|
markupChild->fName = markupDef->fName + "::" +
|
|
|
|
string(nameStart, (size_t) (enumName.fChar - nameStart));
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!this->findComments(*child, markupChild)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const char* dataEnd;
|
|
|
|
do {
|
|
|
|
parser.skipWhiteSpace();
|
|
|
|
if ('}' == parser.peek()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Definition* comment = nullptr;
|
|
|
|
// note that comment, if any, can be before or after (on the same line, though) as member
|
|
|
|
if ('#' == parser.peek()) {
|
|
|
|
// fixme: handle preprecessor, but just skip it for now
|
|
|
|
parser.skipToLineStart();
|
|
|
|
}
|
|
|
|
while (parser.startsWith("/*") || parser.startsWith("//")) {
|
|
|
|
parser.next();
|
|
|
|
const char* start = parser.fChar;
|
|
|
|
const char* end;
|
|
|
|
if ('*' == parser.peek()) {
|
|
|
|
end = parser.strnstr("*/", parser.fEnd);
|
|
|
|
parser.fChar = end;
|
|
|
|
parser.next();
|
|
|
|
parser.next();
|
|
|
|
} else {
|
|
|
|
end = parser.trimmedLineEnd();
|
|
|
|
parser.skipToLineStart();
|
|
|
|
}
|
|
|
|
markupChild->fTokens.emplace_back(MarkType::kComment, start, end, parser.fLineCount,
|
2018-03-05 18:26:16 +00:00
|
|
|
markupChild, '\0');
|
2017-07-28 15:04:54 +00:00
|
|
|
comment = &markupChild->fTokens.back();
|
|
|
|
comment->fTerminator = end;
|
|
|
|
if (!this->parseComment(parser.fFileName, start, end, parser.fLineCount, comment)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
parser.skipWhiteSpace();
|
|
|
|
}
|
|
|
|
parser.skipWhiteSpace();
|
|
|
|
const char* memberStart = parser.fChar;
|
|
|
|
if ('}' == memberStart[0]) {
|
|
|
|
break;
|
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
// if there's comment on same the line as member def, output first as if it was before
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
parser.skipToNonName();
|
2017-07-28 15:04:54 +00:00
|
|
|
string memberName(memberStart, parser.fChar);
|
2017-09-19 21:39:32 +00:00
|
|
|
if (parser.eof() || !parser.skipWhiteSpace()) {
|
2018-06-27 15:00:21 +00:00
|
|
|
return parser.reportError<bool>("enum member must end with comma 1");
|
2017-09-19 21:39:32 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* dataStart = parser.fChar;
|
2017-09-19 21:39:32 +00:00
|
|
|
if ('=' == parser.peek()) {
|
|
|
|
parser.skipToEndBracket(',');
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
if (!parser.eof() && '#' == parser.peek()) {
|
|
|
|
// fixme: handle preprecessor, but just skip it for now
|
|
|
|
continue;
|
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
if (parser.eof() || ',' != parser.peek()) {
|
2018-06-27 15:00:21 +00:00
|
|
|
return parser.reportError<bool>("enum member must end with comma 2");
|
2017-09-19 21:39:32 +00:00
|
|
|
}
|
|
|
|
dataEnd = parser.fChar;
|
|
|
|
const char* start = parser.anyOf("/\n");
|
|
|
|
SkASSERT(start);
|
|
|
|
parser.skipTo(start);
|
|
|
|
if ('/' == parser.next()) {
|
|
|
|
char slashStar = parser.next();
|
|
|
|
if ('/' == slashStar || '*' == slashStar) {
|
2018-04-03 12:43:27 +00:00
|
|
|
TextParserSave save(&parser);
|
2017-09-19 21:39:32 +00:00
|
|
|
char doxCheck = parser.next();
|
|
|
|
if ((slashStar != doxCheck && '!' != doxCheck) || '<' != parser.next()) {
|
|
|
|
save.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parser.skipWhiteSpace();
|
|
|
|
const char* commentStart = parser.fChar;
|
|
|
|
if ('/' == slashStar) {
|
|
|
|
parser.skipToEndBracket('\n');
|
|
|
|
} else {
|
|
|
|
parser.skipToEndBracket("*/");
|
|
|
|
}
|
|
|
|
SkASSERT(!parser.eof());
|
|
|
|
const char* commentEnd = parser.fChar;
|
|
|
|
markupChild->fTokens.emplace_back(MarkType::kComment, commentStart, commentEnd,
|
2018-03-05 18:26:16 +00:00
|
|
|
parser.fLineCount, markupChild, '\0');
|
2017-09-19 21:39:32 +00:00
|
|
|
comment = &markupChild->fTokens.back();
|
|
|
|
comment->fTerminator = commentEnd;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
markupChild->fTokens.emplace_back(MarkType::kMember, dataStart, dataEnd, parser.fLineCount,
|
2018-03-05 18:26:16 +00:00
|
|
|
markupChild, '\0');
|
2017-07-28 15:04:54 +00:00
|
|
|
Definition* member = &markupChild->fTokens.back();
|
|
|
|
member->fName = memberName;
|
|
|
|
if (comment) {
|
|
|
|
member->fChildren.push_back(comment);
|
2017-09-19 21:39:32 +00:00
|
|
|
comment->fPrivate = true;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
markupChild->fChildren.push_back(member);
|
2017-09-19 21:39:32 +00:00
|
|
|
} while (true);
|
2018-01-04 21:11:51 +00:00
|
|
|
for (auto outsideMember : child->fChildren) {
|
|
|
|
if (Definition::Type::kBracket == outsideMember->fType) {
|
2017-10-11 14:37:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
SkASSERT(Definition::Type::kKeyWord == outsideMember->fType);
|
|
|
|
if (KeyWord::kClass == outsideMember->fKeyWord) {
|
2017-10-11 14:37:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
SkASSERT(KeyWord::kStatic == outsideMember->fKeyWord);
|
|
|
|
markupChild->fTokens.emplace_back(MarkType::kMember, outsideMember->fContentStart,
|
2018-03-05 18:26:16 +00:00
|
|
|
outsideMember->fContentEnd, outsideMember->fLineCount, markupChild, '\0');
|
2017-10-11 14:37:52 +00:00
|
|
|
Definition* member = &markupChild->fTokens.back();
|
2018-01-04 21:11:51 +00:00
|
|
|
member->fName = outsideMember->fName;
|
2017-10-11 14:37:52 +00:00
|
|
|
// FIXME: ? add comment as well ?
|
|
|
|
markupChild->fChildren.push_back(member);
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
if (markupDef) {
|
|
|
|
IClassDefinition& classDef = fIClassMap[markupDef->fName];
|
|
|
|
SkASSERT(classDef.fStart);
|
|
|
|
string uniqueName = this->uniqueName(classDef.fEnums, nameStr);
|
|
|
|
markupChild->fName = uniqueName;
|
|
|
|
classDef.fEnums[uniqueName] = markupChild;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-16 12:37:38 +00:00
|
|
|
bool IncludeParser::parseInclude(string name) {
|
2017-07-28 15:04:54 +00:00
|
|
|
fParent = &fIncludeMap[name];
|
|
|
|
fParent->fName = name;
|
|
|
|
fParent->fFileName = fFileName;
|
|
|
|
fParent->fType = Definition::Type::kFileType;
|
|
|
|
fParent->fContentStart = fChar;
|
|
|
|
fParent->fContentEnd = fEnd;
|
|
|
|
// parse include file into tree
|
|
|
|
while (fChar < fEnd) {
|
|
|
|
if (!this->parseChar()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// parse tree and add named objects to maps
|
|
|
|
fParent = &fIncludeMap[name];
|
|
|
|
if (!this->parseObjects(fParent, nullptr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::parseMember(Definition* child, Definition* markupDef) {
|
|
|
|
const char* typeStart = child->fChildren[0]->fContentStart;
|
|
|
|
markupDef->fTokens.emplace_back(MarkType::kMember, typeStart, child->fContentStart,
|
2018-03-05 18:26:16 +00:00
|
|
|
child->fLineCount, markupDef, '\0');
|
2017-07-28 15:04:54 +00:00
|
|
|
Definition* markupChild = &markupDef->fTokens.back();
|
|
|
|
TextParser nameParser(child);
|
2018-04-16 12:37:38 +00:00
|
|
|
nameParser.skipToNonName();
|
2017-07-28 15:04:54 +00:00
|
|
|
string nameStr = string(child->fContentStart, nameParser.fChar - child->fContentStart);
|
|
|
|
IClassDefinition& classDef = fIClassMap[markupDef->fName];
|
|
|
|
string uniqueName = this->uniqueName(classDef.fMethods, nameStr);
|
|
|
|
markupChild->fName = uniqueName;
|
2017-09-19 21:39:32 +00:00
|
|
|
markupChild->fTerminator = markupChild->fContentEnd;
|
2017-07-28 15:04:54 +00:00
|
|
|
classDef.fMembers[uniqueName] = markupChild;
|
|
|
|
if (child->fParentIndex >= 2) {
|
|
|
|
auto comment = child->fParent->fTokens.begin();
|
|
|
|
std::advance(comment, child->fParentIndex - 2);
|
|
|
|
if (Definition::Type::kBracket == comment->fType
|
|
|
|
&& (Bracket::kSlashStar == comment->fBracket
|
|
|
|
|| Bracket::kSlashSlash == comment->fBracket)) {
|
|
|
|
TextParser parser(&*comment);
|
|
|
|
do {
|
|
|
|
parser.skipToAlpha();
|
|
|
|
if (parser.eof()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const char* start = parser.fChar;
|
2017-09-01 19:51:02 +00:00
|
|
|
const char* end = parser.trimmedBracketEnd('\n');
|
2017-07-28 15:04:54 +00:00
|
|
|
if (Bracket::kSlashStar == comment->fBracket) {
|
|
|
|
const char* commentEnd = parser.strnstr("*/", end);
|
|
|
|
if (commentEnd) {
|
|
|
|
end = commentEnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
markupDef->fTokens.emplace_back(MarkType::kComment, start, end, child->fLineCount,
|
2018-03-05 18:26:16 +00:00
|
|
|
markupDef, '\0');
|
2017-07-28 15:04:54 +00:00
|
|
|
Definition* commentChild = &markupDef->fTokens.back();
|
|
|
|
markupChild->fChildren.emplace_back(commentChild);
|
|
|
|
parser.skipTo(end);
|
|
|
|
} while (!parser.eof());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::parseMethod(Definition* child, Definition* markupDef) {
|
|
|
|
auto tokenIter = child->fParent->fTokens.begin();
|
|
|
|
std::advance(tokenIter, child->fParentIndex);
|
|
|
|
tokenIter = std::prev(tokenIter);
|
2017-10-26 11:58:48 +00:00
|
|
|
const char* nameEnd = tokenIter->fContentEnd;
|
2017-11-27 15:44:06 +00:00
|
|
|
bool addConst = false;
|
|
|
|
auto operatorCheck = tokenIter;
|
|
|
|
if ('[' == tokenIter->fStart[0] || '*' == tokenIter->fStart[0]) {
|
|
|
|
operatorCheck = std::prev(tokenIter);
|
|
|
|
}
|
|
|
|
if (KeyWord::kOperator == operatorCheck->fKeyWord) {
|
2017-10-26 11:58:48 +00:00
|
|
|
auto closeParen = std::next(tokenIter);
|
|
|
|
SkASSERT(Definition::Type::kBracket == closeParen->fType &&
|
|
|
|
'(' == closeParen->fContentStart[0]);
|
|
|
|
nameEnd = closeParen->fContentEnd + 1;
|
|
|
|
closeParen = std::next(closeParen);
|
|
|
|
if (Definition::Type::kKeyWord == closeParen->fType &&
|
|
|
|
KeyWord::kConst == closeParen->fKeyWord) {
|
2017-11-27 15:44:06 +00:00
|
|
|
addConst = true;
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
2017-11-27 15:44:06 +00:00
|
|
|
tokenIter = operatorCheck;
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
|
|
|
string nameStr(tokenIter->fStart, nameEnd - tokenIter->fStart);
|
2017-11-27 15:44:06 +00:00
|
|
|
if (addConst) {
|
|
|
|
nameStr += "_const";
|
2017-10-26 11:58:48 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
while (tokenIter != child->fParent->fTokens.begin()) {
|
|
|
|
auto testIter = std::prev(tokenIter);
|
|
|
|
switch (testIter->fType) {
|
|
|
|
case Definition::Type::kWord:
|
2017-10-26 11:58:48 +00:00
|
|
|
if (testIter == child->fParent->fTokens.begin() &&
|
|
|
|
(KeyWord::kIfdef == child->fParent->fKeyWord ||
|
|
|
|
KeyWord::kIfndef == child->fParent->fKeyWord ||
|
|
|
|
KeyWord::kIf == child->fParent->fKeyWord)) {
|
|
|
|
std::next(tokenIter);
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
goto keepGoing;
|
|
|
|
case Definition::Type::kKeyWord: {
|
|
|
|
KeyProperty keyProperty = kKeyWords[(int) testIter->fKeyWord].fProperty;
|
|
|
|
if (KeyProperty::kNumber == keyProperty || KeyProperty::kModifier == keyProperty) {
|
|
|
|
goto keepGoing;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Definition::Type::kBracket:
|
|
|
|
if (Bracket::kAngle == testIter->fBracket) {
|
|
|
|
goto keepGoing;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Definition::Type::kPunctuation:
|
|
|
|
if (Punctuation::kSemicolon == testIter->fPunctuation
|
|
|
|
|| Punctuation::kLeftBrace == testIter->fPunctuation
|
|
|
|
|| Punctuation::kColon == testIter->fPunctuation) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
keepGoing:
|
|
|
|
tokenIter = testIter;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-06-27 15:00:21 +00:00
|
|
|
tokenIter->fName = nameStr; // simple token stream, OK if name is duplicate
|
2017-07-28 15:04:54 +00:00
|
|
|
tokenIter->fMarkType = MarkType::kMethod;
|
2017-10-11 14:37:52 +00:00
|
|
|
tokenIter->fPrivate = string::npos != nameStr.find("::");
|
2017-07-28 15:04:54 +00:00
|
|
|
auto testIter = child->fParent->fTokens.begin();
|
|
|
|
SkASSERT(child->fParentIndex > 0);
|
|
|
|
std::advance(testIter, child->fParentIndex - 1);
|
2017-10-11 14:37:52 +00:00
|
|
|
if (tokenIter->fParent && KeyWord::kIfdef == tokenIter->fParent->fKeyWord &&
|
|
|
|
0 == tokenIter->fParentIndex) {
|
|
|
|
tokenIter = std::next(tokenIter);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
const char* start = tokenIter->fContentStart;
|
|
|
|
const char* end = tokenIter->fContentEnd;
|
|
|
|
const char kDebugCodeStr[] = "SkDEBUGCODE";
|
|
|
|
const size_t kDebugCodeLen = sizeof(kDebugCodeStr) - 1;
|
|
|
|
if (end - start == kDebugCodeLen && !strncmp(start, kDebugCodeStr, kDebugCodeLen)) {
|
|
|
|
std::advance(testIter, 1);
|
|
|
|
start = testIter->fContentStart + 1;
|
|
|
|
end = testIter->fContentEnd - 1;
|
|
|
|
} else {
|
|
|
|
end = testIter->fContentEnd;
|
|
|
|
while (testIter != child->fParent->fTokens.end()) {
|
|
|
|
testIter = std::next(testIter);
|
|
|
|
switch (testIter->fType) {
|
|
|
|
case Definition::Type::kPunctuation:
|
|
|
|
SkASSERT(Punctuation::kSemicolon == testIter->fPunctuation
|
|
|
|
|| Punctuation::kLeftBrace == testIter->fPunctuation
|
|
|
|
|| Punctuation::kColon == testIter->fPunctuation);
|
|
|
|
end = testIter->fStart;
|
|
|
|
break;
|
|
|
|
case Definition::Type::kKeyWord: {
|
|
|
|
KeyProperty keyProperty = kKeyWords[(int) testIter->fKeyWord].fProperty;
|
|
|
|
if (KeyProperty::kNumber == keyProperty || KeyProperty::kModifier == keyProperty) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-09-14 15:25:39 +00:00
|
|
|
while (end > start && ' ' >= end[-1]) {
|
|
|
|
--end;
|
|
|
|
}
|
2017-09-19 21:39:32 +00:00
|
|
|
if (!markupDef) {
|
|
|
|
auto parentIter = child->fParent->fTokens.begin();
|
|
|
|
SkASSERT(child->fParentIndex > 0);
|
|
|
|
std::advance(parentIter, child->fParentIndex - 1);
|
|
|
|
Definition* methodName = &*parentIter;
|
2017-11-27 15:44:06 +00:00
|
|
|
TextParser nameParser(methodName);
|
|
|
|
if (nameParser.skipToEndBracket(':') && nameParser.startsWith("::")) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return true; // expect this is inline class definition outside of class
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
fGlobals.emplace_back(MarkType::kMethod, start, end, tokenIter->fLineCount,
|
|
|
|
fParent, '\0');
|
|
|
|
Definition* globalMarkupChild = &fGlobals.back();
|
|
|
|
string globalUniqueName = this->uniqueName(fIFunctionMap, nameStr);
|
|
|
|
globalMarkupChild->fName = globalUniqueName;
|
|
|
|
if (!this->findComments(*child, globalMarkupChild)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fIFunctionMap[globalUniqueName] = globalMarkupChild;
|
2017-11-27 15:44:06 +00:00
|
|
|
return true;
|
2017-09-19 21:39:32 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
markupDef->fTokens.emplace_back(MarkType::kMethod, start, end, tokenIter->fLineCount,
|
2018-03-05 18:26:16 +00:00
|
|
|
markupDef, '\0');
|
2017-07-28 15:04:54 +00:00
|
|
|
Definition* markupChild = &markupDef->fTokens.back();
|
2018-06-27 15:00:21 +00:00
|
|
|
// TODO: I wonder if there is a way to prevent looking up by operator[] (creating empty) ?
|
|
|
|
{
|
|
|
|
auto mapIter = fIClassMap.find(markupDef->fName);
|
|
|
|
SkASSERT(fIClassMap.end() != mapIter);
|
|
|
|
IClassDefinition& classDef = mapIter->second;
|
|
|
|
SkASSERT(classDef.fStart);
|
|
|
|
string uniqueName = this->uniqueName(classDef.fMethods, nameStr);
|
|
|
|
markupChild->fName = uniqueName;
|
|
|
|
if (!this->findComments(*child, markupChild)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
classDef.fMethods[uniqueName] = markupChild;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::parseObjects(Definition* parent, Definition* markupDef) {
|
2018-06-07 13:59:07 +00:00
|
|
|
fPriorObject = nullptr;
|
|
|
|
for (auto child : parent->fChildren) {
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!this->parseObject(child, markupDef)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
fPriorObject = child;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::parseObject(Definition* child, Definition* markupDef) {
|
|
|
|
// set up for error reporting
|
|
|
|
fLine = fChar = child->fStart;
|
|
|
|
fEnd = child->fContentEnd;
|
|
|
|
// todo: put original line number in child as well
|
|
|
|
switch (child->fType) {
|
|
|
|
case Definition::Type::kKeyWord:
|
|
|
|
switch (child->fKeyWord) {
|
2017-10-09 19:45:33 +00:00
|
|
|
case KeyWord::kClass:
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!this->parseClass(child, IsStruct::kNo)) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return false;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-04-26 12:32:37 +00:00
|
|
|
case KeyWord::kStatic:
|
2018-06-07 13:59:07 +00:00
|
|
|
case KeyWord::kConst:
|
|
|
|
case KeyWord::kConstExpr:
|
2018-04-26 12:32:37 +00:00
|
|
|
if (!this->parseConst(child, markupDef)) {
|
|
|
|
return child->reportError<bool>("failed to parse const or constexpr");
|
|
|
|
}
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kEnum:
|
|
|
|
if (!this->parseEnum(child, markupDef)) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("failed to parse enum");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KeyWord::kStruct:
|
|
|
|
if (!this->parseClass(child, IsStruct::kYes)) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("failed to parse struct");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KeyWord::kTemplate:
|
2018-03-09 20:32:01 +00:00
|
|
|
if (!this->parseTemplate(child, markupDef)) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("failed to parse template");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KeyWord::kTypedef:
|
2017-12-11 21:03:17 +00:00
|
|
|
if (!this->parseTypedef(child, markupDef)) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("failed to parse typedef");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KeyWord::kUnion:
|
|
|
|
if (!this->parseUnion()) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("failed to parse union");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("unhandled keyword");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Definition::Type::kBracket:
|
|
|
|
switch (child->fBracket) {
|
|
|
|
case Bracket::kParen:
|
2017-08-29 21:36:51 +00:00
|
|
|
if (fLastObject) {
|
|
|
|
TextParser checkDeprecated(child->fFileName, fLastObject->fTerminator + 1,
|
|
|
|
child->fStart, fLastObject->fLineCount);
|
2017-09-19 21:39:32 +00:00
|
|
|
if (!checkDeprecated.eof()) {
|
|
|
|
checkDeprecated.skipWhiteSpace();
|
2018-03-19 13:04:10 +00:00
|
|
|
if (checkDeprecated.startsWith(gAttrDeprecated)) {
|
|
|
|
fAttrDeprecated = child;
|
2017-09-19 21:39:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto tokenIter = child->fParent->fTokens.begin();
|
|
|
|
std::advance(tokenIter, child->fParentIndex);
|
|
|
|
tokenIter = std::prev(tokenIter);
|
2018-01-03 13:37:53 +00:00
|
|
|
TextParser previousToken(&*tokenIter);
|
2018-03-19 13:04:10 +00:00
|
|
|
if (previousToken.startsWith(gAttrDeprecated)) {
|
|
|
|
fAttrDeprecated = &*tokenIter;
|
2017-08-29 21:36:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-08-10 17:09:13 +00:00
|
|
|
if (this->isMember(*tokenIter)) {
|
2018-06-14 19:34:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-01-03 13:37:53 +00:00
|
|
|
if (Bracket::kPound == child->fParent->fBracket &&
|
|
|
|
KeyWord::kIf == child->fParent->fKeyWord) {
|
|
|
|
// TODO: this will skip methods named defined() -- for the
|
|
|
|
// moment there aren't any
|
|
|
|
if (previousToken.startsWith("defined")) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-07-12 20:24:53 +00:00
|
|
|
if (previousToken.startsWith("sizeof") && 6 == previousToken.lineLength()) {
|
|
|
|
break;
|
|
|
|
}
|
2017-08-29 21:36:51 +00:00
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fPriorObject && MarkType::kConst == fPriorObject->fMarkType) {
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!this->parseMethod(child, markupDef)) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("failed to parse method");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-03-19 13:04:10 +00:00
|
|
|
if (fAttrDeprecated) {
|
|
|
|
Definition* lastMethod = &markupDef->fTokens.back();
|
|
|
|
lastMethod->fDeprecated = true;
|
|
|
|
fAttrDeprecated = nullptr;
|
|
|
|
}
|
2017-08-29 21:36:51 +00:00
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case Bracket::kSlashSlash:
|
|
|
|
case Bracket::kSlashStar:
|
|
|
|
// comments are picked up by parsing objects first
|
|
|
|
break;
|
|
|
|
case Bracket::kPound:
|
|
|
|
// special-case the #xxx xxx_DEFINED entries
|
|
|
|
switch (child->fKeyWord) {
|
2017-11-27 15:44:06 +00:00
|
|
|
case KeyWord::kIf:
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kIfndef:
|
|
|
|
case KeyWord::kIfdef:
|
2018-04-16 12:37:38 +00:00
|
|
|
if (child->boilerplateIfDef()) {
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!this->parseObjects(child, markupDef)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto preproError;
|
|
|
|
case KeyWord::kDefine:
|
2018-04-16 12:37:38 +00:00
|
|
|
if (this->parseDefine(child, markupDef)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto preproError;
|
|
|
|
case KeyWord::kEndif:
|
|
|
|
if (child->boilerplateEndIf()) {
|
|
|
|
break;
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
case KeyWord::kError:
|
2017-07-28 15:04:54 +00:00
|
|
|
case KeyWord::kInclude:
|
|
|
|
// ignored for now
|
|
|
|
break;
|
|
|
|
case KeyWord::kElse:
|
|
|
|
case KeyWord::kElif:
|
|
|
|
// todo: handle these
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
preproError:
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("unhandled preprocessor");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Bracket::kAngle:
|
|
|
|
// pick up templated function pieces when method is found
|
|
|
|
break;
|
2017-08-29 21:36:51 +00:00
|
|
|
case Bracket::kDebugCode:
|
2017-10-26 11:58:48 +00:00
|
|
|
if (!this->parseObjects(child, markupDef)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-29 21:36:51 +00:00
|
|
|
break;
|
2017-09-19 21:39:32 +00:00
|
|
|
case Bracket::kSquare: {
|
|
|
|
// check to see if parent is operator, the only case we handle so far
|
|
|
|
auto prev = child->fParent->fTokens.begin();
|
|
|
|
std::advance(prev, child->fParentIndex - 1);
|
|
|
|
if (KeyWord::kOperator != prev->fKeyWord) {
|
|
|
|
return child->reportError<bool>("expected operator overload");
|
|
|
|
}
|
|
|
|
} break;
|
2017-07-28 15:04:54 +00:00
|
|
|
default:
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("unhandled bracket");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Definition::Type::kWord:
|
|
|
|
if (MarkType::kMember != child->fMarkType) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("unhandled word type");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (!this->parseMember(child, markupDef)) {
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("unparsable member");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2017-09-19 21:39:32 +00:00
|
|
|
return child->reportError<bool>("unhandled type");
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:32:01 +00:00
|
|
|
bool IncludeParser::parseTemplate(Definition* child, Definition* markupDef) {
|
|
|
|
return this->parseObjects(child, markupDef);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 21:03:17 +00:00
|
|
|
bool IncludeParser::parseTypedef(Definition* child, Definition* markupDef) {
|
|
|
|
TextParser typedefParser(child);
|
2018-01-02 16:34:14 +00:00
|
|
|
typedefParser.skipExact("typedef");
|
|
|
|
typedefParser.skipWhiteSpace();
|
2017-12-11 21:03:17 +00:00
|
|
|
string nameStr = typedefParser.typedefName();
|
|
|
|
if (!markupDef) {
|
2018-04-16 12:37:38 +00:00
|
|
|
fGlobals.emplace_back(MarkType::kTypedef, child->fContentStart, child->fContentEnd,
|
|
|
|
child->fLineCount, fParent, '\0');
|
|
|
|
Definition* globalMarkupChild = &fGlobals.back();
|
|
|
|
string globalUniqueName = this->uniqueName(fITypedefMap, nameStr);
|
|
|
|
globalMarkupChild->fName = globalUniqueName;
|
|
|
|
if (!this->findComments(*child, globalMarkupChild)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fITypedefMap[globalUniqueName] = globalMarkupChild;
|
2018-06-07 13:59:07 +00:00
|
|
|
child->fName = nameStr;
|
2017-12-11 21:03:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
markupDef->fTokens.emplace_back(MarkType::kTypedef, child->fContentStart, child->fContentEnd,
|
2018-03-05 18:26:16 +00:00
|
|
|
child->fLineCount, markupDef, '\0');
|
2017-12-11 21:03:17 +00:00
|
|
|
Definition* markupChild = &markupDef->fTokens.back();
|
|
|
|
markupChild->fName = nameStr;
|
|
|
|
markupChild->fTerminator = markupChild->fContentEnd;
|
|
|
|
IClassDefinition& classDef = fIClassMap[markupDef->fName];
|
|
|
|
classDef.fTypedefs[nameStr] = markupChild;
|
2018-06-07 13:59:07 +00:00
|
|
|
child->fName = markupDef->fName + "::" + nameStr;
|
2017-07-28 15:04:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::parseUnion() {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IncludeParser::parseChar() {
|
|
|
|
char test = *fChar;
|
|
|
|
if ('\\' == fPrev) {
|
|
|
|
if ('\n' == test) {
|
2017-09-14 15:25:39 +00:00
|
|
|
// ++fLineCount;
|
2017-07-28 15:04:54 +00:00
|
|
|
fLine = fChar + 1;
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
switch (test) {
|
|
|
|
case '\n':
|
2017-09-14 15:25:39 +00:00
|
|
|
// ++fLineCount;
|
2017-07-28 15:04:54 +00:00
|
|
|
fLine = fChar + 1;
|
|
|
|
if (fInChar) {
|
|
|
|
return reportError<bool>("malformed char");
|
|
|
|
}
|
|
|
|
if (fInString) {
|
|
|
|
return reportError<bool>("malformed string");
|
|
|
|
}
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Bracket::kPound == this->topBracket()) {
|
|
|
|
KeyWord keyWord = fParent->fKeyWord;
|
|
|
|
if (KeyWord::kNone == keyWord) {
|
|
|
|
return this->reportError<bool>("unhandled preprocessor directive");
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (fInDefine) {
|
|
|
|
SkASSERT(KeyWord::kDefine == keyWord);
|
|
|
|
fInDefine = false;
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
if (KeyWord::kInclude == keyWord || KeyWord::kDefine == keyWord || KeyWord::kError == keyWord) {
|
2017-07-28 15:04:54 +00:00
|
|
|
this->popBracket();
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (fInBrace) {
|
|
|
|
SkASSERT(KeyWord::kDefine == fInBrace->fKeyWord);
|
|
|
|
fInBrace = nullptr;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
} else if (Bracket::kSlashSlash == this->topBracket()) {
|
|
|
|
this->popBracket();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
if (!fInCharCommentString && '/' == fPrev) {
|
|
|
|
this->pushBracket(Bracket::kSlashStar);
|
|
|
|
}
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!fInCharCommentString) {
|
|
|
|
this->addPunctuation(Punctuation::kAsterisk);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
if ('*' == fPrev) {
|
|
|
|
if (!fInCharCommentString) {
|
|
|
|
return reportError<bool>("malformed closing comment");
|
|
|
|
}
|
|
|
|
if (Bracket::kSlashStar == this->topBracket()) {
|
2018-04-03 12:43:27 +00:00
|
|
|
TextParserSave save(this);
|
2017-11-27 15:44:06 +00:00
|
|
|
this->next(); // include close in bracket
|
2017-07-28 15:04:54 +00:00
|
|
|
this->popBracket();
|
2017-11-27 15:44:06 +00:00
|
|
|
save.restore(); // put things back so nothing is skipped
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-10-09 19:45:33 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!fInCharCommentString && '/' == fPrev) {
|
|
|
|
this->pushBracket(Bracket::kSlashSlash);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
if (Bracket::kChar == this->topBracket()) {
|
|
|
|
this->popBracket();
|
|
|
|
} else if (!fInComment && !fInString) {
|
|
|
|
if (fIncludeWord) {
|
|
|
|
return this->reportError<bool>("word then single-quote");
|
|
|
|
}
|
|
|
|
this->pushBracket(Bracket::kChar);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\"':
|
|
|
|
if (Bracket::kString == this->topBracket()) {
|
|
|
|
this->popBracket();
|
|
|
|
} else if (!fInComment && !fInChar) {
|
|
|
|
if (fIncludeWord) {
|
|
|
|
return this->reportError<bool>("word then double-quote");
|
|
|
|
}
|
|
|
|
this->pushBracket(Bracket::kString);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '(':
|
2018-04-16 12:37:38 +00:00
|
|
|
if (fIncludeWord && fChar - fIncludeWord >= 10 &&
|
2017-08-29 21:36:51 +00:00
|
|
|
!strncmp("SkDEBUGCODE", fIncludeWord, 10)) {
|
|
|
|
this->pushBracket(Bracket::kDebugCode);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
case ':':
|
|
|
|
case '[':
|
|
|
|
case '{': {
|
2017-07-28 15:04:54 +00:00
|
|
|
if (fInCharCommentString) {
|
|
|
|
break;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (fInDefine && fInBrace) {
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (':' == test && (fInBrace || ':' == fChar[-1] || ':' == fChar[1])) {
|
|
|
|
break;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fConstExpr) {
|
|
|
|
fConstExpr->fContentEnd = fParent->fTokens.back().fContentEnd;
|
|
|
|
fConstExpr = nullptr;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!fInBrace) {
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (':' == test && !fInFunction) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ('{' == test) {
|
|
|
|
this->addPunctuation(Punctuation::kLeftBrace);
|
|
|
|
} else if (':' == test) {
|
|
|
|
this->addPunctuation(Punctuation::kColon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fInBrace && '{' == test && Definition::Type::kBracket == fInBrace->fType
|
|
|
|
&& Bracket::kColon == fInBrace->fBracket) {
|
|
|
|
Definition* braceParent = fParent->fParent;
|
|
|
|
braceParent->fChildren.pop_back();
|
|
|
|
braceParent->fTokens.pop_back();
|
|
|
|
fParent = braceParent;
|
|
|
|
fInBrace = nullptr;
|
|
|
|
}
|
|
|
|
this->pushBracket(
|
|
|
|
'(' == test ? Bracket::kParen :
|
|
|
|
'[' == test ? Bracket::kSquare :
|
|
|
|
'{' == test ? Bracket::kBrace :
|
|
|
|
Bracket::kColon);
|
|
|
|
if (!fInBrace
|
|
|
|
&& ('{' == test || (':' == test && ' ' >= fChar[1]))
|
|
|
|
&& fInFunction) {
|
|
|
|
fInBrace = fParent;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case '<':
|
|
|
|
if (fInCharCommentString || fInBrace) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (fInEnum) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->pushBracket(Bracket::kAngle);
|
2018-06-27 15:00:21 +00:00
|
|
|
// this angle bracket may be an operator or may be a bracket
|
|
|
|
// wait for balancing close angle, if any, to decide
|
2017-07-28 15:04:54 +00:00
|
|
|
break;
|
|
|
|
case ')':
|
|
|
|
case ']':
|
|
|
|
case '}': {
|
|
|
|
if (fInCharCommentString) {
|
|
|
|
break;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
if (fInDefine && fInBrace) {
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (!fInBrace) {
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool popBraceParent = fInBrace == fParent;
|
2018-06-27 15:00:21 +00:00
|
|
|
Bracket match = ')' == test ? Bracket::kParen :
|
|
|
|
']' == test ? Bracket::kSquare : Bracket::kBrace;
|
|
|
|
if (match == this->topBracket()) {
|
2017-07-28 15:04:54 +00:00
|
|
|
this->popBracket();
|
|
|
|
if (!fInFunction) {
|
2018-08-10 17:09:13 +00:00
|
|
|
fInFunction = ')' == test && !this->inAlignAs();
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
|
|
|
fInFunction = '}' != test;
|
|
|
|
}
|
2017-08-29 21:36:51 +00:00
|
|
|
} else if (')' == test && Bracket::kDebugCode == this->topBracket()) {
|
|
|
|
this->popBracket();
|
2018-06-27 15:00:21 +00:00
|
|
|
} else if (Bracket::kAngle == this->topBracket()
|
|
|
|
&& match == this->grandParentBracket()) {
|
|
|
|
this->popBracket();
|
|
|
|
this->popBracket();
|
2017-07-28 15:04:54 +00:00
|
|
|
} else {
|
|
|
|
return reportError<bool>("malformed close bracket");
|
|
|
|
}
|
|
|
|
if (popBraceParent) {
|
|
|
|
Definition* braceParent = fInBrace->fParent;
|
|
|
|
braceParent->fChildren.pop_back();
|
|
|
|
braceParent->fTokens.pop_back();
|
|
|
|
fInBrace = nullptr;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case '>':
|
|
|
|
if (fInCharCommentString || fInBrace) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (fInEnum) {
|
|
|
|
break;
|
|
|
|
}
|
2017-11-27 15:44:06 +00:00
|
|
|
if (Bracket::kPound == this->topBracket()) {
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (Bracket::kAngle == this->topBracket()) {
|
2018-06-27 15:00:21 +00:00
|
|
|
// looks like angle pair are braces, not operators
|
2017-07-28 15:04:54 +00:00
|
|
|
this->popBracket();
|
|
|
|
} else {
|
|
|
|
return reportError<bool>("malformed close angle bracket");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '#': {
|
|
|
|
if (fInCharCommentString || fInBrace) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SkASSERT(!fIncludeWord); // don't expect this, curious if it is triggered
|
|
|
|
this->pushBracket(Bracket::kPound);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-16 12:37:38 +00:00
|
|
|
case ' ':
|
|
|
|
if (fInDefine && !fInBrace && Bracket::kPound == this->topBracket()) {
|
|
|
|
SkASSERT(KeyWord::kDefine == fParent->fKeyWord);
|
|
|
|
fInBrace = fParent;
|
|
|
|
// delimiting brackets are space ... unescaped-linefeed
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
case '&':
|
|
|
|
case ',':
|
2017-11-27 15:44:06 +00:00
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
case '!':
|
2017-07-28 15:04:54 +00:00
|
|
|
if (fInCharCommentString || fInBrace) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2018-06-07 13:59:07 +00:00
|
|
|
case '=':
|
|
|
|
if (fInCharCommentString || fInBrace) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-18 19:10:08 +00:00
|
|
|
if (!fParent->fTokens.size()) {
|
|
|
|
break;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
{
|
|
|
|
const Definition& lastToken = fParent->fTokens.back();
|
|
|
|
if (lastToken.fType != Definition::Type::kWord) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
string name(lastToken.fContentStart, lastToken.length());
|
|
|
|
if ("SK_" != name.substr(0, 3) && 'k' != name[0]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// find token on start of line
|
|
|
|
auto lineIter = fParent->fTokens.end();
|
|
|
|
do {
|
2018-07-11 20:18:41 +00:00
|
|
|
if (fParent->fTokens.begin() == lineIter) {
|
|
|
|
break;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
--lineIter;
|
|
|
|
} while (lineIter->fContentStart > fLine);
|
2018-07-11 20:18:41 +00:00
|
|
|
if (lineIter->fContentStart < fLine && fParent->fTokens.end() != lineIter) {
|
2018-06-07 13:59:07 +00:00
|
|
|
++lineIter;
|
|
|
|
}
|
|
|
|
Definition* lineStart = &*lineIter;
|
|
|
|
// walk tokens looking for [template <typename T>] [static] [const | constexpr]
|
|
|
|
bool sawConst = false;
|
|
|
|
bool sawStatic = false;
|
|
|
|
bool sawTemplate = false;
|
|
|
|
bool sawType = false;
|
|
|
|
while (&lastToken != &*lineIter) {
|
|
|
|
if (KeyWord::kTemplate == lineIter->fKeyWord) {
|
|
|
|
if (sawConst || sawStatic || sawTemplate) {
|
|
|
|
sawConst = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (&lastToken == &*++lineIter) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (KeyWord::kTypename != lineIter->fKeyWord) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (&lastToken == &*++lineIter) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kWord != lineIter->fType) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sawTemplate = true;
|
|
|
|
} else if (KeyWord::kStatic == lineIter->fKeyWord) {
|
|
|
|
if (sawConst || sawStatic) {
|
|
|
|
sawConst = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sawStatic = true;
|
|
|
|
} else if (KeyWord::kConst == lineIter->fKeyWord
|
|
|
|
|| KeyWord::kConstExpr == lineIter->fKeyWord) {
|
|
|
|
if (sawConst) {
|
|
|
|
sawConst = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sawConst = true;
|
|
|
|
} else {
|
|
|
|
if (sawType) {
|
|
|
|
sawType = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Definition::Type::kKeyWord == lineIter->fType
|
|
|
|
&& KeyProperty::kNumber
|
|
|
|
== kKeyWords[(int) lineIter->fKeyWord].fProperty) {
|
|
|
|
sawType = true;
|
|
|
|
} else if (Definition::Type::kWord == lineIter->fType) {
|
|
|
|
string typeName(lineIter->fContentStart, lineIter->length());
|
|
|
|
if ("Sk" != name.substr(0, 2)) {
|
|
|
|
sawType = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++lineIter;
|
|
|
|
}
|
|
|
|
if (sawType && sawConst) {
|
|
|
|
// if found, name first
|
|
|
|
lineStart->fName = name;
|
|
|
|
lineStart->fMarkType = MarkType::kConst;
|
|
|
|
fParent->fChildren.emplace_back(lineStart);
|
|
|
|
fConstExpr = lineStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-07-28 15:04:54 +00:00
|
|
|
case ';':
|
|
|
|
if (fInCharCommentString || fInBrace) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!this->checkForWord()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-07 13:59:07 +00:00
|
|
|
if (fConstExpr) {
|
|
|
|
fConstExpr->fContentEnd = fParent->fTokens.back().fContentEnd;
|
|
|
|
fConstExpr = nullptr;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (Definition::Type::kKeyWord == fParent->fType
|
|
|
|
&& KeyProperty::kObject == (kKeyWords[(int) fParent->fKeyWord].fProperty)) {
|
2018-03-09 20:32:01 +00:00
|
|
|
bool parentIsClass = KeyWord::kClass == fParent->fKeyWord;
|
|
|
|
if (parentIsClass && fParent->fParent &&
|
2017-08-03 21:14:08 +00:00
|
|
|
KeyWord::kEnum == fParent->fParent->fKeyWord) {
|
|
|
|
this->popObject();
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (KeyWord::kEnum == fParent->fKeyWord) {
|
|
|
|
fInEnum = false;
|
|
|
|
}
|
|
|
|
this->popObject();
|
2018-03-09 20:32:01 +00:00
|
|
|
if (parentIsClass && fParent && KeyWord::kTemplate == fParent->fKeyWord) {
|
|
|
|
this->popObject();
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
fPriorEnum = nullptr;
|
2017-07-28 15:04:54 +00:00
|
|
|
} else if (Definition::Type::kBracket == fParent->fType
|
|
|
|
&& fParent->fParent && Definition::Type::kKeyWord == fParent->fParent->fType
|
|
|
|
&& KeyWord::kStruct == fParent->fParent->fKeyWord) {
|
|
|
|
list<Definition>::iterator baseIter = fParent->fTokens.end();
|
|
|
|
list<Definition>::iterator namedIter = fParent->fTokens.end();
|
|
|
|
for (auto tokenIter = fParent->fTokens.end();
|
2018-07-11 20:18:41 +00:00
|
|
|
fParent->fTokens.begin() != tokenIter; ) {
|
|
|
|
--tokenIter;
|
2017-07-28 15:04:54 +00:00
|
|
|
if (tokenIter->fLineCount == fLineCount) {
|
2018-08-10 17:09:13 +00:00
|
|
|
if (this->isMember(*tokenIter)) {
|
2017-07-28 15:04:54 +00:00
|
|
|
if (namedIter != fParent->fTokens.end()) {
|
|
|
|
return reportError<bool>("found two named member tokens");
|
|
|
|
}
|
|
|
|
namedIter = tokenIter;
|
|
|
|
}
|
|
|
|
baseIter = tokenIter;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FIXME: if a member definition spans multiple lines, this won't work
|
|
|
|
if (namedIter != fParent->fTokens.end()) {
|
|
|
|
if (baseIter == namedIter) {
|
|
|
|
return this->reportError<bool>("expected type before named token");
|
|
|
|
}
|
|
|
|
Definition* member = &*namedIter;
|
|
|
|
member->fMarkType = MarkType::kMember;
|
2017-09-19 21:39:32 +00:00
|
|
|
if (!member->fTerminator) {
|
|
|
|
member->fTerminator = member->fContentEnd;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
fParent->fChildren.push_back(member);
|
|
|
|
for (auto nameType = baseIter; nameType != namedIter; ++nameType) {
|
|
|
|
member->fChildren.push_back(&*nameType);
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
fPriorEnum = nullptr;
|
2017-07-28 15:04:54 +00:00
|
|
|
} else if (fParent->fChildren.size() > 0) {
|
|
|
|
auto lastIter = fParent->fChildren.end();
|
2018-01-04 21:11:51 +00:00
|
|
|
Definition* priorEnum = fPriorEnum;
|
|
|
|
fPriorEnum = nullptr;
|
|
|
|
if (!priorEnum) {
|
|
|
|
while (fParent->fChildren.begin() != lastIter) {
|
|
|
|
std::advance(lastIter, -1);
|
|
|
|
priorEnum = *lastIter;
|
|
|
|
if (Definition::Type::kBracket != priorEnum->fType ||
|
|
|
|
(Bracket::kSlashSlash != priorEnum->fBracket
|
|
|
|
&& Bracket::kSlashStar != priorEnum->fBracket)) {
|
|
|
|
break;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
fPriorIndex = priorEnum->fParentIndex;
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
if (Definition::Type::kKeyWord == priorEnum->fType
|
|
|
|
&& KeyWord::kEnum == priorEnum->fKeyWord) {
|
|
|
|
auto tokenWalker = fParent->fTokens.begin();
|
2018-01-04 21:11:51 +00:00
|
|
|
std::advance(tokenWalker, fPriorIndex);
|
2017-07-28 15:04:54 +00:00
|
|
|
while (tokenWalker != fParent->fTokens.end()) {
|
|
|
|
std::advance(tokenWalker, 1);
|
2018-01-04 21:11:51 +00:00
|
|
|
++fPriorIndex;
|
2017-07-28 15:04:54 +00:00
|
|
|
if (Punctuation::kSemicolon == tokenWalker->fPunctuation) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (tokenWalker != fParent->fTokens.end()) {
|
|
|
|
std::advance(tokenWalker, 1);
|
|
|
|
const Definition* test = &*tokenWalker;
|
|
|
|
if (Definition::Type::kBracket != test->fType ||
|
|
|
|
(Bracket::kSlashSlash != test->fBracket
|
|
|
|
&& Bracket::kSlashStar != test->fBracket)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
auto saveTokenWalker = tokenWalker;
|
2017-07-28 15:04:54 +00:00
|
|
|
Definition* start = &*tokenWalker;
|
|
|
|
bool foundExpected = true;
|
|
|
|
for (KeyWord expected : {KeyWord::kStatic, KeyWord::kConstExpr, KeyWord::kInt}){
|
|
|
|
const Definition* test = &*tokenWalker;
|
|
|
|
if (expected != test->fKeyWord) {
|
|
|
|
foundExpected = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tokenWalker == fParent->fTokens.end()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
std::advance(tokenWalker, 1);
|
|
|
|
}
|
2018-01-04 21:11:51 +00:00
|
|
|
if (!foundExpected) {
|
|
|
|
foundExpected = true;
|
|
|
|
tokenWalker = saveTokenWalker;
|
|
|
|
for (KeyWord expected : {KeyWord::kStatic, KeyWord::kConst, KeyWord::kNone}){
|
|
|
|
const Definition* test = &*tokenWalker;
|
|
|
|
if (expected != test->fKeyWord) {
|
|
|
|
foundExpected = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tokenWalker == fParent->fTokens.end()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (KeyWord::kNone != expected) {
|
|
|
|
std::advance(tokenWalker, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (foundExpected) {
|
|
|
|
auto nameToken = priorEnum->fTokens.begin();
|
|
|
|
string enumName = string(nameToken->fContentStart,
|
|
|
|
nameToken->fContentEnd - nameToken->fContentStart);
|
|
|
|
const Definition* test = &*tokenWalker;
|
|
|
|
string constType = string(test->fContentStart,
|
|
|
|
test->fContentEnd - test->fContentStart);
|
|
|
|
if (enumName != constType) {
|
|
|
|
foundExpected = false;
|
|
|
|
} else {
|
|
|
|
std::advance(tokenWalker, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
if (foundExpected && tokenWalker != fParent->fTokens.end()) {
|
|
|
|
const char* nameStart = tokenWalker->fStart;
|
|
|
|
std::advance(tokenWalker, 1);
|
|
|
|
if (tokenWalker != fParent->fTokens.end()) {
|
|
|
|
TextParser tp(fFileName, nameStart, tokenWalker->fStart, fLineCount);
|
2018-04-16 12:37:38 +00:00
|
|
|
tp.skipToNonName();
|
2017-07-28 15:04:54 +00:00
|
|
|
start->fName = string(nameStart, tp.fChar - nameStart);
|
|
|
|
start->fContentEnd = fChar;
|
|
|
|
priorEnum->fChildren.emplace_back(start);
|
2018-01-04 21:11:51 +00:00
|
|
|
fPriorEnum = priorEnum;
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->addPunctuation(Punctuation::kSemicolon);
|
|
|
|
fInFunction = false;
|
|
|
|
break;
|
|
|
|
case '~':
|
|
|
|
if (fInEnum) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
|
|
|
// TODO: don't want to parse numbers, but do need to track for enum defs
|
|
|
|
// break;
|
|
|
|
case 'A': case 'B': case 'C': case 'D': case 'E':
|
|
|
|
case 'F': case 'G': case 'H': case 'I': case 'J':
|
|
|
|
case 'K': case 'L': case 'M': case 'N': case 'O':
|
|
|
|
case 'P': case 'Q': case 'R': case 'S': case 'T':
|
|
|
|
case 'U': case 'V': case 'W': case 'X': case 'Y':
|
|
|
|
case 'Z': case '_':
|
|
|
|
case 'a': case 'b': case 'c': case 'd': case 'e':
|
|
|
|
case 'f': case 'g': case 'h': case 'i': case 'j':
|
|
|
|
case 'k': case 'l': case 'm': case 'n': case 'o':
|
|
|
|
case 'p': case 'q': case 'r': case 's': case 't':
|
|
|
|
case 'u': case 'v': case 'w': case 'x': case 'y':
|
2017-10-09 19:45:33 +00:00
|
|
|
case 'z':
|
2017-07-28 15:04:54 +00:00
|
|
|
if (fInCharCommentString || fInBrace) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!fIncludeWord) {
|
|
|
|
fIncludeWord = fChar;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
fPrev = test;
|
2017-09-14 15:25:39 +00:00
|
|
|
this->next();
|
2017-07-28 15:04:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeParser::validate() const {
|
|
|
|
IncludeParser::ValidateKeyWords();
|
|
|
|
}
|
2018-01-26 17:56:22 +00:00
|
|
|
|
2018-04-03 12:43:27 +00:00
|
|
|
bool IncludeParser::references(const SkString& file) const {
|
|
|
|
// if includes weren't passed one at a time, assume all references are valid
|
|
|
|
if (fIncludeMap.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SkASSERT(file.endsWith(".bmh") );
|
|
|
|
string root(file.c_str(), file.size() - 4);
|
|
|
|
string kReference("_Reference");
|
|
|
|
if (string::npos != root.find(kReference)) {
|
|
|
|
root = root.substr(0, root.length() - kReference.length());
|
|
|
|
}
|
|
|
|
if (fIClassMap.end() != fIClassMap.find(root)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (fIStructMap.end() != fIStructMap.find(root)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-06-27 15:00:21 +00:00
|
|
|
if (fIEnumMap.end() != fIEnumMap.find(root)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (fIFunctionMap.end() != fIFunctionMap.find(root)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-03 12:43:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
void IncludeParser::RemoveFile(const char* docs, const char* includes) {
|
|
|
|
if (!sk_isdir(includes)) {
|
|
|
|
IncludeParser::RemoveOneFile(docs, includes);
|
|
|
|
} else {
|
|
|
|
SkOSFile::Iter it(includes, ".h");
|
|
|
|
for (SkString file; it.next(&file); ) {
|
|
|
|
SkString p = SkOSPath::Join(includes, file.c_str());
|
|
|
|
const char* hunk = p.c_str();
|
|
|
|
if (!SkStrEndsWith(hunk, ".h")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
IncludeParser::RemoveOneFile(docs, hunk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncludeParser::RemoveOneFile(const char* docs, const char* includesFile) {
|
|
|
|
const char* lastForward = strrchr(includesFile, '/');
|
|
|
|
const char* lastBackward = strrchr(includesFile, '\\');
|
|
|
|
const char* last = lastForward > lastBackward ? lastForward : lastBackward;
|
|
|
|
if (!last) {
|
|
|
|
last = includesFile;
|
|
|
|
} else {
|
|
|
|
last += 1;
|
|
|
|
}
|
|
|
|
SkString baseName(last);
|
|
|
|
SkASSERT(baseName.endsWith(".h"));
|
|
|
|
baseName.remove(baseName.size() - 2, 2);
|
|
|
|
baseName.append("_Reference.bmh");
|
|
|
|
SkString fullName = SkOSPath::Join(docs, baseName.c_str());
|
|
|
|
remove(fullName.c_str());
|
|
|
|
}
|
2018-06-27 15:00:21 +00:00
|
|
|
|
|
|
|
Bracket IncludeParser::topBracket() const {
|
|
|
|
Definition* parent = this->parentBracket(fParent);
|
|
|
|
return parent ? parent->fBracket : Bracket::kNone;
|
|
|
|
}
|