Skip to content

Commit 813357c

Browse files
authored
Use counter instead of lexer line to name anonymous type (#219)
Fixes #217
1 parent 1d559c1 commit 813357c

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

cparser.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type
9999
# to 'foo: Foo' and not 'foo: var Foo'.
100100
continueActions: seq[PNode]
101101
currentSection: Section # can be nil
102+
anoTypeCount: int
102103

103104
ReplaceTuple* = array[0..1, string]
104105

@@ -867,13 +868,14 @@ proc structPragmas(p: Parser, name: PNode, origName: string,
867868
if isUnion: pragmas.add newIdentNodeP("union", p)
868869
result.add pragmas
869870

870-
proc hashPosition(p: Parser): string =
871+
proc hashPosition(p: var Parser): string =
871872
let lineInfo = parLineInfo(p)
872873
when declared(gConfig):
873874
let fileInfo = toFilename(gConfig, lineInfo.fileIndex).splitFile.name
874875
else:
875876
let fileInfo = toFilename(lineInfo.fileIndex).splitFile.name
876-
result = fileInfo & "_" & $lineInfo.line
877+
result = fileInfo & "_" & $p.anoTypeCount
878+
inc(p.anoTypeCount)
877879

878880
proc parseInnerStruct(p: var Parser, stmtList: PNode,
879881
isUnion: bool, name: string): PNode =
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type
2+
INNER_C_STRUCT_nestedanonymousstruct_3* {.bycopy.} = object
3+
a*: cint
4+
5+
INNER_C_STRUCT_nestedanonymousstruct_2* {.bycopy.} = object
6+
meow*: INNER_C_STRUCT_nestedanonymousstruct_3
7+
8+
miauz* {.bycopy.} = object
9+
meow2*: INNER_C_STRUCT_nestedanonymousstruct_2
10+

testsuite/results/struct_anonym.nim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ type
33
a*: cint
44
b*: cint
55

6-
INNER_C_UNION_struct_anonym_14* {.bycopy, union.} = object
6+
INNER_C_UNION_struct_anonym_1* {.bycopy, union.} = object
77
b*: cint
88

9-
INNER_C_STRUCT_struct_anonym_13* {.bycopy.} = object
10-
a_union_in_the_struct*: INNER_C_UNION_struct_anonym_14
9+
INNER_C_STRUCT_struct_anonym_0* {.bycopy.} = object
10+
a_union_in_the_struct*: INNER_C_UNION_struct_anonym_1
1111
c*: cint
1212

13-
INNER_C_STRUCT_struct_anonym_24* {.bycopy.} = object
13+
INNER_C_STRUCT_struct_anonym_4* {.bycopy.} = object
1414
e*: cint
1515

16-
INNER_C_UNION_struct_anonym_21* {.bycopy, union.} = object
16+
INNER_C_UNION_struct_anonym_3* {.bycopy, union.} = object
1717
d*: cint
18-
a_struct_in_the_union*: INNER_C_STRUCT_struct_anonym_24
18+
a_struct_in_the_union*: INNER_C_STRUCT_struct_anonym_4
1919

2020
outerStruct* {.bycopy.} = object
2121
a_nomal_one*: normal
2222
a*: cint
23-
ano_struct_anonym_18*: INNER_C_STRUCT_struct_anonym_13
24-
a_union*: INNER_C_UNION_struct_anonym_21
23+
ano_struct_anonym_2*: INNER_C_STRUCT_struct_anonym_0
24+
a_union*: INNER_C_UNION_struct_anonym_3
2525

testsuite/results/systest2.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ const
2929

3030
proc bcf_float_set*(`ptr`: ptr cfloat; value: uint32_t) {.inline, cdecl.} =
3131
type
32-
INNER_C_UNION_systest2_48 {.importc: "no_name", header: "iup.h", bycopy, union.} = object
32+
INNER_C_UNION_systest2_0 {.importc: "no_name", header: "iup.h", bycopy, union.} = object
3333
i: uint32_t
3434
f: cfloat
3535

36-
var u: INNER_C_UNION_systest2_48
36+
var u: INNER_C_UNION_systest2_0
3737
u.i = value
3838
`ptr`[] = u.f
3939

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
typedef struct
3+
{
4+
struct
5+
{
6+
struct
7+
{
8+
int a;
9+
} meow;
10+
} meow2;
11+
} miauz;

0 commit comments

Comments
 (0)