Files
clang-p2996/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
Adrian Prantl 0e4c482124 Pass ConstString by value (NFC)
My apologies for the large patch. With the exception of ConstString.h
itself it was entirely produced by sed.

ConstString has exactly one const char * data member, so passing a
ConstString by reference is not any more efficient than copying it by
value. In both cases a single pointer is passed. But passing it by
value makes it harder to accidentally return the address of a local
object.

(This fixes rdar://problem/48640859 for the Apple folks)

Differential Revision: https://reviews.llvm.org/D59030

llvm-svn: 355553
2019-03-06 21:22:25 +00:00

79 lines
2.6 KiB
C++

//===-- ClangPersistentVariables.cpp ----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "ClangPersistentVariables.h"
#include "lldb/Core/Value.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
#include "clang/AST/Decl.h"
#include "llvm/ADT/StringMap.h"
using namespace lldb;
using namespace lldb_private;
ClangPersistentVariables::ClangPersistentVariables()
: lldb_private::PersistentExpressionState(LLVMCastKind::eKindClang),
m_next_persistent_variable_id(0) {}
ExpressionVariableSP ClangPersistentVariables::CreatePersistentVariable(
const lldb::ValueObjectSP &valobj_sp) {
return AddNewlyConstructedVariable(new ClangExpressionVariable(valobj_sp));
}
ExpressionVariableSP ClangPersistentVariables::CreatePersistentVariable(
ExecutionContextScope *exe_scope, ConstString name,
const CompilerType &compiler_type, lldb::ByteOrder byte_order,
uint32_t addr_byte_size) {
return AddNewlyConstructedVariable(new ClangExpressionVariable(
exe_scope, name, compiler_type, byte_order, addr_byte_size));
}
void ClangPersistentVariables::RemovePersistentVariable(
lldb::ExpressionVariableSP variable) {
RemoveVariable(variable);
const char *name = variable->GetName().AsCString();
if (*name != '$')
return;
name++;
if (strtoul(name, NULL, 0) == m_next_persistent_variable_id - 1)
m_next_persistent_variable_id--;
}
void ClangPersistentVariables::RegisterPersistentDecl(ConstString name,
clang::NamedDecl *decl) {
m_persistent_decls.insert(
std::pair<const char *, clang::NamedDecl *>(name.GetCString(), decl));
if (clang::EnumDecl *enum_decl = llvm::dyn_cast<clang::EnumDecl>(decl)) {
for (clang::EnumConstantDecl *enumerator_decl : enum_decl->enumerators()) {
m_persistent_decls.insert(std::pair<const char *, clang::NamedDecl *>(
ConstString(enumerator_decl->getNameAsString()).GetCString(),
enumerator_decl));
}
}
}
clang::NamedDecl *
ClangPersistentVariables::GetPersistentDecl(ConstString name) {
PersistentDeclMap::const_iterator i =
m_persistent_decls.find(name.GetCString());
if (i == m_persistent_decls.end())
return NULL;
else
return i->second;
}