Commit d7783206 authored by David Nolden's avatar David Nolden

- Speedup CppPreprocessEnvironment::merge

- Add a switch to enable the more detailed environment string-management. This makes cppcodecompletiontest succeed again.
parent cf5704ea
......@@ -16,8 +16,11 @@
#include <language/interfaces/iproblem.h>
#include <parser/rpp/macrorepository.h>
///@todo Make this configurable
const bool onlyRecordImportantMacroUses = true;
bool onlyRecordImportantMacroUses = true;
void CppPreprocessEnvironment::setRecordOnlyImportantString(bool onlyImportant) {
onlyRecordImportantMacroUses = onlyImportant;
}
CppPreprocessEnvironment::CppPreprocessEnvironment( rpp::pp* preprocessor, KSharedPtr<Cpp::EnvironmentFile> environmentFile ) : Environment(preprocessor), m_identityOffsetRestriction(0), m_finished(false), m_identityOffsetRestrictionEnabled(false), m_environmentFile(environmentFile) {
//If this is included from another preprocessed file, take the current macro-set from there.
......@@ -91,18 +94,17 @@ void CppPreprocessEnvironment::merge( const Cpp::ReferenceCountedMacroSet& macro
}
void CppPreprocessEnvironment::merge( const Cpp::EnvironmentFile* file ) {
for( Cpp::ReferenceCountedMacroSet::Iterator it(file->definedMacros().iterator()); it; ++it ) {
for( Cpp::ReferenceCountedMacroSet::Iterator it(file->definedMacros().iterator()); it; ++it )
rpp::Environment::setMacro(copyConstantMacro(&it.ref())); //Do not use our overridden setMacro(..), because addDefinedMacro(..) is not needed(macro-sets should be merged separately)
m_macroNameSet.insert(it.ref().name);
}
for( Cpp::ReferenceCountedStringSet::Iterator it = file->unDefinedMacroNames().iterator(); it; ++it ) {
rpp::pp_dynamic_macro m(*it);
m.defined = false;
rpp::Environment::setMacro(makeConstant(&m)); //Do not use our overridden setMacro(..), because addDefinedMacro(..) is not needed(macro-sets should be merged separately)
m_macroNameSet.remove(*it);
}
m_macroNameSet += file->definedMacroNames();
m_macroNameSet -= file->unDefinedMacroNames();
}
void CppPreprocessEnvironment::setMacro(rpp::pp_macro* macro) {
......
......@@ -72,6 +72,8 @@ public:
///Only use it if identityOffsetRestrictionEnabled() returns true
uint identityOffsetRestriction() const;
static void setRecordOnlyImportantString(bool);
private:
uint m_identityOffsetRestriction;
bool m_identityOffsetRestrictionEnabled;
......
......@@ -865,6 +865,8 @@ void TestCppCodeCompletion::testMacroExpansionRanges() {
void TestCppCodeCompletion::testEnvironmentMatching() {
{
CppPreprocessEnvironment::setRecordOnlyImportantString(false);
addInclude("deep2.h", "#ifdef WANT_DEEP\nint x;\n#undef WANT_DEEP\n#endif\n");
addInclude("deep1.h", "#define WANT_DEEP\n#include \"deep2.h\"\n");
TopDUContext* test1 = parse(QByteArray("#include \"deep1.h\""), DumpNone);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment