2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2002-01-21 23:30:43 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2002-01-21 23:30:43 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-08-29 02:28:31 +04:00
|
|
|
#include "cmListFileCache.h"
|
2003-12-08 21:36:59 +03:00
|
|
|
|
|
|
|
#include "cmListFileLexer.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmMakefile.h"
|
2015-10-05 21:57:47 +03:00
|
|
|
#include "cmOutputConverter.h"
|
2001-08-29 02:28:31 +04:00
|
|
|
#include "cmSystemTools.h"
|
2008-03-19 22:18:21 +03:00
|
|
|
#include "cmVersion.h"
|
2003-06-23 22:10:12 +04:00
|
|
|
|
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2001-08-29 02:28:31 +04:00
|
|
|
|
2013-02-17 05:14:23 +04:00
|
|
|
struct cmListFileParser
|
|
|
|
{
|
|
|
|
cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename);
|
|
|
|
~cmListFileParser();
|
2016-06-09 10:58:15 +03:00
|
|
|
void IssueFileOpenError(std::string const& text) const;
|
2013-02-17 05:14:23 +04:00
|
|
|
bool ParseFile();
|
|
|
|
bool ParseFunction(const char* name, long line);
|
2013-08-06 23:58:22 +04:00
|
|
|
bool AddArgument(cmListFileLexer_Token* token,
|
2013-02-17 05:14:23 +04:00
|
|
|
cmListFileArgument::Delimiter delim);
|
|
|
|
cmListFile* ListFile;
|
|
|
|
cmMakefile* Makefile;
|
|
|
|
const char* FileName;
|
|
|
|
cmListFileLexer* Lexer;
|
|
|
|
cmListFileFunction Function;
|
2016-05-16 17:34:04 +03:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SeparationOkay,
|
|
|
|
SeparationWarning,
|
|
|
|
SeparationError
|
|
|
|
} Separation;
|
2013-02-17 05:14:23 +04:00
|
|
|
};
|
2003-12-08 21:36:59 +03:00
|
|
|
|
2013-02-17 05:14:23 +04:00
|
|
|
cmListFileParser::cmListFileParser(cmListFile* lf, cmMakefile* mf,
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* filename)
|
|
|
|
: ListFile(lf)
|
|
|
|
, Makefile(mf)
|
|
|
|
, FileName(filename)
|
|
|
|
, Lexer(cmListFileLexer_New())
|
2001-08-29 02:28:31 +04:00
|
|
|
{
|
2013-02-17 05:14:23 +04:00
|
|
|
}
|
2004-08-04 18:45:11 +04:00
|
|
|
|
2013-02-17 05:14:23 +04:00
|
|
|
cmListFileParser::~cmListFileParser()
|
|
|
|
{
|
|
|
|
cmListFileLexer_Delete(this->Lexer);
|
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
|
2016-06-09 10:58:15 +03:00
|
|
|
void cmListFileParser::IssueFileOpenError(const std::string& text) const
|
|
|
|
{
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, text);
|
|
|
|
}
|
|
|
|
|
2013-02-17 05:14:23 +04:00
|
|
|
bool cmListFileParser::ParseFile()
|
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
// Open the file.
|
2013-10-14 23:13:11 +04:00
|
|
|
cmListFileLexer_BOM bom;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom)) {
|
2016-06-09 10:58:15 +03:00
|
|
|
this->IssueFileOpenError("cmListFileCache: error can not open file.");
|
2001-08-29 02:28:31 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
|
2013-10-14 23:13:11 +04:00
|
|
|
// Verify the Byte-Order-Mark, if any.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (bom != cmListFileLexer_BOM_None && bom != cmListFileLexer_BOM_UTF8) {
|
2016-06-27 23:44:16 +03:00
|
|
|
cmListFileLexer_SetFileName(this->Lexer, CM_NULLPTR, CM_NULLPTR);
|
2016-06-09 10:58:15 +03:00
|
|
|
this->IssueFileOpenError(
|
|
|
|
"File starts with a Byte-Order-Mark that is not UTF-8.");
|
2013-10-14 23:13:11 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-14 23:13:11 +04:00
|
|
|
|
2003-12-08 21:36:59 +03:00
|
|
|
// Use a simple recursive-descent parser to process the token
|
|
|
|
// stream.
|
|
|
|
bool haveNewline = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmListFileLexer_Token* token = cmListFileLexer_Scan(this->Lexer)) {
|
|
|
|
if (token->type == cmListFileLexer_Token_Space) {
|
|
|
|
} else if (token->type == cmListFileLexer_Token_Newline) {
|
2003-12-08 21:36:59 +03:00
|
|
|
haveNewline = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (token->type == cmListFileLexer_Token_CommentBracket) {
|
2013-08-06 23:58:22 +04:00
|
|
|
haveNewline = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (token->type == cmListFileLexer_Token_Identifier) {
|
|
|
|
if (haveNewline) {
|
2003-12-08 21:36:59 +03:00
|
|
|
haveNewline = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ParseFunction(token->text, token->line)) {
|
2013-02-17 05:14:23 +04:00
|
|
|
this->ListFile->Functions.push_back(this->Function);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-02-17 05:14:23 +04:00
|
|
|
return false;
|
2003-12-08 21:36:59 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2003-12-08 21:36:59 +03:00
|
|
|
error << "Error in cmake code at\n"
|
2013-02-17 05:14:23 +04:00
|
|
|
<< this->FileName << ":" << token->line << ":\n"
|
2004-09-01 02:39:42 +04:00
|
|
|
<< "Parse error. Expected a newline, got "
|
2013-02-17 05:14:23 +04:00
|
|
|
<< cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
|
2004-09-01 02:39:42 +04:00
|
|
|
<< " with text \"" << token->text << "\".";
|
2003-12-08 21:36:59 +03:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2013-02-17 05:14:23 +04:00
|
|
|
return false;
|
2003-12-08 21:36:59 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2003-12-08 21:36:59 +03:00
|
|
|
error << "Error in cmake code at\n"
|
2013-02-17 05:14:23 +04:00
|
|
|
<< this->FileName << ":" << token->line << ":\n"
|
2004-09-01 02:39:42 +04:00
|
|
|
<< "Parse error. Expected a command name, got "
|
2013-02-17 05:14:23 +04:00
|
|
|
<< cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
|
2016-05-16 17:34:04 +03:00
|
|
|
<< " with text \"" << token->text << "\".";
|
2003-12-08 21:36:59 +03:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2013-02-17 05:14:23 +04:00
|
|
|
return false;
|
2001-08-29 02:28:31 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-02-17 05:14:23 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-29 00:10:26 +03:00
|
|
|
bool cmListFile::ParseFile(const char* filename, cmMakefile* mf)
|
2013-02-17 05:14:23 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(filename) ||
|
|
|
|
cmSystemTools::FileIsDirectory(filename)) {
|
2013-02-17 05:14:23 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
|
2013-02-17 05:14:23 +04:00
|
|
|
bool parseError = false;
|
|
|
|
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileParser parser(this, mf, filename);
|
|
|
|
parseError = !parser.ParseFile();
|
2013-02-17 05:14:23 +04:00
|
|
|
}
|
|
|
|
|
2016-06-02 00:29:53 +03:00
|
|
|
return !parseError;
|
2001-08-29 02:28:31 +04:00
|
|
|
}
|
2002-09-19 22:34:15 +04:00
|
|
|
|
2013-02-17 05:14:23 +04:00
|
|
|
bool cmListFileParser::ParseFunction(const char* name, long line)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2016-03-29 21:24:20 +03:00
|
|
|
// Ininitialize a new function call.
|
2013-02-17 05:14:23 +04:00
|
|
|
this->Function = cmListFileFunction();
|
|
|
|
this->Function.Name = name;
|
|
|
|
this->Function.Line = line;
|
|
|
|
|
2003-12-08 21:36:59 +03:00
|
|
|
// Command name has already been parsed. Read the left paren.
|
|
|
|
cmListFileLexer_Token* token;
|
2016-05-16 17:34:04 +03:00
|
|
|
while ((token = cmListFileLexer_Scan(this->Lexer)) &&
|
|
|
|
token->type == cmListFileLexer_Token_Space) {
|
|
|
|
}
|
|
|
|
if (!token) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2013-02-17 05:14:23 +04:00
|
|
|
error << "Error in cmake code at\n" << this->FileName << ":"
|
|
|
|
<< cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n"
|
2003-12-08 21:36:59 +03:00
|
|
|
<< "Parse error. Function missing opening \"(\".";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2003-12-08 21:36:59 +03:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (token->type != cmListFileLexer_Token_ParenLeft) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2016-05-16 17:34:04 +03:00
|
|
|
error << "Error in cmake code at\n"
|
|
|
|
<< this->FileName << ":"
|
2013-02-17 05:14:23 +04:00
|
|
|
<< cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n"
|
2004-09-01 02:39:42 +04:00
|
|
|
<< "Parse error. Expected \"(\", got "
|
2013-02-17 05:14:23 +04:00
|
|
|
<< cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
|
2004-09-01 02:39:42 +04:00
|
|
|
<< " with text \"" << token->text << "\".";
|
2003-12-08 21:36:59 +03:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2002-12-12 02:13:33 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
|
|
|
|
// Arguments.
|
2013-02-17 05:41:47 +04:00
|
|
|
unsigned long lastLine;
|
2008-06-26 21:01:35 +04:00
|
|
|
unsigned long parenDepth = 0;
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationOkay;
|
2016-05-16 17:34:04 +03:00
|
|
|
while ((lastLine = cmListFileLexer_GetCurrentLine(this->Lexer),
|
|
|
|
token = cmListFileLexer_Scan(this->Lexer))) {
|
|
|
|
if (token->type == cmListFileLexer_Token_Space ||
|
|
|
|
token->type == cmListFileLexer_Token_Newline) {
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationOkay;
|
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (token->type == cmListFileLexer_Token_ParenLeft) {
|
2008-06-26 21:01:35 +04:00
|
|
|
parenDepth++;
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationOkay;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->AddArgument(token, cmListFileArgument::Unquoted)) {
|
2013-08-06 23:58:22 +04:00
|
|
|
return false;
|
2008-06-26 21:01:35 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (token->type == cmListFileLexer_Token_ParenRight) {
|
|
|
|
if (parenDepth == 0) {
|
2008-06-26 21:01:35 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-26 21:01:35 +04:00
|
|
|
parenDepth--;
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationOkay;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->AddArgument(token, cmListFileArgument::Unquoted)) {
|
2013-08-06 23:58:22 +04:00
|
|
|
return false;
|
2003-07-10 01:17:34 +04:00
|
|
|
}
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationWarning;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (token->type == cmListFileLexer_Token_Identifier ||
|
|
|
|
token->type == cmListFileLexer_Token_ArgumentUnquoted) {
|
|
|
|
if (!this->AddArgument(token, cmListFileArgument::Unquoted)) {
|
2013-08-06 23:58:22 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationWarning;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (token->type == cmListFileLexer_Token_ArgumentQuoted) {
|
|
|
|
if (!this->AddArgument(token, cmListFileArgument::Quoted)) {
|
|
|
|
return false;
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Separation = SeparationWarning;
|
|
|
|
} else if (token->type == cmListFileLexer_Token_ArgumentBracket) {
|
|
|
|
if (!this->AddArgument(token, cmListFileArgument::Bracket)) {
|
2013-08-06 23:58:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this->Separation = SeparationError;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (token->type == cmListFileLexer_Token_CommentBracket) {
|
|
|
|
this->Separation = SeparationError;
|
|
|
|
} else {
|
2003-12-08 21:36:59 +03:00
|
|
|
// Error.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2016-05-16 17:34:04 +03:00
|
|
|
error << "Error in cmake code at\n"
|
|
|
|
<< this->FileName << ":"
|
2013-02-17 05:14:23 +04:00
|
|
|
<< cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n"
|
2003-12-08 21:36:59 +03:00
|
|
|
<< "Parse error. Function missing ending \")\". "
|
2004-09-01 02:39:42 +04:00
|
|
|
<< "Instead found "
|
2013-02-17 05:14:23 +04:00
|
|
|
<< cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
|
2004-09-01 02:39:42 +04:00
|
|
|
<< " with text \"" << token->text << "\".";
|
2002-12-12 19:36:28 +03:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2002-12-12 02:13:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2002-12-12 02:13:33 +03:00
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2003-12-08 21:36:59 +03:00
|
|
|
error << "Error in cmake code at\n"
|
2013-02-17 05:14:23 +04:00
|
|
|
<< this->FileName << ":" << lastLine << ":\n"
|
2003-12-08 21:36:59 +03:00
|
|
|
<< "Parse error. Function missing ending \")\". "
|
|
|
|
<< "End of file reached.";
|
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2002-12-12 02:13:33 +03:00
|
|
|
|
2003-12-08 21:36:59 +03:00
|
|
|
return false;
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
2008-03-13 20:48:57 +03:00
|
|
|
|
2013-08-06 23:58:22 +04:00
|
|
|
bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
|
2013-02-17 05:14:23 +04:00
|
|
|
cmListFileArgument::Delimiter delim)
|
|
|
|
{
|
2015-05-24 00:43:37 +03:00
|
|
|
cmListFileArgument a(token->text, delim, token->line);
|
2013-02-17 05:14:23 +04:00
|
|
|
this->Function.Arguments.push_back(a);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Separation == SeparationOkay) {
|
2013-08-06 23:58:22 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-06 23:58:22 +04:00
|
|
|
bool isError = (this->Separation == SeparationError ||
|
|
|
|
delim == cmListFileArgument::Bracket);
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream m;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2013-08-06 23:58:22 +04:00
|
|
|
m << "Syntax " << (isError? "Error":"Warning") << " in cmake code at\n"
|
2013-02-17 05:41:47 +04:00
|
|
|
<< " " << this->FileName << ":" << token->line << ":"
|
|
|
|
<< token->column << "\n"
|
|
|
|
<< "Argument not separated from preceding token by whitespace.";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
if (isError) {
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str());
|
2013-08-06 23:58:22 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str());
|
2013-08-06 23:58:22 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-02-17 05:14:23 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
struct cmListFileBacktrace::Entry : public cmListFileContext
|
2015-11-25 03:43:04 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
Entry(cmListFileContext const& lfc, Entry* up)
|
|
|
|
: cmListFileContext(lfc)
|
|
|
|
, Up(up)
|
|
|
|
, RefCount(0)
|
|
|
|
{
|
|
|
|
if (this->Up) {
|
2016-04-14 18:24:08 +03:00
|
|
|
this->Up->Ref();
|
2016-04-13 00:07:08 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
~Entry()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->Up) {
|
2016-04-14 18:24:08 +03:00
|
|
|
this->Up->Unref();
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
void Ref() { ++this->RefCount; }
|
2016-04-14 18:24:08 +03:00
|
|
|
void Unref()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (--this->RefCount == 0) {
|
2016-04-14 18:24:08 +03:00
|
|
|
delete this;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
Entry* Up;
|
|
|
|
unsigned int RefCount;
|
|
|
|
};
|
2016-04-13 00:07:08 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot bottom, Entry* up,
|
|
|
|
cmListFileContext const& lfc)
|
|
|
|
: Bottom(bottom)
|
|
|
|
, Cur(new Entry(lfc, up))
|
2016-04-14 18:24:08 +03:00
|
|
|
{
|
|
|
|
assert(this->Bottom.IsValid());
|
|
|
|
this->Cur->Ref();
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot bottom, Entry* cur)
|
|
|
|
: Bottom(bottom)
|
|
|
|
, Cur(cur)
|
2016-04-14 18:24:08 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Cur) {
|
2016-04-14 18:24:08 +03:00
|
|
|
assert(this->Bottom.IsValid());
|
|
|
|
this->Cur->Ref();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileBacktrace::cmListFileBacktrace()
|
|
|
|
: Bottom()
|
2016-06-27 23:44:16 +03:00
|
|
|
, Cur(CM_NULLPTR)
|
2016-04-14 18:24:08 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot snapshot)
|
|
|
|
: Bottom(snapshot.GetCallStackBottom())
|
2016-06-27 23:44:16 +03:00
|
|
|
, Cur(CM_NULLPTR)
|
2016-04-14 18:24:08 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileBacktrace::cmListFileBacktrace(cmListFileBacktrace const& r)
|
|
|
|
: Bottom(r.Bottom)
|
|
|
|
, Cur(r.Cur)
|
2016-04-14 18:24:08 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Cur) {
|
2016-04-14 18:24:08 +03:00
|
|
|
assert(this->Bottom.IsValid());
|
|
|
|
this->Cur->Ref();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
}
|
2016-04-13 00:07:08 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileBacktrace& cmListFileBacktrace::operator=(
|
|
|
|
cmListFileBacktrace const& r)
|
2016-04-14 18:24:08 +03:00
|
|
|
{
|
|
|
|
cmListFileBacktrace tmp(r);
|
|
|
|
std::swap(this->Cur, tmp.Cur);
|
|
|
|
std::swap(this->Bottom, tmp.Bottom);
|
|
|
|
return *this;
|
2015-11-25 03:43:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmListFileBacktrace::~cmListFileBacktrace()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Cur) {
|
2016-04-14 18:24:08 +03:00
|
|
|
this->Cur->Unref();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const
|
2016-04-14 18:24:08 +03:00
|
|
|
{
|
|
|
|
// We are entering a file-level scope but have not yet reached
|
|
|
|
// any specific line or command invocation within it. This context
|
|
|
|
// is useful to print when it is at the top but otherwise can be
|
|
|
|
// skipped during call stack printing.
|
|
|
|
cmListFileContext lfc;
|
|
|
|
lfc.FilePath = file;
|
|
|
|
return cmListFileBacktrace(this->Bottom, this->Cur, lfc);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileBacktrace cmListFileBacktrace::Push(
|
|
|
|
cmListFileContext const& lfc) const
|
2016-04-14 18:24:08 +03:00
|
|
|
{
|
|
|
|
return cmListFileBacktrace(this->Bottom, this->Cur, lfc);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmListFileBacktrace cmListFileBacktrace::Pop() const
|
|
|
|
{
|
|
|
|
assert(this->Cur);
|
|
|
|
return cmListFileBacktrace(this->Bottom, this->Cur->Up);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmListFileContext const& cmListFileBacktrace::Top() const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Cur) {
|
2016-04-14 18:24:08 +03:00
|
|
|
return *this->Cur;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2016-04-14 18:24:08 +03:00
|
|
|
static cmListFileContext const empty;
|
|
|
|
return empty;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-11-25 03:43:04 +03:00
|
|
|
}
|
|
|
|
|
2015-07-09 23:26:51 +03:00
|
|
|
void cmListFileBacktrace::PrintTitle(std::ostream& out) const
|
2015-05-18 22:33:38 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Cur) {
|
2015-05-18 22:33:38 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
cmOutputConverter converter(this->Bottom);
|
|
|
|
cmListFileContext lfc = *this->Cur;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Bottom.GetState()->GetIsInTryCompile()) {
|
2016-04-14 18:24:08 +03:00
|
|
|
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-23 14:50:12 +03:00
|
|
|
out << (lfc.Line ? " at " : " in ") << lfc;
|
2015-05-18 22:33:38 +03:00
|
|
|
}
|
|
|
|
|
2015-07-09 23:26:51 +03:00
|
|
|
void cmListFileBacktrace::PrintCallStack(std::ostream& out) const
|
2015-05-18 22:33:38 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Cur || !this->Cur->Up) {
|
2015-05-18 22:33:38 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-18 22:33:38 +03:00
|
|
|
|
2016-04-14 18:24:08 +03:00
|
|
|
bool first = true;
|
|
|
|
cmOutputConverter converter(this->Bottom);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (Entry* i = this->Cur->Up; i; i = i->Up) {
|
|
|
|
if (i->Name.empty()) {
|
2016-04-14 18:24:08 +03:00
|
|
|
// Skip this whole-file scope. When we get here we already will
|
|
|
|
// have printed a more-specific context within the file.
|
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (first) {
|
2016-04-14 18:24:08 +03:00
|
|
|
first = false;
|
|
|
|
out << "Call Stack (most recent call first):\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-13 00:07:08 +03:00
|
|
|
cmListFileContext lfc = *i;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Bottom.GetState()->GetIsInTryCompile()) {
|
2016-04-14 18:24:08 +03:00
|
|
|
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
|
2015-05-18 22:33:38 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
out << " " << lfc << "\n";
|
|
|
|
}
|
2015-05-18 22:33:38 +03:00
|
|
|
}
|
2014-03-13 01:59:42 +04:00
|
|
|
|
2008-03-13 20:48:57 +03:00
|
|
|
std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
|
|
|
|
{
|
|
|
|
os << lfc.FilePath;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lfc.Line) {
|
2008-03-13 20:48:57 +03:00
|
|
|
os << ":" << lfc.Line;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!lfc.Name.empty()) {
|
2008-03-13 20:48:57 +03:00
|
|
|
os << " (" << lfc.Name << ")";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-03-13 20:48:57 +03:00
|
|
|
return os;
|
|
|
|
}
|
2015-05-18 22:44:14 +03:00
|
|
|
|
|
|
|
bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lhs.Line != rhs.Line) {
|
2015-05-18 22:46:50 +03:00
|
|
|
return lhs.Line < rhs.Line;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-18 22:46:50 +03:00
|
|
|
return lhs.FilePath < rhs.FilePath;
|
2015-05-18 22:44:14 +03:00
|
|
|
}
|
2015-05-18 22:51:42 +03:00
|
|
|
|
|
|
|
bool operator==(const cmListFileContext& lhs, const cmListFileContext& rhs)
|
|
|
|
{
|
|
|
|
return lhs.Line == rhs.Line && lhs.FilePath == rhs.FilePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const cmListFileContext& lhs, const cmListFileContext& rhs)
|
|
|
|
{
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|