diff options
author | Kitware Robot <kwrobot@kitware.com> | 2016-05-16 14:34:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-16 20:05:19 (GMT) |
commit | d9fd2f5402eeaa345691313658e02b51038f570b (patch) | |
tree | dca71b9a7e267f4c6300da3eb770415381726785 /Source/cmListFileCache.cxx | |
parent | 82df6deaafb36cbbfd450202bb20b320f637751a (diff) | |
download | CMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2 |
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.
* If you reached this commit for a line in `git blame`, re-run the blame
operation starting at the parent of this commit to see older history
for the content.
* See the parent commit for instructions to rebase a change across this
style transition commit.
Diffstat (limited to 'Source/cmListFileCache.cxx')
-rw-r--r-- | Source/cmListFileCache.cxx | 401 |
1 files changed, 164 insertions, 237 deletions
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 8788e41..f47e9b6 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -19,7 +19,6 @@ #include <cmsys/RegularExpression.hxx> - struct cmListFileParser { cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename); @@ -33,13 +32,20 @@ struct cmListFileParser const char* FileName; cmListFileLexer* Lexer; cmListFileFunction Function; - enum { SeparationOkay, SeparationWarning, SeparationError} Separation; + enum + { + SeparationOkay, + SeparationWarning, + SeparationError + } Separation; }; cmListFileParser::cmListFileParser(cmListFile* lf, cmMakefile* mf, - const char* filename): - ListFile(lf), Makefile(mf), FileName(filename), - Lexer(cmListFileLexer_New()) + const char* filename) + : ListFile(lf) + , Makefile(mf) + , FileName(filename) + , Lexer(cmListFileLexer_New()) { } @@ -52,58 +58,40 @@ bool cmListFileParser::ParseFile() { // Open the file. cmListFileLexer_BOM bom; - if(!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom)) - { + if (!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom)) { cmSystemTools::Error("cmListFileCache: error can not open file ", this->FileName); return false; - } + } // Verify the Byte-Order-Mark, if any. - if(bom != cmListFileLexer_BOM_None && - bom != cmListFileLexer_BOM_UTF8) - { + if (bom != cmListFileLexer_BOM_None && bom != cmListFileLexer_BOM_UTF8) { cmListFileLexer_SetFileName(this->Lexer, 0, 0); std::ostringstream m; m << "File\n " << this->FileName << "\n" << "starts with a Byte-Order-Mark that is not UTF-8."; this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str()); return false; - } + } // Use a simple recursive-descent parser to process the token // stream. bool haveNewline = true; - while(cmListFileLexer_Token* token = - cmListFileLexer_Scan(this->Lexer)) - { - if(token->type == cmListFileLexer_Token_Space) - { - } - else if(token->type == cmListFileLexer_Token_Newline) - { + while (cmListFileLexer_Token* token = cmListFileLexer_Scan(this->Lexer)) { + if (token->type == cmListFileLexer_Token_Space) { + } else if (token->type == cmListFileLexer_Token_Newline) { haveNewline = true; - } - else if(token->type == cmListFileLexer_Token_CommentBracket) - { + } else if (token->type == cmListFileLexer_Token_CommentBracket) { haveNewline = false; - } - else if(token->type == cmListFileLexer_Token_Identifier) - { - if(haveNewline) - { + } else if (token->type == cmListFileLexer_Token_Identifier) { + if (haveNewline) { haveNewline = false; - if(this->ParseFunction(token->text, token->line)) - { + if (this->ParseFunction(token->text, token->line)) { this->ListFile->Functions.push_back(this->Function); - } - else - { + } else { return false; - } } - else - { + } else { std::ostringstream error; error << "Error in cmake code at\n" << this->FileName << ":" << token->line << ":\n" @@ -112,63 +100,51 @@ bool cmListFileParser::ParseFile() << " with text \"" << token->text << "\"."; cmSystemTools::Error(error.str().c_str()); return false; - } } - else - { + } else { std::ostringstream error; error << "Error in cmake code at\n" << this->FileName << ":" << token->line << ":\n" << "Parse error. Expected a command name, got " << cmListFileLexer_GetTypeAsString(this->Lexer, token->type) - << " with text \"" - << token->text << "\"."; + << " with text \"" << token->text << "\"."; cmSystemTools::Error(error.str().c_str()); return false; - } } + } return true; } -bool cmListFile::ParseFile(const char* filename, - bool topLevel, - cmMakefile *mf) +bool cmListFile::ParseFile(const char* filename, bool topLevel, cmMakefile* mf) { - if(!cmSystemTools::FileExists(filename) || - cmSystemTools::FileIsDirectory(filename)) - { + if (!cmSystemTools::FileExists(filename) || + cmSystemTools::FileIsDirectory(filename)) { return false; - } + } bool parseError = false; { - cmListFileParser parser(this, mf, filename); - parseError = !parser.ParseFile(); + cmListFileParser parser(this, mf, filename); + parseError = !parser.ParseFile(); } // do we need a cmake_policy(VERSION call? - if(topLevel) - { + if (topLevel) { bool hasVersion = false; // search for the right policy command - for(std::vector<cmListFileFunction>::iterator i - = this->Functions.begin(); - i != this->Functions.end(); ++i) - { - if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required") - { + for (std::vector<cmListFileFunction>::iterator i = this->Functions.begin(); + i != this->Functions.end(); ++i) { + if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required") { hasVersion = true; break; } } // if no policy command is found this is an error if they use any // non advanced functions or a lot of functions - if(!hasVersion) - { + if (!hasVersion) { bool isProblem = true; - if (this->Functions.size() < 30) - { + if (this->Functions.size() < 30) { // the list of simple commands DO NOT ADD TO THIS LIST!!!!! // these commands must have backwards compatibility forever and // and that is a lot longer than your tiny mind can comprehend mortal @@ -185,59 +161,50 @@ bool cmListFile::ParseFile(const char* filename, allowedCommands.insert("option"); allowedCommands.insert("message"); isProblem = false; - for(std::vector<cmListFileFunction>::iterator i - = this->Functions.begin(); - i != this->Functions.end(); ++i) - { + for (std::vector<cmListFileFunction>::iterator i = + this->Functions.begin(); + i != this->Functions.end(); ++i) { std::string name = cmSystemTools::LowerCase(i->Name); - if (allowedCommands.find(name) == allowedCommands.end()) - { + if (allowedCommands.find(name) == allowedCommands.end()) { isProblem = true; break; } } } - if (isProblem) - { - // Tell the top level cmMakefile to diagnose - // this violation of CMP0000. - mf->SetCheckCMP0000(true); + if (isProblem) { + // Tell the top level cmMakefile to diagnose + // this violation of CMP0000. + mf->SetCheckCMP0000(true); - // Implicitly set the version for the user. - mf->SetPolicyVersion("2.4"); + // Implicitly set the version for the user. + mf->SetPolicyVersion("2.4"); } } } - if(topLevel) - { + if (topLevel) { bool hasProject = false; // search for a project command - for(std::vector<cmListFileFunction>::iterator i - = this->Functions.begin(); - i != this->Functions.end(); ++i) - { - if(cmSystemTools::LowerCase(i->Name) == "project") - { + for (std::vector<cmListFileFunction>::iterator i = this->Functions.begin(); + i != this->Functions.end(); ++i) { + if (cmSystemTools::LowerCase(i->Name) == "project") { hasProject = true; break; - } } + } // if no project command is found, add one - if(!hasProject) - { + if (!hasProject) { cmListFileFunction project; project.Name = "PROJECT"; cmListFileArgument prj("Project", cmListFileArgument::Unquoted, 0); project.Arguments.push_back(prj); - this->Functions.insert(this->Functions.begin(),project); - } + this->Functions.insert(this->Functions.begin(), project); } - if(parseError) - { + } + if (parseError) { return false; - } + } return true; } @@ -250,10 +217,10 @@ bool cmListFileParser::ParseFunction(const char* name, long line) // Command name has already been parsed. Read the left paren. cmListFileLexer_Token* token; - while((token = cmListFileLexer_Scan(this->Lexer)) && - token->type == cmListFileLexer_Token_Space) {} - if(!token) - { + while ((token = cmListFileLexer_Scan(this->Lexer)) && + token->type == cmListFileLexer_Token_Space) { + } + if (!token) { std::ostringstream error; /* clang-format off */ error << "Error in cmake code at\n" << this->FileName << ":" @@ -262,89 +229,69 @@ bool cmListFileParser::ParseFunction(const char* name, long line) /* clang-format on */ cmSystemTools::Error(error.str().c_str()); return false; - } - if(token->type != cmListFileLexer_Token_ParenLeft) - { + } + if (token->type != cmListFileLexer_Token_ParenLeft) { std::ostringstream error; - error << "Error in cmake code at\n" << this->FileName << ":" + error << "Error in cmake code at\n" + << this->FileName << ":" << cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n" << "Parse error. Expected \"(\", got " << cmListFileLexer_GetTypeAsString(this->Lexer, token->type) << " with text \"" << token->text << "\"."; cmSystemTools::Error(error.str().c_str()); return false; - } + } // Arguments. unsigned long lastLine; unsigned long parenDepth = 0; this->Separation = SeparationOkay; - while((lastLine = cmListFileLexer_GetCurrentLine(this->Lexer), - token = cmListFileLexer_Scan(this->Lexer))) - { - if(token->type == cmListFileLexer_Token_Space || - token->type == cmListFileLexer_Token_Newline) - { + while ((lastLine = cmListFileLexer_GetCurrentLine(this->Lexer), + token = cmListFileLexer_Scan(this->Lexer))) { + if (token->type == cmListFileLexer_Token_Space || + token->type == cmListFileLexer_Token_Newline) { this->Separation = SeparationOkay; continue; - } - if(token->type == cmListFileLexer_Token_ParenLeft) - { + } + if (token->type == cmListFileLexer_Token_ParenLeft) { parenDepth++; this->Separation = SeparationOkay; - if(!this->AddArgument(token, cmListFileArgument::Unquoted)) - { + if (!this->AddArgument(token, cmListFileArgument::Unquoted)) { return false; - } } - else if(token->type == cmListFileLexer_Token_ParenRight) - { - if (parenDepth == 0) - { + } else if (token->type == cmListFileLexer_Token_ParenRight) { + if (parenDepth == 0) { return true; - } + } parenDepth--; this->Separation = SeparationOkay; - if(!this->AddArgument(token, cmListFileArgument::Unquoted)) - { + if (!this->AddArgument(token, cmListFileArgument::Unquoted)) { return false; - } - this->Separation = SeparationWarning; } - else if(token->type == cmListFileLexer_Token_Identifier || - token->type == cmListFileLexer_Token_ArgumentUnquoted) - { - if(!this->AddArgument(token, cmListFileArgument::Unquoted)) - { - return false; - } this->Separation = SeparationWarning; - } - else if(token->type == cmListFileLexer_Token_ArgumentQuoted) - { - if(!this->AddArgument(token, cmListFileArgument::Quoted)) - { + } else if (token->type == cmListFileLexer_Token_Identifier || + token->type == cmListFileLexer_Token_ArgumentUnquoted) { + if (!this->AddArgument(token, cmListFileArgument::Unquoted)) { return false; - } + } this->Separation = SeparationWarning; + } else if (token->type == cmListFileLexer_Token_ArgumentQuoted) { + if (!this->AddArgument(token, cmListFileArgument::Quoted)) { + return false; } - else if(token->type == cmListFileLexer_Token_ArgumentBracket) - { - if(!this->AddArgument(token, cmListFileArgument::Bracket)) - { + this->Separation = SeparationWarning; + } else if (token->type == cmListFileLexer_Token_ArgumentBracket) { + if (!this->AddArgument(token, cmListFileArgument::Bracket)) { return false; - } - this->Separation = SeparationError; } - else if(token->type == cmListFileLexer_Token_CommentBracket) - { this->Separation = SeparationError; - } - else - { + } else if (token->type == cmListFileLexer_Token_CommentBracket) { + this->Separation = SeparationError; + } else { // Error. std::ostringstream error; - error << "Error in cmake code at\n" << this->FileName << ":" + error << "Error in cmake code at\n" + << this->FileName << ":" << cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n" << "Parse error. Function missing ending \")\". " << "Instead found " @@ -352,8 +299,8 @@ bool cmListFileParser::ParseFunction(const char* name, long line) << " with text \"" << token->text << "\"."; cmSystemTools::Error(error.str().c_str()); return false; - } } + } std::ostringstream error; error << "Error in cmake code at\n" @@ -370,10 +317,9 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token, { cmListFileArgument a(token->text, delim, token->line); this->Function.Arguments.push_back(a); - if(this->Separation == SeparationOkay) - { + if (this->Separation == SeparationOkay) { return true; - } + } bool isError = (this->Separation == SeparationError || delim == cmListFileArgument::Bracket); std::ostringstream m; @@ -383,90 +329,86 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token, << token->column << "\n" << "Argument not separated from preceding token by whitespace."; /* clang-format on */ - if(isError) - { + if (isError) { this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str()); return false; - } - else - { + } else { this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str()); return true; - } + } } -struct cmListFileBacktrace::Entry: public cmListFileContext +struct cmListFileBacktrace::Entry : public cmListFileContext { - Entry(cmListFileContext const& lfc, Entry* up): - cmListFileContext(lfc), Up(up), RefCount(0) - { - if (this->Up) - { + Entry(cmListFileContext const& lfc, Entry* up) + : cmListFileContext(lfc) + , Up(up) + , RefCount(0) + { + if (this->Up) { this->Up->Ref(); - } } + } ~Entry() - { - if (this->Up) - { + { + if (this->Up) { this->Up->Unref(); - } - } - void Ref() - { - ++this->RefCount; } + } + void Ref() { ++this->RefCount; } void Unref() - { - if (--this->RefCount == 0) - { + { + if (--this->RefCount == 0) { delete this; - } } + } Entry* Up; unsigned int RefCount; }; -cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot bottom, - Entry* up, - cmListFileContext const& lfc): - Bottom(bottom), Cur(new Entry(lfc, up)) +cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot bottom, Entry* up, + cmListFileContext const& lfc) + : Bottom(bottom) + , Cur(new Entry(lfc, up)) { assert(this->Bottom.IsValid()); this->Cur->Ref(); } -cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot bottom, Entry* cur): - Bottom(bottom), Cur(cur) +cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot bottom, Entry* cur) + : Bottom(bottom) + , Cur(cur) { - if (this->Cur) - { + if (this->Cur) { assert(this->Bottom.IsValid()); this->Cur->Ref(); - } + } } -cmListFileBacktrace::cmListFileBacktrace(): Bottom(), Cur(0) +cmListFileBacktrace::cmListFileBacktrace() + : Bottom() + , Cur(0) { } -cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot snapshot): - Bottom(snapshot.GetCallStackBottom()), Cur(0) +cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot snapshot) + : Bottom(snapshot.GetCallStackBottom()) + , Cur(0) { } -cmListFileBacktrace::cmListFileBacktrace(cmListFileBacktrace const& r): - Bottom(r.Bottom), Cur(r.Cur) +cmListFileBacktrace::cmListFileBacktrace(cmListFileBacktrace const& r) + : Bottom(r.Bottom) + , Cur(r.Cur) { - if (this->Cur) - { + if (this->Cur) { assert(this->Bottom.IsValid()); this->Cur->Ref(); - } + } } -cmListFileBacktrace& -cmListFileBacktrace::operator=(cmListFileBacktrace const& r) +cmListFileBacktrace& cmListFileBacktrace::operator=( + cmListFileBacktrace const& r) { cmListFileBacktrace tmp(r); std::swap(this->Cur, tmp.Cur); @@ -476,14 +418,12 @@ cmListFileBacktrace::operator=(cmListFileBacktrace const& r) cmListFileBacktrace::~cmListFileBacktrace() { - if (this->Cur) - { + if (this->Cur) { this->Cur->Unref(); - } + } } -cmListFileBacktrace -cmListFileBacktrace::Push(std::string const& file) const +cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const { // We are entering a file-level scope but have not yet reached // any specific line or command invocation within it. This context @@ -494,8 +434,8 @@ cmListFileBacktrace::Push(std::string const& file) const return cmListFileBacktrace(this->Bottom, this->Cur, lfc); } -cmListFileBacktrace -cmListFileBacktrace::Push(cmListFileContext const& lfc) const +cmListFileBacktrace cmListFileBacktrace::Push( + cmListFileContext const& lfc) const { return cmListFileBacktrace(this->Bottom, this->Cur, lfc); } @@ -508,83 +448,70 @@ cmListFileBacktrace cmListFileBacktrace::Pop() const cmListFileContext const& cmListFileBacktrace::Top() const { - if (this->Cur) - { + if (this->Cur) { return *this->Cur; - } - else - { + } else { static cmListFileContext const empty; return empty; - } + } } void cmListFileBacktrace::PrintTitle(std::ostream& out) const { - if (!this->Cur) - { + if (!this->Cur) { return; - } + } cmOutputConverter converter(this->Bottom); cmListFileContext lfc = *this->Cur; - if (!this->Bottom.GetState()->GetIsInTryCompile()) - { + if (!this->Bottom.GetState()->GetIsInTryCompile()) { lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); - } + } out << (lfc.Line ? " at " : " in ") << lfc; } void cmListFileBacktrace::PrintCallStack(std::ostream& out) const { - if (!this->Cur || !this->Cur->Up) - { + if (!this->Cur || !this->Cur->Up) { return; - } + } bool first = true; cmOutputConverter converter(this->Bottom); - for (Entry* i = this->Cur->Up; i; i = i->Up) - { - if (i->Name.empty()) - { + for (Entry* i = this->Cur->Up; i; i = i->Up) { + if (i->Name.empty()) { // Skip this whole-file scope. When we get here we already will // have printed a more-specific context within the file. continue; - } - if (first) - { + } + if (first) { first = false; out << "Call Stack (most recent call first):\n"; - } + } cmListFileContext lfc = *i; - if (!this->Bottom.GetState()->GetIsInTryCompile()) - { + if (!this->Bottom.GetState()->GetIsInTryCompile()) { lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); - } - out << " " << lfc << "\n"; } + out << " " << lfc << "\n"; + } } std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc) { os << lfc.FilePath; - if(lfc.Line) - { + if (lfc.Line) { os << ":" << lfc.Line; - if(!lfc.Name.empty()) - { + if (!lfc.Name.empty()) { os << " (" << lfc.Name << ")"; - } } + } return os; } bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs) { - if(lhs.Line != rhs.Line) - { + if (lhs.Line != rhs.Line) { return lhs.Line < rhs.Line; - } + } return lhs.FilePath < rhs.FilePath; } |