-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathnamer.d
More file actions
100 lines (83 loc) · 1.69 KB
/
namer.d
File metadata and controls
100 lines (83 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import std.conv;
import std.path;
import ast;
import visitor;
class Namer : Visitor
{
string name;
this()
{
}
alias super.visit visit;
override void visit(FuncDeclaration ast)
{
name = "function " ~ ast.id;
}
override void visit(VarDeclaration ast)
{
name = "variable " ~ ast.id;
}
override void visit(VersionDeclaration ast)
{
ast.members[0][0].visit(this);
name = "version " ~ name;
}
override void visit(TypedefDeclaration ast)
{
name = "typedef " ~ ast.id;
}
override void visit(MacroDeclaration ast)
{
name = "macro " ~ ast.id;
}
override void visit(StructDeclaration ast)
{
name = "struct " ~ ast.id;
}
override void visit(ExternCDeclaration ast)
{
ast.decls[0].visit(this);
name = "externc " ~ name;
}
override void visit(EnumDeclaration ast)
{
if (ast.id.length)
name = "enum " ~ ast.id;
else
{
foreach(m; ast.members)
{
if (m.id)
{
name = "enum " ~ m.id;
return;
}
}
}
}
}
class LongNamer : Namer
{
alias super.visit visit;
override void visit(FuncDeclaration ast)
{
name = "function " ~ ast.id;
foreach(p; ast.params)
{
name ~= p.t ? p.t.mangle : "??";
}
}
}
string getName(Declaration decl)
{
assert(decl);
auto v = new Namer();
decl.visit(v);
return v.name;
}
string getLongName(Declaration decl)
{
auto v = new LongNamer();
decl.visit(v);
return v.name;
}