summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
diff options
context:
space:
mode:
authorEwan Crawford <ewan@codeplay.com>2016-02-19 17:55:10 +0000
committerEwan Crawford <ewan@codeplay.com>2016-02-19 17:55:10 +0000
commit615a807ee835bc18478770161ab8409eea2fccdc (patch)
treea52768afc7828e7ec83166ef04ff4e4959005a21 /lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
parentf56aeef645a1fc798e677c0ff4fd2b349e068e9f (diff)
downloadbcm5719-llvm-615a807ee835bc18478770161ab8409eea2fccdc.tar.gz
bcm5719-llvm-615a807ee835bc18478770161ab8409eea2fccdc.zip
refactor/cleanup ClangExpressionParser::Parse
This patches does the following: + fix return type: ClangExpressionParser::Parse returns unsigned, but was actually returning a signed value, num_errors. + use helper clang::TextDiagnosticBuffer::getNumErrors() instead of counting the errors ourself. + limit scoping of block-level automatic variables as much as practical. + remove reused multipurpose TextDiagnosticBuffer::const_iterator in favour of loop-scoped err, warn, and note variables in the diagnostic printing code. + refactor diagnostic printing loops to use a proper loop invariant. Author: Luke Drummond <luke.drummond@codeplay.com> Differential Revision: http://reviews.llvm.org/D17273 llvm-svn: 261345
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp')
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp53
1 files changed, 20 insertions, 33 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index e6757a2ecd9..2fded88a0ea 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -435,37 +435,34 @@ ClangExpressionParser::~ClangExpressionParser()
}
unsigned
-ClangExpressionParser::Parse (Stream &stream)
+ClangExpressionParser::Parse(Stream &stream)
{
- TextDiagnosticBuffer *diag_buf = static_cast<TextDiagnosticBuffer*>(m_compiler->getDiagnostics().getClient());
-
- diag_buf->FlushDiagnostics (m_compiler->getDiagnostics());
+ TextDiagnosticBuffer *diag_buf = static_cast<TextDiagnosticBuffer *>(m_compiler->getDiagnostics().getClient());
+ diag_buf->FlushDiagnostics(m_compiler->getDiagnostics());
const char *expr_text = m_expr.Text();
- clang::SourceManager &SourceMgr = m_compiler->getSourceManager();
+ clang::SourceManager &source_mgr = m_compiler->getSourceManager();
bool created_main_file = false;
if (m_compiler->getCodeGenOpts().getDebugInfo() == codegenoptions::FullDebugInfo)
{
- std::string temp_source_path;
-
int temp_fd = -1;
llvm::SmallString<PATH_MAX> result_path;
FileSpec tmpdir_file_spec;
if (HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
{
tmpdir_file_spec.AppendPathComponent("lldb-%%%%%%.expr");
- temp_source_path = tmpdir_file_spec.GetPath();
+ std::string temp_source_path = tmpdir_file_spec.GetPath();
llvm::sys::fs::createUniqueFile(temp_source_path, temp_fd, result_path);
}
else
{
llvm::sys::fs::createTemporaryFile("lldb", "expr", temp_fd, result_path);
}
-
+
if (temp_fd != -1)
{
- lldb_private::File file (temp_fd, true);
+ lldb_private::File file(temp_fd, true);
const size_t expr_text_len = strlen(expr_text);
size_t bytes_written = expr_text_len;
if (file.Write(expr_text, bytes_written).Success())
@@ -473,9 +470,8 @@ ClangExpressionParser::Parse (Stream &stream)
if (bytes_written == expr_text_len)
{
file.Close();
- SourceMgr.setMainFileID(SourceMgr.createFileID(
- m_file_manager->getFile(result_path),
- SourceLocation(), SrcMgr::C_User));
+ source_mgr.setMainFileID(source_mgr.createFileID(m_file_manager->getFile(result_path),
+ SourceLocation(), SrcMgr::C_User));
created_main_file = true;
}
}
@@ -485,7 +481,7 @@ ClangExpressionParser::Parse (Stream &stream)
if (!created_main_file)
{
std::unique_ptr<MemoryBuffer> memory_buffer = MemoryBuffer::getMemBufferCopy(expr_text, __FUNCTION__);
- SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(memory_buffer)));
+ source_mgr.setMainFileID(source_mgr.createFileID(std::move(memory_buffer)));
}
diag_buf->BeginSourceFile(m_compiler->getLangOpts(), &m_compiler->getPreprocessor());
@@ -510,34 +506,25 @@ ClangExpressionParser::Parse (Stream &stream)
diag_buf->EndSourceFile();
- TextDiagnosticBuffer::const_iterator diag_iterator;
+ unsigned num_errors = diag_buf->getNumErrors();
- int num_errors = 0;
-
if (m_pp_callbacks && m_pp_callbacks->hasErrors())
{
num_errors++;
-
stream.PutCString(m_pp_callbacks->getErrorString().c_str());
}
- for (diag_iterator = diag_buf->warn_begin();
- diag_iterator != diag_buf->warn_end();
- ++diag_iterator)
- stream.Printf("warning: %s\n", (*diag_iterator).second.c_str());
+ for (TextDiagnosticBuffer::const_iterator warn = diag_buf->warn_begin(), warn_end = diag_buf->warn_end();
+ warn != warn_end; ++warn)
+ stream.Printf("warning: %s\n", warn->second.c_str());
- for (diag_iterator = diag_buf->err_begin();
- diag_iterator != diag_buf->err_end();
- ++diag_iterator)
- {
- num_errors++;
- stream.Printf("error: %s\n", (*diag_iterator).second.c_str());
- }
+ for (TextDiagnosticBuffer::const_iterator err = diag_buf->err_begin(), err_end = diag_buf->err_end();
+ err != err_end; ++err)
+ stream.Printf("error: %s\n", err->second.c_str());
- for (diag_iterator = diag_buf->note_begin();
- diag_iterator != diag_buf->note_end();
- ++diag_iterator)
- stream.Printf("note: %s\n", (*diag_iterator).second.c_str());
+ for (TextDiagnosticBuffer::const_iterator note = diag_buf->note_begin(), note_end = diag_buf->note_end();
+ note != note_end; ++note)
+ stream.Printf("note: %s\n", note->second.c_str());
if (!num_errors)
{
OpenPOWER on IntegriCloud