Bad ClassName in certains cases

Create issue
Issue #1 resolved
Former user created an issue


Thank you for your good work, im using it on mozilla-dev I found a bug that is blocking me on my work when i have this kind of code:

class Foo A_CLASS_DEFINE_HERE (with or without heritage) { //class Foo definition here };

it gives me A_CLASS_DEFINE_HERE as a class name but the full class name should be "Foo A_CLASS_DEFINE_HERE" i might have seen some examples where there was a define before the class name too the full class name must be the words between "class" and ":" or "{"

could you check what is going on with this? it also affect the classes that are heriting from class Foo

Thak you again.

Comments (26)

  1. senex repo owner

    Please provide a sample .h file that will reproduce the issue with as little extra as you can. With this I can help.

  2. Sixdsn
    class NS_STACK_CLASS nsTreeBodyFrame MOZ_FINAL
      : public nsLeafBoxFrame
      , public nsICSSPseudoComparator
      , public nsIScrollbarMediator
      , public nsIReflowCallback
      nsTreeBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
      class ScrollEvent : public nsRunnable {
        ScrollEvent(nsTreeBodyFrame *aInner) : mInner(aInner) {}
        void Revoke() { mInner = nsnull; }
        nsTreeBodyFrame* mInner;

    The script will give me MOZ_FINAL as classname for nsTreeBodyFrame and as namespace for ScrollEvent.

    I would like to have "NS_STACK_CLASS nsTreeBodyFrame MOZ_FINAL" as a classe name and namespace, because it is easier to extract the real name after that.

    Im sorry about the mistake i wrote early, it doesnt touch heritages, just nested classes

    Thank you,

  3. senex repo owner

    Looking into this, I would rather find a solution that does not involve putting spaces in a class name which would be invalid. Could you do the following?

    import CppHeaderParser CppHeaderParser.ignoreSymbols += ["NS_STACK_CLASS", "MOZ_FINAL"] cppHeader = CppHeaderParser.CppHeader(...)

    Doing this works for your example without the need for a code change in CppHeaderParser. It will cause the parser to skip over these symbols resulting in the right class name.

    Alternatively, I could add support for some form of extended symbols if you needed to keep this data around for your project.

  4. Sixdsn

    Thank you,

    actually it seems that thoses defines are not important for my job, there are just usefull at compilation time

    im gonna try this today and check if it is exactly what i want but it looks like ;)

  5. Sixdsn

    I confirm, it works exactly as i want as i'm able to ignore thoses keywords

