Menu

#1051 C++ lexer: handle "#if defined __TOKEN__"

Committed
closed
5
2014-08-25
2014-05-01
Alpha
No

Attached patch extends the C/C++ preprocessor to handle the following construct:

#if defined __TOKEN__
// do my code
#endif
1 Attachments

Discussion

  • Neil Hodgson

    Neil Hodgson - 2014-05-01

    The patch extends an earlier hack for handling defined in a direction that appears too complex and difficult to maintain. It would be better to move symbol look-up out of the initial lexing and into EvaluateTokens after the initial loop for checking "defined" clauses. Then augmenting the "defined" loop to handle "defined TOKEN".

     
  • Neil Hodgson

    Neil Hodgson - 2014-05-12
    • labels: --> lexer, cpp, scintilla
    • assigned_to: Neil Hodgson
    • Group: Completed --> Committed
     
  • Neil Hodgson

    Neil Hodgson - 2014-05-12

    Change set [efde54] implements #if defined TOKEN.

    It also implements handling of some macros with arguments. This is a large change so may contain bugs.

     

    Related

    Commit: [efde54]

  • Alpha

    Alpha - 2014-05-12

    Thanks for working on this. (I had started trying to refactor, but ran out of free time.)
    I will test and let you know if any problems arise for me.

     
  • Alpha

    Alpha - 2014-05-12

    Possibly a minor copy-paste error (-Wshadow)?

    diff --git a/src/sdk/wxscintilla/src/scintilla/lexers/LexCPP.cxx b/src/sdk/wxscintilla/src/scintilla/lexers/LexCPP.cxx
    index 8ff987a..152e63d 100644
    --- a/src/sdk/wxscintilla/src/scintilla/lexers/LexCPP.cxx
    +++ b/src/sdk/wxscintilla/src/scintilla/lexers/LexCPP.cxx
    @@ -1350,7 +1350,6 @@ void LexerCPP::EvaluateTokens(std::vector<std::string> &tokens, const SymbolTabl
                            SymbolTable::const_iterator it = preprocessorDefinitions.find(tokens[i]);
                            if (it != preprocessorDefinitions.end()) {
                                    // Tokenize value
    -                               std::vector<std::string> macroTokens = Tokenize(it->second.value);
                                    if (it->second.IsMacro()) {
                                            if ((i + 1 < tokens.size()) && (tokens.at(i + 1) == "(")) {
                                                    // Create map of argument name to value
    @@ -1390,6 +1389,7 @@ void LexerCPP::EvaluateTokens(std::vector<std::string> &tokens, const SymbolTabl
                                                    i++;
                                            }
                                    } else {
    +                                       std::vector<std::string> macroTokens = Tokenize(it->second.value);
                                            // Remove invocation
                                            tokens.erase(tokens.begin() + i);
                                            // Insert results back into tokens
    
     
    • Neil Hodgson

      Neil Hodgson - 2014-05-12

      Fixed the other way round with [ffc1bc], by relying on the initial declaration in all branches.

      -Wshadow and some other warnings are not turned on because other externally maintained lexers have shadowed variables and other issues.

       

      Related

      Commit: [ffc1bc]

  • Neil Hodgson

    Neil Hodgson - 2014-05-22
    • status: open --> closed
     

Log in to post a comment.