Author Topic: Tagging not working with specific #defines  (Read 2228 times)

TKasparek

  • Senior Community Member
  • Posts: 246
  • Hero Points: 29
Tagging not working with specific #defines
« on: July 20, 2016, 05:09:59 PM »
The following compiles with g++:

Code: [Select]
// File tagging not working example.

#include <iostream>
using namespace std;

#define AccessorDeclaration(varType, varName)   \
    varType Get##varName() const;               \
    void Set##varName(varType newVal);


#define AccessorImplementation(varType, varName, className)                     \
    inline varType className::Get##varName() const { return varName; }          \
    inline void className::Set##varName(varType newVal) { varName = newVal; };

class MyClass {
public:
    MyClass() {MyClassVar = 12;}
    AccessorDeclaration(size_t, MyClassVar)
    size_t MyClassVar;
};

AccessorImplementation(size_t, MyClassVar, MyClass)

int main(int argc, char ** argv) {

    MyClass MyVar;

    cout << MyVar.GetMyClassVar() << endl;
    MyVar.SetMyClassVar(21);
    cout << MyVar.GetMyClassVar();

    return 0;
}

Notice the two uses of the preprocessor macros don't have a semicolon, as is not needed.
If you have Symbol coloring on and set to Use strict symbol lookups then:
  • The use of AccessorDeclaration in the class is colored as a Public member function. After you place the semicolon after it is correctly colored as a Preprocessor macro.
  • The use of AccessorImplementation is colored as a Global function. After you place the semicolon after it is correctly colored as a Preprocessor macro.
  • argc and arg v are colored as Symbol not found until AccessorImplementation has the semicolon placed.
  • GetMyClassVar and SetMyClassVar are colored as Symbol not found

Again the semicolons are not needed for this to compile. I understand why (4.) GetMyClassVar and SetMyClassVar aren't found, but the others seem like bugs. Any way around these?

TKasparek

  • Senior Community Member
  • Posts: 246
  • Hero Points: 29
Re: Tagging not working with specific #defines
« Reply #1 on: July 20, 2016, 05:23:01 PM »
OK, so (1.) and (3.) are SlickEdit 2016 alone I guess. I opened in 2015 and those seemed to work correctly again. In 2016 adding __attribute_section("SOMETHING") prior to a function causes all parameters to not tag correctly.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6866
  • Hero Points: 528
Re: Tagging not working with specific #defines
« Reply #2 on: July 21, 2016, 06:49:21 AM »
I see identical symbol coloring with 2015 as 2016.

This is a pretty classic problem for which there is no great work around. SlickEdit does not do full preprocessing. The work around for preprocessing macros like these is to define global preprocessing or preprocessing for the workspace. That way the parser sees the semicolons.

If you have too many different macros, it's not worth the effort. If you don't have that many, then it's worth it.

There are some heuristics in the parser that attempt to handle confusing preprocessing. It only works in some cases though as you are seeing.  "m() mytype MyClassVar;" works but "m() int foo();" doesn't. Looks like a simple problem...nope.

I'm going to pass this along to Dennis. Maybe he figure out a something that doesn't break other parsing cases badly.