    Thank you very much your project was very helpful on my work :)

    i have just a last question : is it possible to get the real line content that is being parsed by your module? i mean, i would like to get the real line in the methods declarations to be able to compare them. i got them in tokens but it would be really safer to have the line that is actually wroten in the file

    do you think it's possible?


  6. senex repo owner

    I'm afraid I dont understand exactly what you are asking. Are you saying for method X you want to know the line number method X was found on for example?

    Also, out of curiosity, what are you using CppHeaderParser for?

  7. Sixdsn

    I would like to have the real line content as a string for a method Foo as : "void Foo(int i, char c);" stocked somewhere in the cppHeader[classes] struct do you see what i mean? :)

    its for mozilla-central a migration to c++11 i have to add a keyword to some specific methods

  8. senex repo owner

    I think what you are looking for is the "debug" attribute. Here is an example

    sample_header = """\
    class CrowClass
        void testSlot(int i);
    cppHeader = CppHeaderParser.CppHeader(sample_header, "string")
    print cppHeader.classes["CrowClass"]["methods"]["private"][0]["debug"]

    This will print "void testSlot ( int i ) ;"

  9. senex repo owner

    My pleasure. I love Firefox, so please message me when you are done with CppHeaderParser to tell me how it went and what you used it for.

  10. Sixdsn

    It's done I had to add the keyword "override" (migration to C++2011) to all methods from child classes that are overriding their mother's classes methods in one of the folder of the mozilla core Your parser really help me

    Thank you very much again :)

  11. Sixdsn

    Hi again,

    earlier you said: Are you saying for method X you want to know the line number method X was found on for example

    is it possible? finally it would make my replacements part much reliable and simple


  12. senex repo owner

    The current code does not expose the line number, partially because it would not always be accurate. Do you require this?

  13. Sixdsn

    it would be very efficient yes because if i dont get it i need to do a personnal parser to modify the files its working but i still miss specific things but if i have the line number it has to be the good one why wouldnt it be accurate?

  14. senex repo owner

    I will see what I can do tonight. There is some pre-processing I do on the file, I will have to make sure it doesn't modify line numbers.

  15. Sixdsn

    ok thanks maybe you can get number of lines in the file before you do the preproces and compare it to the number of lines after to get the difference of lines if your preprocess just adds lines on the top of the file

  16. senex repo owner

    Try the latest commit 89:dad8a82b929c

    This adds the attribute "line_number" which will give you the line numbers for the given method/class/property etc

  17. Sixdsn

    It's awesome :) im using it right now and it works really great i dont have to search the pattern i want to modify now that i have the line

    i just had a few bug (coming from me) because the line_number begin to '1' but my file lines_array begins to 0

    so easy to do many things with your module we really thank you very much :)

  18. Sixdsn

    Hi again,

    i'm back working on my script to improve it. i still have a little issue with the "line_number" attribute. it looks like things like this:

    NS_IMETHOD  HandleEvent(nsPresContext* aPresContext,
                              nsGUIEvent*     aEvent,
                              nsEventStatus*  aEventStatus) MOZ_OVERRIDE;
    NS_IMETHOD  GetContentForEvent(nsEvent* aEvent,
                                     nsIContent** aContent);

    does not work properly. it looks like it says the GetContentForEvent method is on line 2 but it should say its on line 4. is it possible to patch your code to give the real line number in the file?

  19. senex repo owner

    I just tried your example, and it works perfectly for me. Here is the output that I get (notice the line numbers are correct for each function and parameter).

    {'line_number': 2, 'static': False, 'rtnType': 'NS_IMETHOD', 'const': False, 'parameters': [{'line_number': 2, 'constant': 0, 'name': 'aPresContext', 'reference': 0, 'type': 'nsPresContext *', 'static': 0, 'pointer': 1}, {'line_number': 3, 'constant': 0, 'name': 'aEvent', 'reference': 0, 'type': 'nsGUIEvent *', 'static': 0, 'pointer': 1}, {'line_number': 4, 'constant': 0, 'name': 'aEventStatus', 'reference': 0, 'type': 'nsEventStatus *', 'static': 0, 'pointer': 1}], 'namespace': '', 'virtual': False, 'destructor': False, 'returns': 'NS_IMETHOD', 'template': False, 'friend': False, 'unresolved_parameters': True, 'returns_class': False, 'extern': False, 'returns_pointer': 0, 'class': None, 'name': 'HandleEvent', 'pure_virtual': False, 'explicit': False, 'returns_fundamental': False, 'constructor': False, 'debug': 'NS_IMETHOD HandleEvent ( nsPresContext * aPresContext , nsGUIEvent * aEvent , nsEventStatus * aEventStatus ) MOZ_OVERRIDE ;', 'inline': False}
    {'line_number': 5, 'static': False, 'rtnType': 'NS_IMETHOD', 'const': False, 'parameters': [{'line_number': 5, 'constant': 0, 'name': 'aEvent', 'reference': 0, 'type': 'nsEvent *', 'static': 0, 'pointer': 1}, {'line_number': 6, 'constant': 0, 'name': 'aContent', 'reference': 0, 'type': 'nsIContent * *', 'static': 0, 'pointer': 2}], 'namespace': '', 'virtual': False, 'destructor': False, 'returns': 'NS_IMETHOD', 'template': False, 'friend': False, 'unresolved_parameters': True, 'returns_class': False, 'extern': False, 'returns_pointer': 0, 'class': None, 'name': 'GetContentForEvent', 'pure_virtual': False, 'explicit': False, 'returns_fundamental': False, 'constructor': False, 'debug': 'NS_IMETHOD GetContentForEvent ( nsEvent * aEvent , nsIContent * * aContent ) ;', 'inline': False}

    Are you using version 2.3? If so, please attach a file and the results of printing the resulting parsed object tree since I cannot replicate the error.

  20. Sixdsn


    yep i saw later that this example was working, i thought it was this part of the file that was making it wrong. So i did some checks: with version dad8a82b929c, i didnt get that kind of problems, but in my script this version isnt not as good as the 2.3 with 2.3 version, it works better but this is where i found the line_number problem.

    here i uploaded some files:

    nsFrame.h: one of the files where the error occurs.

    senex.example: juste an example with one function where the function in nsFrame.h is at line 209 but the package says 208

    senex.full: the full log with all the missing functions and the prettyprint for the entire file nsFrame.h

    you will see that all the missing functions are not found at the good line. format: File, M|F, class::function, line_number

    thank you for your time.

  21. Log in to comment