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"
|
2015-10-05 21:57:47 +03:00
|
|
|
#include "cmOutputConverter.h"
|
2001-08-29 02:28:31 +04:00
|
|
|
#include "cmSystemTools.h"
|
2008-03-06 18:57:59 +03:00
|
|
|
#include "cmMakefile.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
|
|
|
|
2006-08-01 19:38:42 +04:00
|
|
|
|
2013-02-17 05:14:23 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
struct cmListFileParser
|
|
|
|
{
|
|
|
|
cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename);
|
|
|
|
~cmListFileParser();
|
|
|
|
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;
|
2013-08-06 23:58:22 +04: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,
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
if(!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom))
|
2003-12-08 21:36:59 +03:00
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
cmSystemTools::Error("cmListFileCache: error can not open file ",
|
2013-02-17 05:14:23 +04:00
|
|
|
this->FileName);
|
2001-08-29 02:28:31 +04:00
|
|
|
return false;
|
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
|
2013-10-14 23:13:11 +04:00
|
|
|
// Verify the Byte-Order-Mark, if any.
|
|
|
|
if(bom != cmListFileLexer_BOM_None &&
|
|
|
|
bom != cmListFileLexer_BOM_UTF8)
|
|
|
|
{
|
|
|
|
cmListFileLexer_SetFileName(this->Lexer, 0, 0);
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream m;
|
2013-10-14 23:13:11 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-12-08 21:36:59 +03:00
|
|
|
// Use a simple recursive-descent parser to process the token
|
|
|
|
// stream.
|
|
|
|
bool haveNewline = true;
|
2013-02-17 05:14:23 +04:00
|
|
|
while(cmListFileLexer_Token* token =
|
|
|
|
cmListFileLexer_Scan(this->Lexer))
|
2001-08-29 02:28:31 +04:00
|
|
|
{
|
2013-02-17 05:41:47 +04:00
|
|
|
if(token->type == cmListFileLexer_Token_Space)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if(token->type == cmListFileLexer_Token_Newline)
|
2001-08-29 02:28:31 +04:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
haveNewline = true;
|
2001-08-29 02:28:31 +04:00
|
|
|
}
|
2013-08-06 23:58:22 +04:00
|
|
|
else if(token->type == cmListFileLexer_Token_CommentBracket)
|
|
|
|
{
|
|
|
|
haveNewline = false;
|
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
else if(token->type == cmListFileLexer_Token_Identifier)
|
2001-11-30 00:44:22 +03:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
if(haveNewline)
|
|
|
|
{
|
|
|
|
haveNewline = false;
|
2013-02-17 05:14:23 +04:00
|
|
|
if(this->ParseFunction(token->text, token->line))
|
2003-12-08 21:36:59 +03:00
|
|
|
{
|
2013-02-17 05:14:23 +04:00
|
|
|
this->ListFile->Functions.push_back(this->Function);
|
2003-12-08 21:36:59 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-17 05:14:23 +04:00
|
|
|
return false;
|
2003-12-08 21:36:59 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
2004-09-01 02:39:42 +04:00
|
|
|
<< " with text \""
|
2003-12-08 21:36:59 +03:00
|
|
|
<< token->text << "\".";
|
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2013-02-17 05:14:23 +04:00
|
|
|
return false;
|
2001-11-30 00:44:22 +03:00
|
|
|
}
|
2001-08-29 02:28:31 +04:00
|
|
|
}
|
2013-02-17 05:14:23 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmListFile::ParseFile(const char* filename,
|
|
|
|
bool topLevel,
|
|
|
|
cmMakefile *mf)
|
|
|
|
{
|
2014-06-10 00:19:07 +04:00
|
|
|
if(!cmSystemTools::FileExists(filename) ||
|
|
|
|
cmSystemTools::FileIsDirectory(filename))
|
2003-12-08 21:36:59 +03:00
|
|
|
{
|
2013-02-17 05:14:23 +04:00
|
|
|
return false;
|
2003-12-08 21:36:59 +03:00
|
|
|
}
|
|
|
|
|
2013-02-17 05:14:23 +04:00
|
|
|
bool parseError = false;
|
|
|
|
|
|
|
|
{
|
|
|
|
cmListFileParser parser(this, mf, filename);
|
|
|
|
parseError = !parser.ParseFile();
|
|
|
|
}
|
|
|
|
|
2008-03-06 18:57:59 +03:00
|
|
|
// do we need a cmake_policy(VERSION call?
|
|
|
|
if(topLevel)
|
|
|
|
{
|
2008-03-19 22:18:21 +03:00
|
|
|
bool hasVersion = false;
|
2008-03-06 18:57:59 +03:00
|
|
|
// search for the right policy command
|
2012-08-13 21:42:58 +04:00
|
|
|
for(std::vector<cmListFileFunction>::iterator i
|
2008-03-06 18:57:59 +03:00
|
|
|
= this->Functions.begin();
|
|
|
|
i != this->Functions.end(); ++i)
|
|
|
|
{
|
2008-03-07 19:43:47 +03:00
|
|
|
if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required")
|
|
|
|
{
|
2008-03-19 22:18:21 +03:00
|
|
|
hasVersion = true;
|
2008-03-07 19:43:47 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-03-06 18:57:59 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
// if no policy command is found this is an error if they use any
|
2008-04-27 15:01:05 +04:00
|
|
|
// non advanced functions or a lot of functions
|
2008-03-19 22:18:21 +03:00
|
|
|
if(!hasVersion)
|
2008-03-20 17:40:24 +03:00
|
|
|
{
|
|
|
|
bool isProblem = true;
|
|
|
|
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
|
|
|
|
std::set<std::string> allowedCommands;
|
|
|
|
allowedCommands.insert("project");
|
|
|
|
allowedCommands.insert("set");
|
|
|
|
allowedCommands.insert("if");
|
|
|
|
allowedCommands.insert("endif");
|
|
|
|
allowedCommands.insert("else");
|
|
|
|
allowedCommands.insert("elseif");
|
|
|
|
allowedCommands.insert("add_executable");
|
|
|
|
allowedCommands.insert("add_library");
|
|
|
|
allowedCommands.insert("target_link_libraries");
|
|
|
|
allowedCommands.insert("option");
|
|
|
|
allowedCommands.insert("message");
|
|
|
|
isProblem = false;
|
2012-08-13 21:42:58 +04:00
|
|
|
for(std::vector<cmListFileFunction>::iterator i
|
2008-03-20 17:40:24 +03:00
|
|
|
= this->Functions.begin();
|
|
|
|
i != this->Functions.end(); ++i)
|
|
|
|
{
|
|
|
|
std::string name = cmSystemTools::LowerCase(i->Name);
|
|
|
|
if (allowedCommands.find(name) == allowedCommands.end())
|
|
|
|
{
|
2008-03-20 17:46:24 +03:00
|
|
|
isProblem = true;
|
|
|
|
break;
|
2012-08-13 21:42:58 +04:00
|
|
|
}
|
2008-03-20 17:40:24 +03:00
|
|
|
}
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-03-20 17:40:24 +03:00
|
|
|
if (isProblem)
|
2008-03-06 18:57:59 +03:00
|
|
|
{
|
2008-03-31 21:33:09 +04:00
|
|
|
// 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");
|
2008-03-06 18:57:59 +03:00
|
|
|
}
|
2008-03-20 17:40:24 +03:00
|
|
|
}
|
2008-03-06 18:57:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(topLevel)
|
2002-12-02 23:30:59 +03:00
|
|
|
{
|
|
|
|
bool hasProject = false;
|
|
|
|
// search for a project command
|
2012-08-13 21:42:58 +04:00
|
|
|
for(std::vector<cmListFileFunction>::iterator i
|
2006-03-15 19:02:08 +03:00
|
|
|
= this->Functions.begin();
|
|
|
|
i != this->Functions.end(); ++i)
|
2002-12-02 23:30:59 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
if(cmSystemTools::LowerCase(i->Name) == "project")
|
2002-12-02 23:30:59 +03:00
|
|
|
{
|
|
|
|
hasProject = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if no project command is found, add one
|
|
|
|
if(!hasProject)
|
|
|
|
{
|
|
|
|
cmListFileFunction project;
|
2006-03-15 19:02:08 +03:00
|
|
|
project.Name = "PROJECT";
|
2015-05-24 00:43:37 +03:00
|
|
|
cmListFileArgument prj("Project", cmListFileArgument::Unquoted, 0);
|
2006-03-15 19:02:08 +03:00
|
|
|
project.Arguments.push_back(prj);
|
|
|
|
this->Functions.insert(this->Functions.begin(),project);
|
2002-12-02 23:30:59 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-19 21:42:05 +03:00
|
|
|
if(parseError)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2001-08-29 02:28:31 +04:00
|
|
|
return true;
|
|
|
|
}
|
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;
|
2013-02-17 05:41:47 +04:00
|
|
|
while((token = cmListFileLexer_Scan(this->Lexer)) &&
|
|
|
|
token->type == cmListFileLexer_Token_Space) {}
|
|
|
|
if(!token)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
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 \"(\".";
|
|
|
|
cmSystemTools::Error(error.str().c_str());
|
|
|
|
return false;
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
if(token->type != cmListFileLexer_Token_ParenLeft)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2013-02-17 05:14:23 +04:00
|
|
|
error << "Error in cmake code at\n" << this->FileName << ":"
|
|
|
|
<< 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;
|
|
|
|
}
|
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;
|
|
|
|
while((lastLine = cmListFileLexer_GetCurrentLine(this->Lexer),
|
|
|
|
token = cmListFileLexer_Scan(this->Lexer)))
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2013-02-17 05:41:47 +04:00
|
|
|
if(token->type == cmListFileLexer_Token_Space ||
|
|
|
|
token->type == cmListFileLexer_Token_Newline)
|
|
|
|
{
|
|
|
|
this->Separation = SeparationOkay;
|
|
|
|
continue;
|
|
|
|
}
|
2008-06-26 21:01:35 +04:00
|
|
|
if(token->type == cmListFileLexer_Token_ParenLeft)
|
2003-07-10 01:17:34 +04:00
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
parenDepth++;
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationOkay;
|
2013-08-06 23:58:22 +04:00
|
|
|
if(!this->AddArgument(token, cmListFileArgument::Unquoted))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-26 21:01:35 +04:00
|
|
|
}
|
|
|
|
else if(token->type == cmListFileLexer_Token_ParenRight)
|
|
|
|
{
|
|
|
|
if (parenDepth == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
parenDepth--;
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationOkay;
|
2013-08-06 23:58:22 +04:00
|
|
|
if(!this->AddArgument(token, cmListFileArgument::Unquoted))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationWarning;
|
2003-07-10 01:17:34 +04:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
else if(token->type == cmListFileLexer_Token_Identifier ||
|
|
|
|
token->type == cmListFileLexer_Token_ArgumentUnquoted)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2013-08-06 23:58:22 +04:00
|
|
|
if(!this->AddArgument(token, cmListFileArgument::Unquoted))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationWarning;
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
else if(token->type == cmListFileLexer_Token_ArgumentQuoted)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2013-08-06 23:58:22 +04:00
|
|
|
if(!this->AddArgument(token, cmListFileArgument::Quoted))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-17 05:41:47 +04:00
|
|
|
this->Separation = SeparationWarning;
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
2013-08-06 23:58:22 +04:00
|
|
|
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;
|
|
|
|
}
|
2013-02-17 05:41:47 +04:00
|
|
|
else
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
// Error.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
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 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-02-17 05:14:23 +04: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);
|
2013-02-17 05:41:47 +04:00
|
|
|
if(this->Separation == SeparationOkay)
|
|
|
|
{
|
2013-08-06 23:58:22 +04:00
|
|
|
return true;
|
2013-02-17 05:41:47 +04: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;
|
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.";
|
2013-08-06 23:58:22 +04: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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2013-02-17 05:14:23 +04:00
|
|
|
}
|
|
|
|
|
2016-04-14 18:24:08 +03:00
|
|
|
struct cmListFileBacktrace::Entry: public cmListFileContext
|
2015-11-25 03:43:04 +03:00
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
Entry(cmListFileContext const& lfc, Entry* up):
|
|
|
|
cmListFileContext(lfc), Up(up), RefCount(0)
|
2016-04-13 00:07:08 +03:00
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
if (this->Up)
|
|
|
|
{
|
|
|
|
this->Up->Ref();
|
|
|
|
}
|
2016-04-13 00:07:08 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
~Entry()
|
|
|
|
{
|
|
|
|
if (this->Up)
|
|
|
|
{
|
|
|
|
this->Up->Unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Ref()
|
|
|
|
{
|
|
|
|
++this->RefCount;
|
|
|
|
}
|
|
|
|
void Unref()
|
2015-11-24 23:00:47 +03:00
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
if (--this->RefCount == 0)
|
2016-04-13 00:07:08 +03:00
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
delete this;
|
2016-04-13 00:07:08 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
}
|
|
|
|
Entry* Up;
|
|
|
|
unsigned int RefCount;
|
|
|
|
};
|
2016-04-13 00:07:08 +03:00
|
|
|
|
2016-04-14 18:24:08 +03:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (this->Cur)
|
|
|
|
{
|
|
|
|
assert(this->Bottom.IsValid());
|
|
|
|
this->Cur->Ref();
|
2015-11-24 23:00:47 +03:00
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmListFileBacktrace::cmListFileBacktrace(): Bottom(), Cur(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot snapshot):
|
|
|
|
Bottom(snapshot.GetCallStackBottom()), Cur(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmListFileBacktrace::cmListFileBacktrace(cmListFileBacktrace const& r):
|
|
|
|
Bottom(r.Bottom), Cur(r.Cur)
|
|
|
|
{
|
|
|
|
if (this->Cur)
|
|
|
|
{
|
|
|
|
assert(this->Bottom.IsValid());
|
|
|
|
this->Cur->Ref();
|
|
|
|
}
|
|
|
|
}
|
2016-04-13 00:07:08 +03:00
|
|
|
|
2016-04-14 18:24:08 +03:00
|
|
|
cmListFileBacktrace&
|
|
|
|
cmListFileBacktrace::operator=(cmListFileBacktrace const& r)
|
|
|
|
{
|
|
|
|
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-04-14 18:24:08 +03:00
|
|
|
if (this->Cur)
|
|
|
|
{
|
|
|
|
this->Cur->Unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmListFileBacktrace
|
|
|
|
cmListFileBacktrace::Push(cmListFileContext const& lfc) const
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
if (this->Cur)
|
|
|
|
{
|
|
|
|
return *this->Cur;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static cmListFileContext const empty;
|
|
|
|
return empty;
|
|
|
|
}
|
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-04-14 18:24:08 +03:00
|
|
|
if (!this->Cur)
|
2015-05-18 22:33:38 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-04-14 18:24:08 +03:00
|
|
|
cmOutputConverter converter(this->Bottom);
|
|
|
|
cmListFileContext lfc = *this->Cur;
|
|
|
|
if (!this->Bottom.GetState()->GetIsInTryCompile())
|
|
|
|
{
|
|
|
|
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
|
|
|
|
}
|
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-04-14 18:24:08 +03:00
|
|
|
if (!this->Cur || !this->Cur->Up)
|
2015-05-18 22:33:38 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-14 18:24:08 +03:00
|
|
|
bool first = true;
|
|
|
|
cmOutputConverter converter(this->Bottom);
|
|
|
|
for (Entry* i = this->Cur->Up; i; i = i->Up)
|
2015-05-18 22:33:38 +03:00
|
|
|
{
|
2016-04-14 18:24:08 +03:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
first = false;
|
|
|
|
out << "Call Stack (most recent call first):\n";
|
|
|
|
}
|
2016-04-13 00:07:08 +03:00
|
|
|
cmListFileContext lfc = *i;
|
2016-04-14 18:24:08 +03:00
|
|
|
if (!this->Bottom.GetState()->GetIsInTryCompile())
|
|
|
|
{
|
|
|
|
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
|
|
|
|
}
|
2015-05-18 22:33:38 +03:00
|
|
|
out << " " << lfc << "\n";
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
if(lfc.Line)
|
|
|
|
{
|
|
|
|
os << ":" << lfc.Line;
|
|
|
|
if(!lfc.Name.empty())
|
|
|
|
{
|
|
|
|
os << " (" << lfc.Name << ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
2015-05-18 22:44:14 +03:00
|
|
|
|
|
|
|
bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs)
|
|
|
|
{
|
2015-05-18 22:46:50 +03:00
|
|
|
if(lhs.Line != rhs.Line)
|
|
|
|
{
|
|
|
|
return lhs.Line < rhs.Line;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|