Skip to content

Commit c3a276f

Browse files
committed
feat: visit import statements
Signed-off-by: Prajwal S N <[email protected]>
1 parent c083f83 commit c3a276f

File tree

10 files changed

+481
-3855
lines changed

10 files changed

+481
-3855
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "libdparse"]
2-
path = libdparse
3-
url = https://github.com/dlang-community/libdparse.git
41
[submodule "stdx-allocator"]
52
path = stdx-allocator
63
url = https://github.com/dlang-community/stdx-allocator

dub.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
"targetType": "autodetect",
55
"license": "BSL-1.0",
66
"dependencies": {
7-
"libdparse": ">=0.19.2 <1.0.0",
8-
"dmd": "~>2.105.2"
7+
"dmd": "~>2.106.0-beta.1"
98
},
10-
"targetPath" : "bin/",
11-
"targetName" : "dfmt",
12-
"stringImportPaths" : [
13-
"bin"
9+
"targetPath": "bin/",
10+
"targetName": "dfmt",
11+
"stringImportPaths": [
12+
"bin"
1413
],
15-
"versions" : [
14+
"versions": [
1615
"built_with_dub"
1716
],
18-
"preBuildCommands" : [
19-
"$DC -run \"$PACKAGE_DIR/dubhash.d\""
17+
"preBuildCommands": [
18+
"$DC -run \"$PACKAGE_DIR/dubhash.d\""
2019
]
2120
}

libdparse

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/dfmt/ast.d

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
module dfmt.ast;
2+
3+
import dmd.visitor;
4+
import dmd.astcodegen;
5+
import std.range;
6+
import std.stdio : writeln, File;
7+
8+
extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
9+
{
10+
File.LockingTextWriter buf;
11+
uint depth;
12+
13+
this(File.LockingTextWriter buf)
14+
{
15+
this.buf = buf;
16+
}
17+
18+
alias visit = SemanticTimeTransitiveVisitor.visit;
19+
20+
void newline()
21+
{
22+
version (Windows)
23+
{
24+
buf.put(0x0A0D); // newline is CR,LF on Microsoft OS's
25+
}
26+
else
27+
{
28+
buf.put('\n');
29+
}
30+
}
31+
32+
override:
33+
/* void visit(ASTCodegen.Dsymbol s) */
34+
/* { */
35+
/* visitDsymbol(s); */
36+
/* } */
37+
38+
/* void visit(ASTCodegen.StaticAssert s) */
39+
/* { */
40+
/* visitStaticAssert(s); */
41+
/* } */
42+
43+
/* void visit(ASTCodegen.DebugSymbol s) */
44+
/* { */
45+
/* visitDebugSymbol(s); */
46+
/* } */
47+
48+
/* void visit(ASTCodegen.VersionSymbol s) */
49+
/* { */
50+
/* visitVersionSymbol(s); */
51+
/* } */
52+
53+
/* void visit(ASTCodegen.EnumMember em) */
54+
/* { */
55+
/* visitEnumMember(em); */
56+
/* } */
57+
58+
void visit(ASTCodegen.Import imp)
59+
{
60+
if (imp.isstatic)
61+
buf.put("static ");
62+
buf.put("import ");
63+
if (imp.aliasId)
64+
{
65+
buf.put(imp.aliasId.toString());
66+
buf.put(" = ");
67+
}
68+
foreach (const pid; imp.packages)
69+
{
70+
buf.put(pid.toString());
71+
buf.put(".");
72+
}
73+
buf.put(imp.id.toString());
74+
if (imp.names.length)
75+
{
76+
buf.put(" : ");
77+
foreach (const i, const name; imp.names)
78+
{
79+
if (i)
80+
buf.put(", ");
81+
const _alias = imp.aliases[i];
82+
if (_alias)
83+
{
84+
buf.put(_alias.toString());
85+
buf.put(" = ");
86+
buf.put(name.toString());
87+
}
88+
else
89+
buf.put(name.toString());
90+
}
91+
}
92+
93+
buf.put(';');
94+
newline();
95+
}
96+
97+
/* void visit(ASTCodegen.AliasThis d) */
98+
/* { */
99+
/* visitAliasThis(d); */
100+
/* } */
101+
102+
/* void visit(ASTCodegen.AttribDeclaration d) */
103+
/* { */
104+
/* visitAttribDeclaration(d); */
105+
/* } */
106+
107+
/* void visit(ASTCodegen.StorageClassDeclaration d) */
108+
/* { */
109+
/* visitStorageClassDeclaration(d); */
110+
/* } */
111+
112+
/* void visit(ASTCodegen.DeprecatedDeclaration d) */
113+
/* { */
114+
/* visitDeprecatedDeclaration(d); */
115+
/* } */
116+
117+
/* void visit(ASTCodegen.LinkDeclaration d) */
118+
/* { */
119+
/* visitLinkDeclaration(d); */
120+
/* } */
121+
122+
/* void visit(ASTCodegen.CPPMangleDeclaration d) */
123+
/* { */
124+
/* visitCPPMangleDeclaration(d); */
125+
/* } */
126+
127+
/* void visit(ASTCodegen.VisibilityDeclaration d) */
128+
/* { */
129+
/* visitVisibilityDeclaration(d); */
130+
/* } */
131+
132+
/* void visit(ASTCodegen.AlignDeclaration d) */
133+
/* { */
134+
/* visitAlignDeclaration(d); */
135+
/* } */
136+
137+
/* void visit(ASTCodegen.AnonDeclaration d) */
138+
/* { */
139+
/* visitAnonDeclaration(d); */
140+
/* } */
141+
142+
/* void visit(ASTCodegen.PragmaDeclaration d) */
143+
/* { */
144+
/* visitPragmaDeclaration(d); */
145+
/* } */
146+
147+
/* void visit(ASTCodegen.ConditionalDeclaration d) */
148+
/* { */
149+
/* visitConditionalDeclaration(d); */
150+
/* } */
151+
152+
/* void visit(ASTCodegen.StaticForeachDeclaration s) */
153+
/* { */
154+
/* visitStaticForeachDeclaration(s); */
155+
/* } */
156+
157+
/* void visit(ASTCodegen.MixinDeclaration d) */
158+
/* { */
159+
/* visitMixinDeclaration(d); */
160+
/* } */
161+
162+
/* void visit(ASTCodegen.UserAttributeDeclaration d) */
163+
/* { */
164+
/* visitUserAttributeDeclaration(d); */
165+
/* } */
166+
167+
/* void visit(ASTCodegen.TemplateDeclaration d) */
168+
/* { */
169+
/* visitTemplateDeclaration(d); */
170+
/* } */
171+
172+
/* void visit(ASTCodegen.TemplateInstance ti) */
173+
/* { */
174+
/* visitTemplateInstance(ti); */
175+
/* } */
176+
177+
/* void visit(ASTCodegen.TemplateMixin tm) */
178+
/* { */
179+
/* visitTemplateMixin(tm); */
180+
/* } */
181+
182+
/* void visit(ASTCodegen.EnumDeclaration d) */
183+
/* { */
184+
/* visitEnumDeclaration(d); */
185+
/* } */
186+
187+
/* void visit(ASTCodegen.Nspace d) */
188+
/* { */
189+
/* visitNspace(d); */
190+
/* } */
191+
192+
/* void visit(ASTCodegen.StructDeclaration d) */
193+
/* { */
194+
/* visitStructDeclaration(d); */
195+
/* } */
196+
197+
/* void visit(ASTCodegen.ClassDeclaration d) */
198+
/* { */
199+
/* visitClassDeclaration(d); */
200+
/* } */
201+
202+
/* void visit(ASTCodegen.AliasDeclaration d) */
203+
/* { */
204+
/* visitAliasDeclaration(d); */
205+
/* } */
206+
207+
/* void visit(ASTCodegen.AliasAssign d) */
208+
/* { */
209+
/* visitAliasAssign(d); */
210+
/* } */
211+
212+
/* void visit(ASTCodegen.VarDeclaration d) */
213+
/* { */
214+
/* visitVarDeclaration(d); */
215+
/* } */
216+
217+
/* void visit(ASTCodegen.FuncDeclaration f) */
218+
/* { */
219+
/* visitFuncDeclaration(f); */
220+
/* } */
221+
222+
/* void visit(ASTCodegen.FuncLiteralDeclaration f) */
223+
/* { */
224+
/* visitFuncLiteralDeclaration(f); */
225+
/* } */
226+
227+
/* void visit(ASTCodegen.PostBlitDeclaration d) */
228+
/* { */
229+
/* visitPostBlitDeclaration(d); */
230+
/* } */
231+
232+
/* void visit(ASTCodegen.DtorDeclaration d) */
233+
/* { */
234+
/* visitDtorDeclaration(d); */
235+
/* } */
236+
237+
/* void visit(ASTCodegen.StaticCtorDeclaration d) */
238+
/* { */
239+
/* visitStaticCtorDeclaration(d); */
240+
/* } */
241+
242+
/* void visit(ASTCodegen.StaticDtorDeclaration d) */
243+
/* { */
244+
/* visitStaticDtorDeclaration(d); */
245+
/* } */
246+
247+
/* void visit(ASTCodegen.InvariantDeclaration d) */
248+
/* { */
249+
/* visitInvariantDeclaration(d); */
250+
/* } */
251+
252+
/* void visit(ASTCodegen.UnitTestDeclaration d) */
253+
/* { */
254+
/* visitUnitTestDeclaration(d); */
255+
/* } */
256+
257+
/* void visit(ASTCodegen.BitFieldDeclaration d) */
258+
/* { */
259+
/* visitBitFieldDeclaration(d); */
260+
/* } */
261+
262+
/* void visit(ASTCodegen.NewDeclaration d) */
263+
/* { */
264+
/* visitNewDeclaration(d); */
265+
/* } */
266+
267+
/* void visit(ASTCodegen.Module m) */
268+
/* { */
269+
/* visitModule(m); */
270+
/* } */
271+
}

0 commit comments

Comments
 (0)