From e2fe6df591d73bcd545b79f248acb788a179a40c Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Thu, 21 Feb 2013 13:52:35 +1100 Subject: Feature: [#978]. Update preprocessor defines upon encountering an #undef directive. From Alpha. --- lexers/LexCPP.cxx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lexers/LexCPP.cxx') diff --git a/lexers/LexCPP.cxx b/lexers/LexCPP.cxx index f30cdfbdd..a064328c8 100644 --- a/lexers/LexCPP.cxx +++ b/lexers/LexCPP.cxx @@ -132,8 +132,9 @@ struct PPDefinition { int line; std::string key; std::string value; - PPDefinition(int line_, const std::string &key_, const std::string &value_) : - line(line_), key(key_), value(value_) { + bool isUndef; + PPDefinition(int line_, const std::string &key_, const std::string &value_, bool isUndef_ = false) : + line(line_), key(key_), value(value_), isUndef(isUndef_) { } }; @@ -547,7 +548,10 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle, std::map preprocessorDefinitions = preprocessorDefinitionsStart; for (std::vector::iterator itDef = ppDefineHistory.begin(); itDef != ppDefineHistory.end(); ++itDef) { - preprocessorDefinitions[itDef->key] = itDef->value; + if (itDef->isUndef) + preprocessorDefinitions.erase(itDef->key); + else + preprocessorDefinitions[itDef->key] = itDef->value; } std::string rawStringTerminator = rawStringTerminators.ValueAt(lineCurrent-1); @@ -991,6 +995,18 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle, } } } + } else if (sc.Match("undef")) { + if (options.updatePreprocessor && !preproc.IsInactive()) { + std::string restOfLine = GetRestOfLine(styler, sc.currentPos + 5, true); + std::vector tokens = Tokenize(restOfLine); + std::string key; + if (tokens.size() >= 1) { + key = tokens[0]; + preprocessorDefinitions.erase(key); + ppDefineHistory.push_back(PPDefinition(lineCurrent, key, "", true)); + definitionsChanged = true; + } + } } } } -- cgit v1.2.3