Bug in token coordinates
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() { ; }
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.
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 a =
#include "intval.h"
;
Got it, thanks. Yes, this could be improved. PRs welcome.