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

Bug in token coordinates #417

Open
corradods opened this issue May 26, 2021 · 3 comments
Open

Bug in token coordinates #417

corradods opened this issue May 26, 2021 · 3 comments

Comments

@corradods
Copy link

corradods commented May 26, 2021

I know this sounds like a really niche example, but it was made as simple as possible. This behavior is actually quite common with "strange" includes. Since I guess it's not the expected behavior and it's causing me a lot of problems in my analysis I wanted to know if it's possible to fix it.

//FILE intval.h
1
// FILEmain.c
int a =
#include "intval.h" 
;

 int main() {  ;  }

Ast show with coordinates:

FileAST:  (at None)
  Decl <ext[0]>: a, [], [], [] (at C:/Users/Corrado/Desktop/main.c:1:5)
    TypeDecl <type>: a, [] (at C:/Users/Corrado/Desktop/main.c:1:5)
      IdentifierType <type>: ['int'] (at C:/Users/Corrado/Desktop/main.c:1:1)
    Constant <init>: int, 1 (at C:/Users/Corrado/Desktop/main.c:1:1)                <---------Coordinate is wrong
  FuncDef <ext[1]>:  (at C:/Users/Corrado/Desktop/main.c:5:6)
    Decl <decl>: main, [], [], [] (at C:/Users/Corrado/Desktop/main.c:5:6)
      FuncDecl <type>:  (at C:/Users/Corrado/Desktop/main.c:5:6)
        TypeDecl <type>: main, [] (at C:/Users/Corrado/Desktop/main.c:5:6)
          IdentifierType <type>: ['int'] (at C:/Users/Corrado/Desktop/main.c:5:2)
    Compound <body>:  (at C:/Users/Corrado/Desktop/main.c:5:1)
      EmptyStatement <block_items[0]>:  (at C:/Users/Corrado/Desktop/main.c:5:15)

The pointed coordinate is wrong. Directives inserted by cpp preprocessor were right and reports correctly when i am entering and leaving the file.

cpp -E output:

# 1 "C:/Users/Corrado/Desktop/main.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "C:/Users/Corrado/Desktop/main.c"
int a =
# 1 "C:/Users/Corrado/Desktop/intval.h" 1               <--------------entering
1
# 3 "C:/Users/Corrado/Desktop/main.c" 2              <----------------leaving
;

 int main() { ; }
@eliben
Copy link
Owner

eliben commented May 27, 2021

I'm not sure I understand what's wrong in the coordinates; could you elaborate in more detail what you see, what you expect to see and why? Provide a minimal example with preprocessed code fed to pycparser, please.

@corradods
Copy link
Author

Hello Eli,
code is in the first part of the first post.
Preprocessed code is in the bottom of the same post.
What i expect is that the coordinates for this token:
Constant : int, 1 (at C:/Users/Corrado/Desktop/main.c:1:1)
were instead (at C:/Users/Corrado/Desktop/intval.h:1:1), since it comes from this piece of code:

int a =
#include "intval.h" 
;

@eliben
Copy link
Owner

eliben commented May 27, 2021

Got it, thanks. Yes, this could be improved. PRs welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants