build: bug fixes for release version

* fixed search activating 2 nodes, because of NodeType in query
* fixed search results didn't contain results with same name
* added protected contents to sample and tictactoe code
* fixed CxxParserTests not logging errors, disabled logging for tests with errors
* fixed CxxParserTests not finding system headers, added TestSettings.xml and pass headers to Parser::parseFile()
This commit is contained in:
Eberhard Graether
2015-03-11 13:14:22 +01:00
parent 5a259ed7c7
commit ca85d5a5d3
14 changed files with 121 additions and 67 deletions
+1 -1
View File
@@ -738,7 +738,7 @@ std::vector<SearchMatch> Storage::getAutocompletionMatches(const std::string& qu
}
Token* token = m_graph.getTokenById(*match.tokenIds.cbegin());
if(!token->isEdge())
if (token->isNode())
{
match.nodeType = dynamic_cast<Node*>(token)->getType();
}
+4 -1
View File
@@ -20,7 +20,10 @@ public:
const std::vector<FilePath>& filePaths,
const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths) = 0;
virtual void parseFile(std::shared_ptr<TextAccess> textAccess) = 0;
virtual void parseFile(
std::shared_ptr<TextAccess> textAccess,
const std::vector<std::string>& systemHeaderSearchPaths,
bool logErrors) = 0;
protected:
ParserClient* m_client;
+43 -35
View File
@@ -63,36 +63,9 @@ void CxxParser::parseFiles(
const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths
){
// Commandline flags passed to the programm. Everything after '--' will be interpreted by the ClangTool.
std::vector<std::string> args;
args.push_back("app");
args.push_back("--");
// verbose
// args.push_back("-v");
// The option -fno-delayed-template-parsing signals that templates that there should
// be AST elements for unused template functions as well.
args.push_back("-fno-delayed-template-parsing");
// The option -c signals that no executable is built.
args.push_back("-c");
// The option '-x c++' treats subsequent input files as C++.
args.push_back("-x");
args.push_back("c++");
args.push_back("-std=c++11");
for (const std::string& path : systemHeaderSearchPaths)
{
args.push_back("-isystem" + path);
}
for (const std::string& path : headerSearchPaths)
{
args.push_back("-I" + path);
}
std::vector<std::string> args = getArgs(systemHeaderSearchPaths, headerSearchPaths);
args.insert(args.begin(), "app");
args.insert(args.begin() + 1, "--");
int argc = args.size();
const char** argv = new const char*[argc];
@@ -129,16 +102,51 @@ void CxxParser::parseFiles(
tool.run(&actionFactory);
}
void CxxParser::parseFile(std::shared_ptr<TextAccess> textAccess)
{
std::vector<std::string> args;
args.push_back("-fno-delayed-template-parsing");
void CxxParser::parseFile(
std::shared_ptr<TextAccess> textAccess, const std::vector<std::string>& systemHeaderSearchPaths, bool logErrors
){
std::vector<std::string> args = getArgs(systemHeaderSearchPaths, std::vector<std::string>());
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client, false);
CxxDiagnosticConsumer reporter(llvm::errs(), &*options, m_client, logErrors);
FileRegister fileRegister(m_fileManager, std::vector<FilePath>());
ASTActionFactory actionFactory(m_client, &fileRegister);
runToolOnCodeWithArgs(&reporter, actionFactory.create(), textAccess->getText(), args);
}
std::vector<std::string> CxxParser::getArgs(
const std::vector<std::string>& systemHeaderSearchPaths, const std::vector<std::string>& headerSearchPaths
) const {
// Commandline flags passed to the programm. Everything after '--' will be interpreted by the ClangTool.
std::vector<std::string> args;
// verbose
// args.push_back("-v");
// The option -fno-delayed-template-parsing signals that templates that there should
// be AST elements for unused template functions as well.
args.push_back("-fno-delayed-template-parsing");
// The option -c signals that no executable is built.
args.push_back("-c");
// The option '-x c++' treats subsequent input files as C++.
args.push_back("-x");
args.push_back("c++");
args.push_back("-std=c++11");
for (const std::string& path : systemHeaderSearchPaths)
{
args.push_back("-isystem" + path);
}
for (const std::string& path : headerSearchPaths)
{
args.push_back("-I" + path);
}
return args;
}
+8 -1
View File
@@ -14,9 +14,16 @@ public:
const std::vector<FilePath>& filePaths,
const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths);
virtual void parseFile(std::shared_ptr<TextAccess> textAccess);
virtual void parseFile(
std::shared_ptr<TextAccess> textAccess,
const std::vector<std::string>& systemHeaderSearchPaths,
bool logErrors);
private:
std::vector<std::string> getArgs(
const std::vector<std::string>& systemHeaderSearchPaths,
const std::vector<std::string>& headerSearchPaths) const;
const FileManager* m_fileManager;
};
+2 -5
View File
@@ -61,7 +61,6 @@ std::string SearchMatch::encodeForQuery() const
{
std::stringstream ss;
ss << QueryToken::BOUNDARY << fullName;
ss << QueryToken::DELIMITER << nodeType;
for (Id tokenId : tokenIds)
{
ss << QueryToken::DELIMITER << tokenId;
@@ -103,17 +102,15 @@ void SearchMatch::decodeFromQuery(std::string query)
fullName = queryParts[0];
if(queryParts.size() > 1)
if (queryParts.size() > 1)
{
for(int i = 2; i < queryParts.size(); ++i)
for (size_t i = 2; i < queryParts.size(); ++i)
{
tokenIds.insert(std::strtoul(queryParts[i].c_str(),nullptr,0));
}
}
}
std::deque<SearchMatch> SearchMatch::stringDequeToSearchMatchDeque(const std::deque<std::string>& stringDeque)
{
std::deque<SearchMatch> matchDeque;
+8 -1
View File
@@ -23,5 +23,12 @@ bool SearchResult::operator()(const SearchResult& lhs, const SearchResult& rhs)
return lhs.weight > rhs.weight;
}
return utility::toLowerCase(lhs.node->getFullName()) < utility::toLowerCase(rhs.node->getFullName());
std::string lhsLow = utility::toLowerCase(lhs.node->getFullName());
std::string rhsLow = utility::toLowerCase(rhs.node->getFullName());
if (lhsLow != rhsLow)
{
return lhsLow < rhsLow;
}
return lhs.node->getFirstTokenId() < rhs.node->getFirstTokenId();
}
+16 -4
View File
@@ -1,5 +1,6 @@
#include "cxxtest/TestSuite.h"
#include "ApplicationSettings.h"
#include "data/parser/cxx/CxxParser.h"
#include "data/parser/ParseFunction.h"
#include "data/parser/ParseLocation.h"
@@ -669,7 +670,8 @@ public:
"};\n"
"class B : public A {\n"
" int foo();\n"
"};\n"
"};\n",
false
);
TS_ASSERT_EQUALS(client->overrides.size(), 1);
@@ -2017,7 +2019,8 @@ public:
void test_cxx_parser_catches_error()
{
std::shared_ptr<TestParserClient> client = parseCode(
"int a = b;\n"
"int a = b;\n",
false
);
TS_ASSERT_EQUALS(client->errors.size(), 1);
@@ -2316,12 +2319,21 @@ private:
}
};
std::shared_ptr<TestParserClient> parseCode(std::string code) const
std::shared_ptr<TestParserClient> parseCode(std::string code, bool logErrors = true)
{
if (!m_systemHeaderSearchPaths.size())
{
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
settings->load("data/TestSettings.xml");
m_systemHeaderSearchPaths = settings->getHeaderSearchPaths();
}
TestFileManager fm;
std::shared_ptr<TestParserClient> client = std::make_shared<TestParserClient>();
CxxParser parser(client.get(), &fm);
parser.parseFile(TextAccess::createFromString(code));
parser.parseFile(TextAccess::createFromString(code), m_systemHeaderSearchPaths, logErrors);
return client;
}
std::vector<std::string> m_systemHeaderSearchPaths;
};
+1 -1
View File
@@ -9,7 +9,7 @@ void TestStorage::parseCxxCode(std::string code)
clear();
TestFileManager fm;
CxxParser parser(this, &fm);
parser.parseFile(TextAccess::createFromString(code));
parser.parseFile(TextAccess::createFromString(code), std::vector<std::string>(), true);
}
const Graph& TestStorage::getGraph() const