Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line numbers set to 0 #116

Closed
MathieuChailloux opened this issue Mar 10, 2016 · 6 comments
Closed

Line numbers set to 0 #116

MathieuChailloux opened this issue Mar 10, 2016 · 6 comments

Comments

@MathieuChailloux
Copy link

Hi,

First of all, thanks for the work done over here.
I've noticed that field .coord.line is systematically set to 0 for nodes of classes Compound and EmptyStatement (and maybe some others).

For instance, considering below file toto.c :

void f() {
  if (1) {
    ;
  } else {
    return;
  }
}

Pycparser give me this :

>>> import pycparser
>>> ast = pycparser.parse_file("toto.c")
>>> ast.show(showcoord=True)
FileAST:  (at None)
  FuncDef:  (at toto.c:1)
    Decl: f, [], [], [] (at toto.c:1)
      FuncDecl:  (at toto.c:1)
        TypeDecl: f, [] (at toto.c:1)
          IdentifierType: ['void'] (at toto.c:1)
    Compound:  (at toto.c:0)
      If:  (at toto.c:2)
        Constant: int, 1 (at toto.c:2)
        Compound:  (at toto.c:0)
          EmptyStatement:  (at toto.c:0)
        Compound:  (at toto.c:0)
          Return:  (at toto.c:5)

Is this an implementation choice, a known issue, a new one ?

Regards

@eliben
Copy link
Owner

eliben commented Mar 11, 2016

Seems fairly arbitrary to me, since these nodes don't really have a concrete source representation

@MathieuChailloux
Copy link
Author

Well, I haven't explored deeply the grammar used for parsing but i guess an EmptyStatement is built when meeting a line containing a lonely ;, so to me it does have a concrete source representation and an associated line.

For Compound nodes, i guess they match opening and closing braces.
For instance, considering below files "toto3.c" and "toto4.c"

toto3.c

void f() {
  while(1)
    ;
}

toto4.c

void f() {
  while(1) {
    ;
  }
}

Pycparser gives me this

>>> ast3 = pycparser.parse_file("toto3.c")
>>> ast3.show(showcoord=True)
FileAST:  (at None)
  FuncDef:  (at toto3.c:1)
    Decl: f, [], [], [] (at toto3.c:1)
      FuncDecl:  (at toto3.c:1)
        TypeDecl: f, [] (at toto3.c:1)
          IdentifierType: ['void'] (at toto3.c:1)
    Compound:  (at toto3.c:0)
      While:  (at toto3.c:2)
        Constant: int, 1 (at toto3.c:2)
        EmptyStatement:  (at toto3.c:0)
>>> ast4 = pycparser.parse_file("toto4.c")
>>> ast4.show(showcoord=True)
FileAST:  (at None)
  FuncDef:  (at toto4.c:1)
    Decl: f, [], [], [] (at toto4.c:1)
      FuncDecl:  (at toto4.c:1)
        TypeDecl: f, [] (at toto4.c:1)
          IdentifierType: ['void'] (at toto4.c:1)
    Compound:  (at toto4.c:0)
      While:  (at toto4.c:2)
        Constant: int, 1 (at toto4.c:2)
        Compound:  (at toto4.c:0)
          EmptyStatement:  (at toto4.c:0)

That would lead me to think that they indeed match braces.

So I don't really see your point but maybe have I missed something.

Regards

@eliben
Copy link
Owner

eliben commented Mar 11, 2016

That sounds reasonable. Feel free to submit a PR and we can talk over the concrete details there

@guivigon
Copy link

guivigon commented Oct 6, 2016

Hi

sorry for asking again about this. It might be resolved and I'm not aware. Is this issue fixed? I'm interested on getting this functionality working...

Thanks.

Regards

@eliben
Copy link
Owner

eliben commented Oct 6, 2016

@guivigon Not that I know of

@eliben
Copy link
Owner

eliben commented Oct 12, 2016

I believe this should be fixed int the master branch now. Please LMK if you see additional issues.

@eliben eliben closed this as completed Oct 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants