diff options
author | nyamatongwe <unknown> | 2013-02-21 13:52:35 +1100 |
---|---|---|
committer | nyamatongwe <unknown> | 2013-02-21 13:52:35 +1100 |
commit | e2fe6df591d73bcd545b79f248acb788a179a40c (patch) | |
tree | 306d2f915946f729a1701766aee4e6c65fc80204 /lexers/LexCPP.cxx | |
parent | 8f979246405a667b034b78f0bb33b4b861b3503e (diff) | |
download | scintilla-mirror-e2fe6df591d73bcd545b79f248acb788a179a40c.tar.gz |
Feature: [#978]. Update preprocessor defines upon encountering an #undef directive.
From Alpha.
Diffstat (limited to 'lexers/LexCPP.cxx')
-rw-r--r-- | lexers/LexCPP.cxx | 22 |
1 files changed, 19 insertions, 3 deletions
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<std::string, std::string> preprocessorDefinitions = preprocessorDefinitionsStart; for (std::vector<PPDefinition>::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<std::string> 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; + } + } } } } |