Skip to content

Commit

Permalink
feat: visit import statements
Browse files Browse the repository at this point in the history
Signed-off-by: Prajwal S N <[email protected]>
  • Loading branch information
snprajwal committed Nov 6, 2023
1 parent c083f83 commit c3a276f
Show file tree
Hide file tree
Showing 10 changed files with 481 additions and 3,855 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "libdparse"]
path = libdparse
url = https://github.com/dlang-community/libdparse.git
[submodule "stdx-allocator"]
path = stdx-allocator
url = https://github.com/dlang-community/stdx-allocator
Expand Down
17 changes: 8 additions & 9 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
"targetType": "autodetect",
"license": "BSL-1.0",
"dependencies": {
"libdparse": ">=0.19.2 <1.0.0",
"dmd": "~>2.105.2"
"dmd": "~>2.106.0-beta.1"
},
"targetPath" : "bin/",
"targetName" : "dfmt",
"stringImportPaths" : [
"bin"
"targetPath": "bin/",
"targetName": "dfmt",
"stringImportPaths": [
"bin"
],
"versions" : [
"versions": [
"built_with_dub"
],
"preBuildCommands" : [
"$DC -run \"$PACKAGE_DIR/dubhash.d\""
"preBuildCommands": [
"$DC -run \"$PACKAGE_DIR/dubhash.d\""
]
}
1 change: 0 additions & 1 deletion libdparse
Submodule libdparse deleted from fe6d1e
271 changes: 271 additions & 0 deletions src/dfmt/ast.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
module dfmt.ast;

import dmd.visitor;
import dmd.astcodegen;
import std.range;
import std.stdio : writeln, File;

extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
{
File.LockingTextWriter buf;
uint depth;

this(File.LockingTextWriter buf)
{
this.buf = buf;
}

alias visit = SemanticTimeTransitiveVisitor.visit;

void newline()
{
version (Windows)
{
buf.put(0x0A0D); // newline is CR,LF on Microsoft OS's
}
else
{
buf.put('\n');
}
}

override:
/* void visit(ASTCodegen.Dsymbol s) */
/* { */
/* visitDsymbol(s); */
/* } */

/* void visit(ASTCodegen.StaticAssert s) */
/* { */
/* visitStaticAssert(s); */
/* } */

/* void visit(ASTCodegen.DebugSymbol s) */
/* { */
/* visitDebugSymbol(s); */
/* } */

/* void visit(ASTCodegen.VersionSymbol s) */
/* { */
/* visitVersionSymbol(s); */
/* } */

/* void visit(ASTCodegen.EnumMember em) */
/* { */
/* visitEnumMember(em); */
/* } */

void visit(ASTCodegen.Import imp)
{
if (imp.isstatic)
buf.put("static ");
buf.put("import ");
if (imp.aliasId)
{
buf.put(imp.aliasId.toString());
buf.put(" = ");
}
foreach (const pid; imp.packages)
{
buf.put(pid.toString());
buf.put(".");
}
buf.put(imp.id.toString());
if (imp.names.length)
{
buf.put(" : ");
foreach (const i, const name; imp.names)
{
if (i)
buf.put(", ");
const _alias = imp.aliases[i];
if (_alias)
{
buf.put(_alias.toString());
buf.put(" = ");
buf.put(name.toString());
}
else
buf.put(name.toString());
}
}

buf.put(';');
newline();
}

/* void visit(ASTCodegen.AliasThis d) */
/* { */
/* visitAliasThis(d); */
/* } */

/* void visit(ASTCodegen.AttribDeclaration d) */
/* { */
/* visitAttribDeclaration(d); */
/* } */

/* void visit(ASTCodegen.StorageClassDeclaration d) */
/* { */
/* visitStorageClassDeclaration(d); */
/* } */

/* void visit(ASTCodegen.DeprecatedDeclaration d) */
/* { */
/* visitDeprecatedDeclaration(d); */
/* } */

/* void visit(ASTCodegen.LinkDeclaration d) */
/* { */
/* visitLinkDeclaration(d); */
/* } */

/* void visit(ASTCodegen.CPPMangleDeclaration d) */
/* { */
/* visitCPPMangleDeclaration(d); */
/* } */

/* void visit(ASTCodegen.VisibilityDeclaration d) */
/* { */
/* visitVisibilityDeclaration(d); */
/* } */

/* void visit(ASTCodegen.AlignDeclaration d) */
/* { */
/* visitAlignDeclaration(d); */
/* } */

/* void visit(ASTCodegen.AnonDeclaration d) */
/* { */
/* visitAnonDeclaration(d); */
/* } */

/* void visit(ASTCodegen.PragmaDeclaration d) */
/* { */
/* visitPragmaDeclaration(d); */
/* } */

/* void visit(ASTCodegen.ConditionalDeclaration d) */
/* { */
/* visitConditionalDeclaration(d); */
/* } */

/* void visit(ASTCodegen.StaticForeachDeclaration s) */
/* { */
/* visitStaticForeachDeclaration(s); */
/* } */

/* void visit(ASTCodegen.MixinDeclaration d) */
/* { */
/* visitMixinDeclaration(d); */
/* } */

/* void visit(ASTCodegen.UserAttributeDeclaration d) */
/* { */
/* visitUserAttributeDeclaration(d); */
/* } */

/* void visit(ASTCodegen.TemplateDeclaration d) */
/* { */
/* visitTemplateDeclaration(d); */
/* } */

/* void visit(ASTCodegen.TemplateInstance ti) */
/* { */
/* visitTemplateInstance(ti); */
/* } */

/* void visit(ASTCodegen.TemplateMixin tm) */
/* { */
/* visitTemplateMixin(tm); */
/* } */

/* void visit(ASTCodegen.EnumDeclaration d) */
/* { */
/* visitEnumDeclaration(d); */
/* } */

/* void visit(ASTCodegen.Nspace d) */
/* { */
/* visitNspace(d); */
/* } */

/* void visit(ASTCodegen.StructDeclaration d) */
/* { */
/* visitStructDeclaration(d); */
/* } */

/* void visit(ASTCodegen.ClassDeclaration d) */
/* { */
/* visitClassDeclaration(d); */
/* } */

/* void visit(ASTCodegen.AliasDeclaration d) */
/* { */
/* visitAliasDeclaration(d); */
/* } */

/* void visit(ASTCodegen.AliasAssign d) */
/* { */
/* visitAliasAssign(d); */
/* } */

/* void visit(ASTCodegen.VarDeclaration d) */
/* { */
/* visitVarDeclaration(d); */
/* } */

/* void visit(ASTCodegen.FuncDeclaration f) */
/* { */
/* visitFuncDeclaration(f); */
/* } */

/* void visit(ASTCodegen.FuncLiteralDeclaration f) */
/* { */
/* visitFuncLiteralDeclaration(f); */
/* } */

/* void visit(ASTCodegen.PostBlitDeclaration d) */
/* { */
/* visitPostBlitDeclaration(d); */
/* } */

/* void visit(ASTCodegen.DtorDeclaration d) */
/* { */
/* visitDtorDeclaration(d); */
/* } */

/* void visit(ASTCodegen.StaticCtorDeclaration d) */
/* { */
/* visitStaticCtorDeclaration(d); */
/* } */

/* void visit(ASTCodegen.StaticDtorDeclaration d) */
/* { */
/* visitStaticDtorDeclaration(d); */
/* } */

/* void visit(ASTCodegen.InvariantDeclaration d) */
/* { */
/* visitInvariantDeclaration(d); */
/* } */

/* void visit(ASTCodegen.UnitTestDeclaration d) */
/* { */
/* visitUnitTestDeclaration(d); */
/* } */

/* void visit(ASTCodegen.BitFieldDeclaration d) */
/* { */
/* visitBitFieldDeclaration(d); */
/* } */

/* void visit(ASTCodegen.NewDeclaration d) */
/* { */
/* visitNewDeclaration(d); */
/* } */

/* void visit(ASTCodegen.Module m) */
/* { */
/* visitModule(m); */
/* } */
}
Loading

0 comments on commit c3a276f

Please sign in to comment.