summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib/run_compile_commands.cxx
diff options
context:
space:
mode:
authorKitware Robot <kwrobot@kitware.com>2016-05-16 14:34:04 (GMT)
committerBrad King <brad.king@kitware.com>2016-05-16 20:05:19 (GMT)
commitd9fd2f5402eeaa345691313658e02b51038f570b (patch)
treedca71b9a7e267f4c6300da3eb770415381726785 /Tests/CMakeLib/run_compile_commands.cxx
parent82df6deaafb36cbbfd450202bb20b320f637751a (diff)
downloadCMake-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 'Tests/CMakeLib/run_compile_commands.cxx')
-rw-r--r--Tests/CMakeLib/run_compile_commands.cxx88
1 files changed, 45 insertions, 43 deletions
diff --git a/Tests/CMakeLib/run_compile_commands.cxx b/Tests/CMakeLib/run_compile_commands.cxx
index 26ab223..1cfd381 100644
--- a/Tests/CMakeLib/run_compile_commands.cxx
+++ b/Tests/CMakeLib/run_compile_commands.cxx
@@ -1,24 +1,24 @@
#include "cmSystemTools.h"
-class CompileCommandParser {
+class CompileCommandParser
+{
public:
- class CommandType: public std::map<std::string, std::string>
+ class CommandType : public std::map<std::string, std::string>
{
public:
std::string const& at(std::string const& k) const
- {
+ {
const_iterator i = this->find(k);
- if(i != this->end()) { return i->second; }
+ if (i != this->end()) {
+ return i->second;
+ }
static std::string emptyString;
return emptyString;
- }
+ }
};
typedef std::vector<CommandType> TranslationUnitsType;
- CompileCommandParser(std::ifstream *input)
- {
- this->Input = input;
- }
+ CompileCommandParser(std::ifstream* input) { this->Input = input; }
void Parse()
{
@@ -36,54 +36,53 @@ private:
{
this->TranslationUnits = TranslationUnitsType();
ExpectOrDie('[', "at start of compile command file\n");
- do
- {
+ do {
ParseTranslationUnit();
this->TranslationUnits.push_back(this->Command);
- } while(Expect(','));
+ } while (Expect(','));
ExpectOrDie(']', "at end of array");
}
void ParseTranslationUnit()
{
this->Command = CommandType();
- if(!Expect('{')) return;
- if(Expect('}')) return;
- do
- {
+ if (!Expect('{'))
+ return;
+ if (Expect('}'))
+ return;
+ do {
ParseString();
std::string name = this->String;
ExpectOrDie(':', "between name and value");
ParseString();
std::string value = this->String;
this->Command[name] = value;
- } while(Expect(','));
+ } while (Expect(','));
ExpectOrDie('}', "at end of object");
}
void ParseString()
{
this->String = "";
- if(!Expect('"')) return;
- while (!Expect('"'))
- {
+ if (!Expect('"'))
+ return;
+ while (!Expect('"')) {
Expect('\\');
- this->String.append(1,C);
+ this->String.append(1, C);
Next();
- }
+ }
}
bool Expect(char c)
{
- if(this->C == c)
- {
+ if (this->C == c) {
NextNonWhitespace();
return true;
- }
+ }
return false;
}
- void ExpectOrDie(char c, const std::string & message)
+ void ExpectOrDie(char c, const std::string& message)
{
if (!Expect(c))
ErrorExit(std::string("'") + c + "' expected " + message + ".");
@@ -91,51 +90,54 @@ private:
void NextNonWhitespace()
{
- do { Next(); } while (IsWhitespace());
+ do {
+ Next();
+ } while (IsWhitespace());
}
void Next()
{
this->C = char(Input->get());
- if (this->Input->bad()) ErrorExit("Unexpected end of file.");
+ if (this->Input->bad())
+ ErrorExit("Unexpected end of file.");
}
- void ErrorExit(const std::string &message) {
+ void ErrorExit(const std::string& message)
+ {
std::cout << "ERROR: " << message;
exit(1);
}
bool IsWhitespace()
{
- return (this->C == ' ' || this->C == '\t' ||
- this->C == '\n' || this->C == '\r');
+ return (this->C == ' ' || this->C == '\t' || this->C == '\n' ||
+ this->C == '\r');
}
char C;
TranslationUnitsType TranslationUnits;
CommandType Command;
std::string String;
- std::ifstream *Input;
+ std::ifstream* Input;
};
-int main ()
+int main()
{
std::ifstream file("compile_commands.json");
CompileCommandParser parser(&file);
parser.Parse();
- for(CompileCommandParser::TranslationUnitsType::const_iterator
- it = parser.GetTranslationUnits().begin(),
- end = parser.GetTranslationUnits().end(); it != end; ++it)
- {
+ for (CompileCommandParser::TranslationUnitsType::const_iterator
+ it = parser.GetTranslationUnits().begin(),
+ end = parser.GetTranslationUnits().end();
+ it != end; ++it) {
std::vector<std::string> command;
cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), command);
- if (!cmSystemTools::RunSingleCommand(
- command, 0, 0, 0, it->at("directory").c_str()))
- {
- std::cout << "ERROR: Failed to run command \""
- << command[0] << "\"" << std::endl;
+ if (!cmSystemTools::RunSingleCommand(command, 0, 0, 0,
+ it->at("directory").c_str())) {
+ std::cout << "ERROR: Failed to run command \"" << command[0] << "\""
+ << std::endl;
exit(1);
- }
}
+ }
return 0;
}