From cb8c0ff916f257d91356f553e464897bb82cd907 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Wed, 22 Aug 2018 01:11:22 +0200 Subject: [PATCH 1/7] Testing D to H tool --- src/dmd/dtoh.d | 1256 ++++++++++++++++++++++++++++++++++++++++++++++++ src/posix.mak | 3 + 2 files changed, 1259 insertions(+) create mode 100644 src/dmd/dtoh.d diff --git a/src/dmd/dtoh.d b/src/dmd/dtoh.d new file mode 100644 index 000000000000..1eaf4ddea043 --- /dev/null +++ b/src/dmd/dtoh.d @@ -0,0 +1,1256 @@ +// Compiler implementation of the D programming language +// Copyright (c) 1999-2015 by Digital Mars +// All Rights Reserved +// written by Walter Bright +// http://www.digitalmars.com +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +module dmd.dtoh; + +import core.stdc.stdio; +import core.stdc.string; +import core.stdc.ctype; + +import dmd.astcodegen; +import dmd.arraytypes; +import dmd.globals; +import dmd.identifier; +import dmd.visitor; + +import dmd.root.outbuffer; + +immutable string[] frontendSources = [ + "access.d", "aggregate.d", "aliasthis.d", "apply.d", "argtypes.d", "arrayop.d", "arraytypes.d", "attrib.d", + "blockexit.d", "builtin.d", + "canthrow.d", "clone.d", "compiler.d", "complex.d", "cond.d", "console.d", "constfold.d", "cppmangle.d", "cppmanglewin.d", "ctfeexpr.d", "ctorflow.d", + "dcast.d", "dclass.d", "declaration.d", "delegatize.d", "denum.d", "dimport.d", "dinterpret.d", + "dmacro.d", "dmangle.d", "dmodule.d", "doc.d", "dscope.d", "dstruct.d", "dsymbol.d", "dsymbolsem.d", "dtemplate.d", "dversion.d", + "entity.d", "errors.d", "escape.d", "expression.d", "expressionsem.d", + "func.d", + "globals.d", "gluelayer.d", + "hdrgen.d", + "iasm.d", "id.d", "identifier.d", "impcnvtab.d", "imphint.d", "init.d", "initsem.d", "inline.d", "inlinecost.d", "intrange.d", + "json.d", + "lambdacomp.d", "lexer.d", + "mtype.d", + "nogc.d", "nspace.d", + "objc.d", "opover.d", "optimize.d", + "parse.d", "printast.d", + "safe.d", "sapply.d", "semantic2.d", "semantic3.d", "sideeffect.d", "statement.d", + "statementsem.d", "staticassert.d", "staticcond.d", + "target.d", "templateparamsem.d", "tokens.d", "traits.d", "typesem.d", "typinf.d", + "utf.d", "utils.d", +]; + +private bool isIdentifierClass(ASTCodegen.ClassDeclaration cd) +{ + return (cd.ident == Identifier.idPool("Identifier") && + cd.parent !is null && + cd.parent.ident == Identifier.idPool("identifier") && + cd.parent.parent && cd.parent.parent.ident == Identifier.idPool("dmd") && + !cd.parent.parent.parent); +} + +private bool isVisitorClass(ASTCodegen.ClassDeclaration cd) +{ + for (auto cdb = cd; cdb; cdb = cdb.baseClass) + { + if (cdb.ident == Identifier.idPool("Visitor") || + cdb.ident == Identifier.idPool("ParseTimeVisitor")) + return true; + } + return false; +} + +private bool isFrontendModule(ASTCodegen.Module m) +{ + if (!m || !m.parent) + return false; + + // Ignore dmd.root + if (m.parent.ident == Identifier.idPool("root") && + m.parent.parent && m.parent.parent.ident == Identifier.idPool("dmd") && + !m.parent.parent.parent) + { + return false; + } + + // Ignore dmd.visitor and derivatives + if ((m.ident == Identifier.idPool("visitor") || + m.ident == Identifier.idPool("parsetimevisitor") || + m.ident == Identifier.idPool("permissivevisitor") || + m.ident == Identifier.idPool("strictvisitor") || + m.ident == Identifier.idPool("transitivevisitor")) && + m.parent && m.parent.ident == Identifier.idPool("dmd") && + !m.parent.parent) + { + return false; + } + + return ((m.parent.ident == Identifier.idPool("dmd") && !m.parent.parent) || + (m.parent.parent.ident == Identifier.idPool("dmd") && !m.parent.parent.parent)); +} + +/**************************************************** + */ +void genCppFiles(OutBuffer* buf, Modules *ms) +{ + import dmd.tokens; + + extern(C++) final class ToCppBuffer(AST) : Visitor + { + alias visit = super.visit; + public: + bool[void*] visited; + bool[void*] forwarded; + OutBuffer *fwdbuf; + OutBuffer *checkbuf; + OutBuffer *donebuf; + OutBuffer *buf; + AST.AggregateDeclaration adparent; + AST.ClassDeclaration cdparent; + AST.TemplateDeclaration tdparent; + Identifier ident; + LINK linkage = LINK.d; + + this(OutBuffer* checkbuf, OutBuffer* fwdbuf, OutBuffer* donebuf, OutBuffer* buf) + { + this.checkbuf = checkbuf; + this.fwdbuf = fwdbuf; + this.donebuf = donebuf; + this.buf = buf; + } + + private void indent() + { + if (adparent) + buf.writestring(" "); + } + + override void visit(AST.Dsymbol s) + { + if (s.getModule() && s.getModule().isFrontendModule()) + { + indent(); + buf.printf("// ignored %s %s\n", s.kind(), s.toPrettyChars()); + } + } + + override void visit(AST.Import) + { + } + + override void visit(AST.AttribDeclaration pd) + { + Dsymbols* decl = pd.include(null); + if (decl) + { + foreach (s; *decl) + { + if (!adparent && s.prot().kind < AST.Prot.Kind.public_) + continue; + s.accept(this); + } + } + } + + override void visit(AST.LinkDeclaration ld) + { + auto save = linkage; + linkage = ld.linkage; + if (ld.linkage != LINK.c && ld.linkage != LINK.cpp) + { + indent(); + buf.printf("// ignoring %s block because of linkage\n", ld.toPrettyChars()); + } + else + visit(cast(AST.AttribDeclaration)ld); + linkage = save; + } + + override void visit(AST.Module m) + { + foreach (s; *m.members) + { + if (s.prot().kind < AST.Prot.Kind.public_) + continue; + s.accept(this); + } + } + + override void visit(AST.FuncDeclaration fd) + { + if (cast(void*)fd in visited) + return; + if (fd.getModule() && !fd.getModule().isFrontendModule()) + return; + // printf("FuncDeclaration %s %s\n", fd.toPrettyChars(), fd.type.toChars()); + visited[cast(void*)fd] = true; + + auto tf = cast(AST.TypeFunction)fd.type; + indent(); + if (!tf || !tf.deco) + { + buf.printf("// ignoring function %s because semantic hasn't been run\n", fd.toPrettyChars()); + return; + } + if (tf.linkage != LINK.c && tf.linkage != LINK.cpp) + { + buf.printf("// ignoring function %s because of linkage\n", fd.toPrettyChars()); + return; + } + if (!adparent && !fd.fbody) + { + buf.printf("// ignoring function %s because it's extern\n", fd.toPrettyChars()); + return; + } + + if (tf.linkage == LINK.c) + buf.writestring("extern \"C\" "); + else if (!adparent) + buf.writestring("extern "); + if (adparent && fd.isStatic()) + buf.writestring("static "); + if (adparent && fd.vtblIndex != -1) + { + if (!fd.isOverride()) + buf.writestring("virtual "); + + auto s = adparent.search(Loc.initial, fd.ident); + if (!(adparent.storage_class & AST.STC.abstract_) && + !(cast(AST.ClassDeclaration)adparent).isAbstract() && + s is fd && !fd.overnext) + { + auto save = buf; + buf = checkbuf; + buf.writestring(" assert(getSlotNumber<"); + buf.writestring(adparent.ident.toChars()); + buf.writestring(">(0, &"); + buf.writestring(adparent.ident.toChars()); + buf.writestring("::"); + buf.writestring(fd.ident.toChars()); + buf.printf(") == %d);\n", fd.vtblIndex); + buf = save; + } + } + funcToBuffer(tf, fd.ident); + if (adparent && tf.isConst()) + buf.writestring(" const"); + if (adparent && fd.isAbstract()) + buf.writestring(" = 0"); + buf.printf(";\n"); + if (!adparent) + buf.printf("\n"); + } + + override void visit(AST.UnitTestDeclaration fd) + { + } + + override void visit(AST.VarDeclaration vd) + { + if (cast(void*)vd in visited) + return; + if (vd.getModule() && !vd.getModule().isFrontendModule()) + return; + visited[cast(void*)vd] = true; + + if (vd.storage_class & AST.STC.manifest && + vd.type.isintegral() && + vd._init && vd._init.isExpInitializer()) + { + indent(); + buf.writestring("#define "); + buf.writestring(vd.ident.toChars()); + buf.writestring(" "); + auto e = AST.initializerToExpression(vd._init); + if (e.type.ty == AST.Tbool) + buf.printf("%d", e.toInteger()); + else + AST.initializerToExpression(vd._init).accept(this); + buf.writestring("\n"); + if (!adparent) + buf.printf("\n"); + return; + } + + if (tdparent && vd.type && !vd.type.deco) + { + indent(); + if (linkage != LINK.c && linkage != LINK.cpp) + { + buf.printf("// ignoring variable %s because of linkage\n", vd.toPrettyChars()); + return; + } + typeToBuffer(vd.type, vd.ident); + buf.writestring(";\n"); + return; + } + + if (vd.storage_class & (AST.STC.static_ | AST.STC.extern_ | AST.STC.tls | AST.STC.gshared) || + vd.parent && vd.parent.isModule()) + { + indent(); + if (vd.linkage != LINK.c && vd.linkage != LINK.cpp) + { + buf.printf("// ignoring variable %s because of linkage\n", vd.toPrettyChars()); + return; + } + if (vd.storage_class & AST.STC.tls) + { + buf.printf("// ignoring variable %s because of thread-local storage\n", vd.toPrettyChars()); + return; + } + if (vd.linkage == LINK.c) + buf.writestring("extern \"C\" "); + else if (!adparent) + buf.writestring("extern "); + if (adparent) + buf.writestring("static "); + typeToBuffer(vd.type, vd.ident); + buf.writestring(";\n"); + if (!adparent) + buf.printf("\n"); + return; + } + + if (adparent && vd.type && vd.type.deco) + { + indent(); + auto save = cdparent; + cdparent = vd.isField() ? adparent.isClassDeclaration() : null; + typeToBuffer(vd.type, vd.ident); + cdparent = save; + buf.writestring(";\n"); + if (vd.type.ty == AST.Tstruct) + { + auto t = cast(AST.TypeStruct)vd.type; + includeSymbol(t.sym); + } + auto savex = buf; + buf = checkbuf; + buf.writestring(" assert(offsetof("); + buf.writestring(adparent.ident.toChars()); + buf.writestring(", "); + buf.writestring(vd.ident.toChars()); + buf.printf(") == %d);\n", vd.offset); + buf = savex; + return; + } + + visit(cast(AST.Dsymbol)vd); + } + + override void visit(AST.TypeInfoDeclaration) + { + } + + override void visit(AST.AliasDeclaration ad) + { + if (ad.getModule() && !ad.getModule().isFrontendModule()) + return; + if (auto t = ad.type) + { + if (t.ty == AST.Tdelegate) + { + visit(cast(AST.Dsymbol)ad); + return; + } + buf.writestring("typedef "); + typeToBuffer(t, ad.ident); + buf.writestring(";\n"); + if (!adparent) + buf.printf("\n"); + return; + } + if (!ad.aliassym) + { + ad.print(); + assert(0); + } + if (auto ti = ad.aliassym.isTemplateInstance()) + { + visitTi(ti); + return; + } + if (auto sd = ad.aliassym.isStructDeclaration()) + { + buf.writestring("typedef "); + sd.type.accept(this); + buf.writestring(" "); + buf.writestring(ad.ident.toChars()); + buf.writestring(";\n"); + if (!adparent) + buf.printf("\n"); + return; + } + indent(); + buf.printf("// ignored %s %s\n", ad.aliassym.kind(), ad.aliassym.toPrettyChars()); + } + + override void visit(AST.AnonDeclaration ad) + { + buf.writestring(ad.isunion ? "union" : "struct"); + buf.writestring("\n{\n"); + foreach (s; *ad.decl) + { + s.accept(this); + } + buf.writestring("};\n"); + } + + private bool memberField(AST.VarDeclaration vd) + { + if (!vd.type || !vd.type.deco || !vd.ident) + return false; + if (!vd.isField()) + return false; + if (vd.type.ty == AST.Tfunction) + return false; + if (vd.type.ty == AST.Tsarray) + return false; + return true; + } + + override void visit(AST.StructDeclaration sd) + { + if (sd.isInstantiated()) + return; + if (cast(void*)sd in visited) + return; + if (!sd.type || !sd.type.deco) + return; + if (sd.getModule() && !sd.getModule().isFrontendModule()) + return; + visited[cast(void*)sd] = true; + + if (sd.alignment == 1) + buf.writestring("#pragma pack(push, 1)\n"); + buf.writestring(sd.isUnionDeclaration() ? "union " : "struct "); + buf.writestring(sd.ident.toChars()); + if (sd.members) + { + buf.writestring("\n{\n"); + auto save = adparent; + adparent = sd; + foreach (m; *sd.members) + { + m.accept(this); + } + adparent = save; + // Generate default ctor + buf.printf(" %s(", sd.ident.toChars()); + buf.printf(") {"); + size_t varCount; + foreach (m; *sd.members) + { + if (auto vd = m.isVarDeclaration()) + { + if (!memberField(vd)) + continue; + varCount++; + if (!vd._init && !vd.type.isTypeBasic()) + continue; + buf.printf(" this->%s = ", vd.ident.toChars()); + if (vd._init) + AST.initializerToExpression(vd._init).accept(this); + else if (vd.type.isTypeBasic()) + vd.type.defaultInitLiteral(Loc.initial).accept(this); + buf.printf(";"); + } + } + buf.printf(" }\n"); + + if (varCount) + { + buf.printf(" %s(", sd.ident.toChars()); + bool first = true; + foreach (m; *sd.members) + { + if (auto vd = m.isVarDeclaration()) + { + if (!memberField(vd)) + continue; + if (first) + first = false; + else + buf.writestring(", "); + assert(vd.type); + assert(vd.ident); + typeToBuffer(vd.type, vd.ident); + } + } + buf.printf(") {"); + foreach (m; *sd.members) + { + if (auto vd = m.isVarDeclaration()) + { + if (!memberField(vd)) + continue; + buf.printf(" this->%s = %s;", vd.ident.toChars(), vd.ident.toChars()); + } + } + buf.printf(" }\n"); + } + + buf.writestring("};\n\n"); + + if (sd.alignment == 1) + buf.writestring("#pragma pack(pop)\n"); + + auto savex = buf; + buf = checkbuf; + buf.writestring(" assert(sizeof("); + buf.writestring(sd.ident.toChars()); + buf.printf(") == %d);\n", sd.size(Loc.initial)); + buf = savex; + } + else + buf.writestring(";\n\n"); + } + + private void includeSymbol(AST.Dsymbol ds) + { + // printf("Forward declaring %s %d\n", ds.toChars(), level); + if (cast(void*)ds !in visited) + { + OutBuffer decl; + auto save = buf; + buf = &decl; + ds.accept(this); + buf = save; + donebuf.writestring(decl.peekString()); + } + } + + override void visit(AST.ClassDeclaration cd) + { + if (cast(void*)cd in visited) + return; + if (cd.getModule() && !cd.getModule().isFrontendModule()) + return; + if (cd.isVisitorClass()) + return; + visited[cast(void*)cd] = true; + if (!cd.isCPPclass()) + { + buf.printf("// ignoring non-cpp class %s\n", cd.toChars()); + return; + } + + buf.writestring("class "); + buf.writestring(cd.ident.toChars()); + if (cd.baseClass) + { + buf.writestring(" : public "); + buf.writestring(cd.baseClass.ident.toChars()); + + includeSymbol(cd.baseClass); + } + if (cd.members) + { + buf.writestring("\n{\npublic:\n"); + auto save = adparent; + adparent = cd; + foreach (m; *cd.members) + { + m.accept(this); + } + adparent = save; + // Generate special static inline function. + if (cd.isIdentifierClass()) + { + buf.writestring(" static inline Identifier *idPool(const char *s) { return idPool(s, strlen(s)); }\n"); + } + buf.writestring("};\n\n"); + } + else + buf.writestring(";\n\n"); + } + + override void visit(AST.EnumDeclaration ed) + { + if (cast(void*)ed in visited) + return; + if (ed.getModule() && !ed.getModule().isFrontendModule()) + return; + visited[cast(void*)ed] = true; + if (ed.isSpecial()) + return; + buf.writestring("enum"); + const(char)* ident = null; + if (ed.ident) + ident = ed.ident.toChars(); + if (ident) + { + buf.writeByte(' '); + buf.writestring(ident); + } + if (ed.members) + { + buf.writestring("\n{\n"); + foreach (i, m; *ed.members) + { + if (i) + buf.writestring(",\n"); + buf.writestring(" "); + if (ident) + { + foreach (c; ident[0 .. strlen(ident)]) + buf.writeByte(toupper(c)); + } + m.accept(this); + } + buf.writestring("\n};\n\n"); + } + else + buf.writestring(";\n\n"); + } + + override void visit(AST.EnumMember em) + { + buf.writestring(em.ident.toChars()); + buf.writestring(" = "); + assert(em.value.op == TOK.int64); + auto ie = cast(AST.IntegerExp)em.value; + visitInteger(ie.toInteger(), em.ed.memtype); + } + + private void typeToBuffer(AST.Type t, Identifier ident) + { + this.ident = ident; + t.accept(this); + if (this.ident) + { + buf.writeByte(' '); + buf.writestring(ident.toChars()); + } + this.ident = null; + if (t.ty == AST.Tsarray) + { + auto tsa = cast(AST.TypeSArray)t; + buf.writeByte('['); + tsa.dim.accept(this); + buf.writeByte(']'); + } + } + + override void visit(AST.Type t) + { + printf("Invalid type: %s\n", t.toPrettyChars()); + assert(0); + } + + override void visit(AST.TypeIdentifier t) + { + buf.writestring(t.ident.toChars()); + } + + override void visit(AST.TypeBasic t) + { + if (!cdparent && t.isConst()) + buf.writestring("const "); + switch (t.ty) + { + case AST.Tbool, AST.Tvoid: + case AST.Tchar, AST.Twchar, AST.Tdchar: + case AST.Tint8, AST.Tuns8: + case AST.Tint16, AST.Tuns16: + case AST.Tint32, AST.Tuns32: + case AST.Tint64, AST.Tuns64: + case AST.Tfloat32, AST.Tfloat64, AST.Tfloat80: + buf.writestring("_d_"); + buf.writestring(t.dstring); + break; + default: + t.print(); + assert(0); + } + } + + override void visit(AST.TypePointer t) + { + if (t.next.ty == AST.Tstruct && + !strcmp((cast(AST.TypeStruct)t.next).sym.ident.toChars(), "__va_list_tag")) + { + buf.writestring("va_list"); + return; + } + t.next.accept(this); + if (t.next.ty != AST.Tfunction) + buf.writeByte('*'); + if (!cdparent && t.isConst()) + buf.writestring(" const"); + } + + override void visit(AST.TypeSArray t) + { + t.next.accept(this); + } + + override void visit(AST.TypeAArray t) + { + AST.Type.tvoidptr.accept(this); + } + + override void visit(AST.TypeFunction tf) + { + tf.next.accept(this); + buf.writeByte('('); + buf.writeByte('*'); + if (ident) + buf.writestring(ident.toChars()); + ident = null; + buf.writeByte(')'); + buf.writeByte('('); + foreach (i; 0 .. AST.Parameter.dim(tf.parameters)) + { + if (i) + buf.writestring(", "); + auto fparam = AST.Parameter.getNth(tf.parameters, i); + fparam.accept(this); + } + if (tf.varargs) + { + if (tf.parameters.dim && tf.varargs == 1) + buf.writestring(", "); + buf.writestring("..."); + } + buf.writeByte(')'); + } + + private void enumToBuffer(AST.EnumDeclaration ed) + { + if (ed.isSpecial()) + { + if (ed.ident == Identifier.idPool("__c_long")) + buf.writestring("long"); + else if (ed.ident == Identifier.idPool("__c_ulong")) + buf.writestring("unsigned long"); + else if (ed.ident == Identifier.idPool("__c_longlong")) + buf.writestring("long long"); + else if (ed.ident == Identifier.idPool("__c_ulonglong")) + buf.writestring("unsigned long long"); + else if (ed.ident == Identifier.idPool("__c_long_double")) + buf.writestring("long double"); + else + { + ed.print(); + assert(0); + } + } + else + buf.writestring(ed.toChars()); + } + + override void visit(AST.TypeEnum t) + { + if (cast(void*)t.sym !in forwarded) + { + forwarded[cast(void*)t.sym] = true; + auto save = buf; + buf = fwdbuf; + t.sym.accept(this); + buf = save; + } + if (!cdparent && t.isConst()) + buf.writestring("const "); + enumToBuffer(t.sym); + } + + override void visit(AST.TypeStruct t) + { + if (cast(void*)t.sym !in forwarded && + !t.sym.parent.isTemplateInstance()) + { + forwarded[cast(void*)t.sym] = true; + fwdbuf.writestring(t.sym.isUnionDeclaration() ? "union " : "struct "); + fwdbuf.writestring(t.sym.toChars()); + fwdbuf.writestring(";\n"); + } + + if (!cdparent && t.isConst()) + buf.writestring("const "); + if (auto ti = t.sym.parent.isTemplateInstance()) + { + visitTi(ti); + return; + } + buf.writestring(t.sym.toChars()); + } + + override void visit(AST.TypeDArray t) + { + if (!cdparent && t.isConst()) + buf.writestring("const "); + buf.writestring("DArray<"); + t.next.accept(this); + buf.writestring(">"); + } + + private void visitTi(AST.TemplateInstance ti) + { + if (ti.tempdecl.ident == Identifier.idPool("AssocArray")) + { + buf.writestring("AA*"); + return; + } + if (ti.tempdecl.ident == Identifier.idPool("Array")) + buf.writestring("Array"); + else + { + foreach (o; *ti.tiargs) + { + if (!AST.isType(o)) + return; + } + buf.writestring(ti.tempdecl.ident.toChars()); + } + buf.writeByte('<'); + foreach (i, o; *ti.tiargs) + { + if (i) + buf.writestring(", "); + if (auto tt = AST.isType(o)) + { + tt.accept(this); + } + else + { + ti.print(); + o.print(); + assert(0); + } + } + buf.writeByte('>'); + } + + override void visit(AST.TemplateDeclaration td) + { + if (cast(void*)td in visited) + return; + visited[cast(void*)td] = true; + + if (td.getModule() && !td.getModule().isFrontendModule()) + return; + if (!td.parameters || !td.onemember || !td.onemember.isStructDeclaration()) + { + visit(cast(AST.Dsymbol)td); + return; + } + + // Explcitly disallow templates with non-type parameters or specialization. + foreach (p; *td.parameters) + { + if (!p.isTemplateTypeParameter() || p.specialization()) + { + visit(cast(AST.Dsymbol)td); + return; + } + } + + if (linkage != LINK.c && linkage != LINK.cpp) + { + buf.printf("// ignoring template %s because of linkage\n", td.toPrettyChars()); + return; + } + + auto sd = td.onemember.isStructDeclaration(); + auto save = tdparent; + tdparent = td; + indent(); + buf.writestring("template <"); + bool first = true; + foreach (p; *td.parameters) + { + if (first) + first = false; + else + buf.writestring(", "); + buf.writestring("typename "); + buf.writestring(p.ident.toChars()); + } + buf.writestring(">\n"); + buf.writestring(sd.isUnionDeclaration() ? "union " : "struct "); + buf.writestring(sd.ident.toChars()); + if (sd.members) + { + buf.writestring("\n{\n"); + auto savex = adparent; + adparent = sd; + foreach (m; *sd.members) + { + m.accept(this); + } + adparent = savex; + buf.writestring("};\n\n"); + } + else + buf.writestring(";\n\n"); + tdparent = save; + } + + override void visit(AST.TypeClass t) + { + if (cast(void*)t.sym !in forwarded) + { + forwarded[cast(void*)t.sym] = true; + fwdbuf.writestring("class "); + fwdbuf.writestring(t.sym.toChars()); + fwdbuf.writestring(";\n"); + } + + if (!cdparent && t.isConst()) + buf.writestring("const "); + buf.writestring(t.sym.toChars()); + buf.writeByte('*'); + if (!cdparent && t.isConst()) + buf.writestring(" const"); + } + + private void funcToBuffer(AST.TypeFunction tf, Identifier ident) + { + assert(tf.next); + tf.next.accept(this); + if (tf.isref) + buf.writeByte('&'); + buf.writeByte(' '); + buf.writestring(ident.toChars()); + + buf.writeByte('('); + foreach (i; 0 .. AST.Parameter.dim(tf.parameters)) + { + if (i) + buf.writestring(", "); + auto fparam = AST.Parameter.getNth(tf.parameters, i); + fparam.accept(this); + } + if (tf.varargs) + { + if (tf.parameters.dim && tf.varargs == 1) + buf.writestring(", "); + buf.writestring("..."); + } + buf.writeByte(')'); + } + + override void visit(AST.Parameter p) + { + ident = p.ident; + p.type.accept(this); + assert(!(p.storageClass & ~(AST.STC.ref_))); + if (p.storageClass & AST.STC.ref_) + buf.writeByte('&'); + buf.writeByte(' '); + if (ident) + buf.writestring(ident.toChars()); + ident = null; + if (p.defaultArg) + { + // buf.writestring("/*"); + buf.writestring(" = "); + p.defaultArg.accept(this); + // buf.writestring("*/"); + } + } + + override void visit(AST.Expression e) + { + e.print(); + assert(0); + } + + override void visit(AST.NullExp e) + { + buf.writestring("_d_null"); + } + + override void visit(AST.ArrayLiteralExp e) + { + buf.writestring("arrayliteral"); + } + + override void visit(AST.StringExp e) + { + assert(e.sz == 1 || e.sz == 2); + if (e.sz == 2) + buf.writeByte('L'); + buf.writeByte('"'); + size_t o = buf.offset; + for (size_t i = 0; i < e.len; i++) + { + uint c = e.charAt(i); + switch (c) + { + case '"': + case '\\': + buf.writeByte('\\'); + goto default; + default: + if (c <= 0xFF) + { + if (c <= 0x7F && isprint(c)) + buf.writeByte(c); + else + buf.printf("\\x%02x", c); + } + else if (c <= 0xFFFF) + buf.printf("\\x%02x\\x%02x", c & 0xFF, c >> 8); + else + buf.printf("\\x%02x\\x%02x\\x%02x\\x%02x", c & 0xFF, (c >> 8) & 0xFF, (c >> 16) & 0xFF, c >> 24); + break; + } + } + buf.writeByte('"'); + } + + override void visit(AST.RealExp e) + { + buf.writestring("0"); + } + + override void visit(AST.IntegerExp e) + { + visitInteger(e.toInteger, e.type); + } + + private void visitInteger(dinteger_t v, AST.Type t) + { + switch (t.ty) + { + case AST.Tenum: + auto te = cast(AST.TypeEnum)t; + buf.writestring("("); + enumToBuffer(te.sym); + buf.writestring(")"); + visitInteger(v, te.sym.memtype); + break; + case AST.Tbool: + buf.writestring(v ? "true" : "false"); + break; + case AST.Tint8: + buf.printf("%d", cast(byte)v); + break; + case AST.Tuns8: + case AST.Tchar: + buf.printf("%uu", cast(ubyte)v); + break; + case AST.Tint16: + buf.printf("%d", cast(short)v); + break; + case AST.Tuns16: + buf.printf("%uu", cast(ushort)v); + break; + case AST.Tint32: + buf.printf("%d", cast(int)v); + break; + case AST.Tuns32: + buf.printf("%uu", cast(uint)v); + break; + case AST.Tint64: + buf.printf("%lldLL", v); + break; + case AST.Tuns64: + buf.printf("%lluLLU", v); + break; + default: + t.print(); + assert(0); + } + } + + override void visit(AST.StructLiteralExp sle) + { + buf.writestring(sle.sd.ident.toChars()); + buf.writeByte('('); + foreach(i, e; *sle.elements) + { + if (i) + buf.writestring(", "); + e.accept(this); + } + buf.writeByte(')'); + } + } + + buf.writeByte('\n'); + buf.printf("// Automatically generated by dtoh\n"); + buf.writeByte('\n'); + buf.writestring("#include \n"); + buf.writestring("#include \n"); + buf.writestring("#include \n"); + buf.writestring("#include \n"); + buf.writeByte('\n'); + buf.writestring("#define _d_void void\n"); + buf.writestring("#define _d_bool bool\n"); + buf.writestring("#define _d_byte signed char\n"); + buf.writestring("#define _d_ubyte unsigned char\n"); + buf.writestring("#define _d_short short\n"); + buf.writestring("#define _d_ushort unsigned short\n"); + buf.writestring("#define _d_int int\n"); + buf.writestring("#define _d_uint unsigned\n"); + if (global.params.isLP64) + { + buf.writestring("#define _d_long long\n"); + buf.writestring("#define _d_ulong unsigned long\n"); + } + else + { + buf.writestring("#define _d_long long long\n"); + buf.writestring("#define _d_ulong unsigned long long\n"); + } + buf.writestring("#define _d_float float\n"); + buf.writestring("#define _d_double double\n"); + buf.writestring("#define _d_real long double\n"); + buf.writestring("#define _d_char char\n"); + buf.writestring("#define _d_wchar wchar_t\n"); + buf.writestring("#define _d_dchar unsigned\n"); + buf.writestring("\n"); + buf.writestring("#define _d_null NULL\n"); + buf.writestring("\n"); + buf.writestring("struct AA;\n"); + buf.writestring("\n"); + + OutBuffer check; + check.writestring(` +#if OFFSETS + +template +size_t getSlotNumber(int dummy, ...) +{ + T c; + va_list ap; + va_start(ap, dummy); + void *f = va_arg(ap, void*); + for (size_t i = 0; ; i++) + { + if ( (*(void***)&c)[i] == f) + return i; + } + va_end(ap); +} + +void testOffsets() +{ + `); + + OutBuffer done; + OutBuffer decl; + scope v = new ToCppBuffer!ASTCodegen(&check, buf, &done, &decl); + foreach (m; *ms) + { + buf.printf("// Parsing module %s\n", m.toPrettyChars()); + m.accept(v); + } + buf.write(&done); + buf.write(&decl); + + check.writestring(` +} +#endif + `); + + debug buf.write(&check); +} + +void main() +{ + import std.stdio; + import std.algorithm.sorting : sort; + import std.array : array; + import std.file : readText; + import std.path : baseName, buildPath, dirName; + import std.string : toStringz; + + import dmd.id; + import dmd.parse; + import dmd.dsymbolsem; + import dmd.semantic2; + import dmd.semantic3; + import dmd.builtin : builtin_init; + import dmd.dmodule : Module; + import dmd.cond : VersionCondition; + import dmd.expression : Expression; + import dmd.objc : Objc; + import dmd.target : Target; + + import core.memory; + + GC.disable(); + + global._init(); + global.params.isLinux = true; + global.params.is64bit = (size_t.sizeof == 8); + global.params.isLP64 = global.params.is64bit; + + global.path = new Strings(); + global.path.push(__FILE_FULL_PATH__.dirName.buildPath("../../../druntime/src/").toStringz()); + + global.filePath = new Strings(); + global.params.fileImppath = global.filePath; + global.filePath.push(__FILE_FULL_PATH__.dirName.buildPath("../../").toStringz()); + global.filePath.push(__FILE_FULL_PATH__.dirName.buildPath("../../res/").toStringz()); + + ASTCodegen.Type._init(); + Id.initialize(); + Module._init(); + Target._init(); + Expression._init(); + Objc._init(); + builtin_init(); + + VersionCondition.addPredefinedGlobalIdent("all"); + VersionCondition.addPredefinedGlobalIdent("DigitalMars"); + VersionCondition.addPredefinedGlobalIdent("Posix"); + VersionCondition.addPredefinedGlobalIdent("linux"); + VersionCondition.addPredefinedGlobalIdent("CRuntime_Glibc"); + VersionCondition.addPredefinedGlobalIdent("NoBackend"); + VersionCondition.addPredefinedGlobalIdent("NoMain"); + if (global.params.is64bit) + VersionCondition.addPredefinedGlobalIdent("X86_64"); + else + VersionCondition.addPredefinedGlobalIdent("X86"); + if (global.params.isLP64) + VersionCondition.addPredefinedGlobalIdent("D_LP64"); + + Modules modules; + + string path = __FILE_FULL_PATH__.dirName.buildPath("../dmd/"); + + foreach (f; frontendSources) + { + string fn = buildPath(path, f); + + auto id = Identifier.idPool(baseName(fn, ".d")); + auto m = new Module(fn.toStringz(), id, false, false); + auto input = readText(fn); + + if (!Module.rootModule) + Module.rootModule = m; + + m.importedFrom = m; + m.srcfile.setbuffer(cast(void*)input.ptr, input.length); + m.srcfile._ref = 1; + m.parse(); + modules.push(m); + } + + foreach (m; modules) + m.importAll(null); + foreach (m; modules) + m.dsymbolSemantic(null); + Module.dprogress = 1; + Module.runDeferredSemantic(); + foreach (m; modules) + m.semantic2(null); + Module.runDeferredSemantic2(); + foreach (m; modules) + m.semantic3(null); + Module.runDeferredSemantic3(); + + OutBuffer buf; + genCppFiles(&buf, &modules); + + writeln(buf.peekSlice()); +} diff --git a/src/posix.mak b/src/posix.mak index bc001797be9f..5503bf229935 100644 --- a/src/posix.mak +++ b/src/posix.mak @@ -627,6 +627,9 @@ dscanner: $(DSCANNER_DIR)/dsc ###################################################### +$G/dtoh: $D/dtoh.d $(FRONT_SRCS) $D/gluelayer.d $(ROOT_SRCS) $G/newdelete.o $G/lexer.a $(STRING_IMPORT_FILES) $(HOST_DMD_PATH) + CC="$(HOST_CXX)" $(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J../res -L-lstdc++ $(DFLAGS) -version=NoBackend -version=NoMain $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH),$^) + $G/cxxfrontend.o: $G/%.o: tests/%.c $(SRC) $(ROOT_SRC) $(CXX) -c -o$@ $(CXXFLAGS) $(DMD_FLAGS) $(MMD) $< From 9f7b99426c91b49a40823cb105ab204223876c0f Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Wed, 22 Aug 2018 01:12:34 +0200 Subject: [PATCH 2/7] Fix object.h to compile with converted sources --- src/dmd/root/object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dmd/root/object.h b/src/dmd/root/object.h index b33d42295f05..e94a56442301 100644 --- a/src/dmd/root/object.h +++ b/src/dmd/root/object.h @@ -60,5 +60,5 @@ class RootObject * Used as a replacement for dynamic_cast. Returns a unique number * defined by the library user. For Object, the return value is 0. */ - virtual int dyncast() const; + virtual DYNCAST dyncast() const; }; From 29013adf1516456e604eaf219f99535a19af49a2 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Wed, 22 Aug 2018 01:19:33 +0200 Subject: [PATCH 3/7] Use generated frontend.h in C++ test --- src/posix.mak | 6 +++- src/tests/cxxfrontend.c | 62 ++++++++++------------------------------- 2 files changed, 20 insertions(+), 48 deletions(-) diff --git a/src/posix.mak b/src/posix.mak index 5503bf229935..c8870ac4520b 100644 --- a/src/posix.mak +++ b/src/posix.mak @@ -494,6 +494,7 @@ build-examples: $(EXAMPLES) clean: rm -Rf $(GENERATED) rm -f $(addprefix $D/backend/, $(optabgen_output)) + rm -f $D/frontend.h @[ ! -d ${PGO_DIR} ] || echo You should issue manually: rm -rf ${PGO_DIR} ######## Download and install the last dmd buildable without dmd @@ -630,7 +631,10 @@ dscanner: $(DSCANNER_DIR)/dsc $G/dtoh: $D/dtoh.d $(FRONT_SRCS) $D/gluelayer.d $(ROOT_SRCS) $G/newdelete.o $G/lexer.a $(STRING_IMPORT_FILES) $(HOST_DMD_PATH) CC="$(HOST_CXX)" $(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J../res -L-lstdc++ $(DFLAGS) -version=NoBackend -version=NoMain $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH),$^) -$G/cxxfrontend.o: $G/%.o: tests/%.c $(SRC) $(ROOT_SRC) +$D/frontend.h: $G/dtoh + $G/dtoh > $D/frontend.h + +$G/cxxfrontend.o: $G/%.o: tests/%.c $D/frontend.h $(SRC) $(ROOT_SRC) $(CXX) -c -o$@ $(CXXFLAGS) $(DMD_FLAGS) $(MMD) $< $G/cxx-unittest: $G/cxxfrontend.o $(DMD_SRCS) $(ROOT_SRCS) $G/newdelete.o $G/lexer.a $(G_OBJS) $(G_DOBJS) $(STRING_IMPORT_FILES) $(HOST_DMD_PATH) diff --git a/src/tests/cxxfrontend.c b/src/tests/cxxfrontend.c index 99d6e3cd4af1..cf4d56ea2f5e 100644 --- a/src/tests/cxxfrontend.c +++ b/src/tests/cxxfrontend.c @@ -8,54 +8,22 @@ * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/tests/cxxfrontend.c, _cxxfrontend.c) */ -#include "root/array.h" -#include "root/ctfloat.h" -#include "root/dcompat.h" -#include "root/file.h" -#include "root/filename.h" -#include "root/longdouble.h" -#include "root/object.h" -#include "root/outbuffer.h" -#include "root/port.h" -#include "root/rmem.h" -#include "root/root.h" -#include "root/thread.h" - -#include "aggregate.h" -#include "aliasthis.h" -#include "arraytypes.h" -#include "attrib.h" -#include "compiler.h" -#include "complex_t.h" -#include "cond.h" -#include "ctfe.h" -#include "declaration.h" -#include "doc.h" -#include "dsymbol.h" -#include "enum.h" -#include "errors.h" -#include "expression.h" -#include "globals.h" -#include "hdrgen.h" -#include "identifier.h" -#include "id.h" -#include "import.h" -#include "init.h" -#include "json.h" -#include "mars.h" -#include "mangle.h" -#include "module.h" -#include "mtype.h" -#include "nspace.h" -#include "objc.h" -#include "scope.h" -#include "statement.h" -#include "staticassert.h" -#include "target.h" -#include "template.h" -#include "tokens.h" -#include "version.h" +#include "array.h" +#include "ctfloat.h" +#include "file.h" +#include "filename.h" +#include "longdouble.h" +#include "object.h" +// FIXME: UINT64_MAX +//#include "outbuffer.h" +//#include "port.h" +#include "rmem.h" +//#include "root.h" +//#include "stringtable.h" +#include "thread.h" + #include "visitor.h" +#include "frontend.h" /**********************************/ From 2ecd09140c54128f2ad91a625a1eefd2d3536232 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Wed, 22 Aug 2018 01:36:45 +0200 Subject: [PATCH 4/7] Remove unused and redundant dmd headers --- src/dmd/aggregate.h | 329 ----------- src/dmd/aliasthis.h | 28 - src/dmd/attrib.h | 241 -------- src/dmd/cond.h | 94 --- src/dmd/ctfe.h | 66 --- src/dmd/declaration.h | 800 ------------------------- src/dmd/dsymbol.h | 388 ------------ src/dmd/enum.h | 88 --- src/dmd/expression.h | 1274 ---------------------------------------- src/dmd/hdrgen.h | 28 - src/dmd/id.h | 16 - src/dmd/identifier.h | 41 -- src/dmd/import.h | 55 -- src/dmd/init.h | 98 ---- src/dmd/json.h | 17 - src/dmd/module.h | 166 ------ src/dmd/mtype.h | 824 -------------------------- src/dmd/nspace.h | 35 -- src/dmd/objc.h | 54 -- src/dmd/scope.h | 142 ----- src/dmd/statement.h | 722 ----------------------- src/dmd/staticassert.h | 28 - src/dmd/target.h | 86 --- src/dmd/template.h | 329 ----------- src/dmd/tokens.h | 230 -------- src/dmd/version.h | 39 -- src/posix.mak | 9 +- 27 files changed, 2 insertions(+), 6225 deletions(-) delete mode 100644 src/dmd/aggregate.h delete mode 100644 src/dmd/aliasthis.h delete mode 100644 src/dmd/attrib.h delete mode 100644 src/dmd/cond.h delete mode 100644 src/dmd/ctfe.h delete mode 100644 src/dmd/declaration.h delete mode 100644 src/dmd/dsymbol.h delete mode 100644 src/dmd/enum.h delete mode 100644 src/dmd/expression.h delete mode 100644 src/dmd/hdrgen.h delete mode 100644 src/dmd/id.h delete mode 100644 src/dmd/identifier.h delete mode 100644 src/dmd/import.h delete mode 100644 src/dmd/init.h delete mode 100644 src/dmd/json.h delete mode 100644 src/dmd/module.h delete mode 100644 src/dmd/mtype.h delete mode 100644 src/dmd/nspace.h delete mode 100644 src/dmd/objc.h delete mode 100644 src/dmd/scope.h delete mode 100644 src/dmd/statement.h delete mode 100644 src/dmd/staticassert.h delete mode 100644 src/dmd/target.h delete mode 100644 src/dmd/template.h delete mode 100644 src/dmd/tokens.h delete mode 100644 src/dmd/version.h diff --git a/src/dmd/aggregate.h b/src/dmd/aggregate.h deleted file mode 100644 index 460e2c0547d5..000000000000 --- a/src/dmd/aggregate.h +++ /dev/null @@ -1,329 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/aggregate.h - */ - -#pragma once - -#include "dsymbol.h" -#include "objc.h" - -class Identifier; -class Type; -class TypeFunction; -class Expression; -class FuncDeclaration; -class CtorDeclaration; -class DtorDeclaration; -class NewDeclaration; -class DeleteDeclaration; -class InterfaceDeclaration; -class TypeInfoClassDeclaration; -class VarDeclaration; - -enum Sizeok -{ - SIZEOKnone, // size of aggregate is not yet able to compute - SIZEOKfwd, // size of aggregate is ready to compute - SIZEOKdone // size of aggregate is set correctly -}; - -enum Baseok -{ - BASEOKnone, // base classes not computed yet - BASEOKin, // in process of resolving base classes - BASEOKdone, // all base classes are resolved - BASEOKsemanticdone // all base classes semantic done -}; - -enum StructPOD -{ - ISPODno, // struct is not POD - ISPODyes, // struct is POD - ISPODfwd // POD not yet computed -}; - -enum Abstract -{ - ABSfwdref = 0, // whether an abstract class is not yet computed - ABSyes, // is abstract class - ABSno // is not abstract class -}; - -FuncDeclaration *search_toString(StructDeclaration *sd); - -struct ClassKind -{ - enum Type - { - /// the aggregate is a d(efault) struct/class/interface - d, - /// the aggregate is a C++ struct/class/interface - cpp, - /// the aggregate is an Objective-C class/interface - objc - }; -}; - -class AggregateDeclaration : public ScopeDsymbol -{ -public: - Type *type; - StorageClass storage_class; - Prot protection; - unsigned structsize; // size of struct - unsigned alignsize; // size of struct for alignment purposes - VarDeclarations fields; // VarDeclaration fields - Sizeok sizeok; // set when structsize contains valid data - Dsymbol *deferred; // any deferred semantic2() or semantic3() symbol - bool isdeprecated; // true if deprecated - - ClassKind::Type classKind; // specifies the linkage type - - /* !=NULL if is nested - * pointing to the dsymbol that directly enclosing it. - * 1. The function that enclosing it (nested struct and class) - * 2. The class that enclosing it (nested class only) - * 3. If enclosing aggregate is template, its enclosing dsymbol. - * See AggregateDeclaraton::makeNested for the details. - */ - Dsymbol *enclosing; - VarDeclaration *vthis; // 'this' parameter if this aggregate is nested - // Special member functions - FuncDeclarations invs; // Array of invariants - FuncDeclaration *inv; // invariant - NewDeclaration *aggNew; // allocator - DeleteDeclaration *aggDelete; // deallocator - - Dsymbol *ctor; // CtorDeclaration or TemplateDeclaration - - // default constructor - should have no arguments, because - // it would be stored in TypeInfo_Class.defaultConstructor - CtorDeclaration *defaultCtor; - - Dsymbol *aliasthis; // forward unresolved lookups to aliasthis - bool noDefaultCtor; // no default construction - - DtorDeclarations dtors; // Array of destructors - DtorDeclaration *dtor; // aggregate destructor - DtorDeclaration *primaryDtor; // non-deleting C++ destructor, same as dtor for D - DtorDeclaration *tidtor; // aggregate destructor used in TypeInfo (must have extern(D) ABI) - FuncDeclaration *fieldDtor; // aggregate destructor for just the fields - - Expression *getRTInfo; // pointer to GC info generated by object.RTInfo(this) - - virtual Scope *newScope(Scope *sc); - void setScope(Scope *sc); - bool determineFields(); - bool determineSize(Loc loc); - virtual void finalizeSize() = 0; - d_uns64 size(const Loc &loc); - bool fill(Loc loc, Expressions *elements, bool ctorinit); - Type *getType(); - bool isDeprecated(); // is aggregate deprecated? - bool isNested(); - void makeNested(); - bool isExport() const; - Dsymbol *searchCtor(); - - Prot prot(); - - // 'this' type - Type *handleType() { return type; } - - // Back end - Symbol *stag; // tag symbol for debug data - Symbol *sinit; - - AggregateDeclaration *isAggregateDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -struct StructFlags -{ - enum Type - { - none = 0x0, - hasPointers = 0x1 // NB: should use noPointers as in ClassFlags - }; -}; - -class StructDeclaration : public AggregateDeclaration -{ -public: - bool zeroInit; // !=0 if initialize with 0 fill - bool hasIdentityAssign; // true if has identity opAssign - bool hasIdentityEquals; // true if has identity opEquals - bool hasNoFields; // has no fields - FuncDeclarations postblits; // Array of postblit functions - FuncDeclaration *postblit; // aggregate postblit - - FuncDeclaration *xeq; // TypeInfo_Struct.xopEquals - FuncDeclaration *xcmp; // TypeInfo_Struct.xopCmp - FuncDeclaration *xhash; // TypeInfo_Struct.xtoHash - static FuncDeclaration *xerreq; // object.xopEquals - static FuncDeclaration *xerrcmp; // object.xopCmp - - structalign_t alignment; // alignment applied outside of the struct - StructPOD ispod; // if struct is POD - - // For 64 bit Efl function call/return ABI - Type *arg1type; - Type *arg2type; - - // Even if struct is defined as non-root symbol, some built-in operations - // (e.g. TypeidExp, NewExp, ArrayLiteralExp, etc) request its TypeInfo. - // For those, today TypeInfo_Struct is generated in COMDAT. - bool requestTypeInfo; - - static StructDeclaration *create(Loc loc, Identifier *id, bool inObject); - Dsymbol *syntaxCopy(Dsymbol *s); - void semanticTypeInfoMembers(); - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - const char *kind() const; - void finalizeSize(); - bool fit(const Loc &loc, Scope *sc, Expressions *elements, Type *stype); - bool isPOD(); - - StructDeclaration *isStructDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class UnionDeclaration : public StructDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *s); - const char *kind() const; - - UnionDeclaration *isUnionDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -struct BaseClass -{ - Type *type; // (before semantic processing) - - ClassDeclaration *sym; - unsigned offset; // 'this' pointer offset - // for interfaces: Array of FuncDeclaration's - // making up the vtbl[] - FuncDeclarations vtbl; - - DArray baseInterfaces; // if BaseClass is an interface, these - // are a copy of the InterfaceDeclaration::interfaces - - BaseClass(); - BaseClass(Type *type); - - bool fillVtbl(ClassDeclaration *cd, FuncDeclarations *vtbl, int newinstance); - void copyBaseInterfaces(BaseClasses *); -}; - -struct ClassFlags -{ - enum Type - { - none = 0x0, - isCOMclass = 0x1, - noPointers = 0x2, - hasOffTi = 0x4, - hasCtor = 0x8, - hasGetMembers = 0x10, - hasTypeInfo = 0x20, - isAbstract = 0x40, - isCPPclass = 0x80, - hasDtor = 0x100 - }; -}; - -class ClassDeclaration : public AggregateDeclaration -{ -public: - static ClassDeclaration *object; - static ClassDeclaration *throwable; - static ClassDeclaration *exception; - static ClassDeclaration *errorException; - static ClassDeclaration *cpp_type_info_ptr; - - ClassDeclaration *baseClass; // NULL only if this is Object - FuncDeclaration *staticCtor; - FuncDeclaration *staticDtor; - Dsymbols vtbl; // Array of FuncDeclaration's making up the vtbl[] - Dsymbols vtblFinal; // More FuncDeclaration's that aren't in vtbl[] - - BaseClasses *baseclasses; // Array of BaseClass's; first is super, - // rest are Interface's - - DArray interfaces; // interfaces[interfaces_dim] for this class - // (does not include baseClass) - - BaseClasses *vtblInterfaces; // array of base interfaces that have - // their own vtbl[] - - TypeInfoClassDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration - bool com; // true if this is a COM class (meaning it derives from IUnknown) - bool stack; // true if this is a scope class - int cppDtorVtblIndex; // slot reserved for the virtual destructor [extern(C++)] - bool inuse; // to prevent recursive attempts - bool isActuallyAnonymous; // true if this class has an identifier, but was originally declared anonymous - // used in support of https://issues.dlang.org/show_bug.cgi?id=17371 - - Abstract isabstract; // 0: fwdref, 1: is abstract class, 2: not abstract - Baseok baseok; // set the progress of base classes resolving - ObjcClassDeclaration objc; // Data for a class declaration that is needed for the Objective-C integration - Symbol *cpp_type_info_ptr_sym; // cached instance of class Id.cpp_type_info_ptr - - static ClassDeclaration *create(Loc loc, Identifier *id, BaseClasses *baseclasses, Dsymbols *members, bool inObject); - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - bool isBaseOf2(ClassDeclaration *cd); - - #define OFFSET_RUNTIME 0x76543210 - #define OFFSET_FWDREF 0x76543211 - virtual bool isBaseOf(ClassDeclaration *cd, int *poffset); - bool isAnonymous(); - - bool isBaseInfoComplete(); - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - ClassDeclaration *searchBase(Identifier *ident); - void finalizeSize(); - bool isFuncHidden(FuncDeclaration *fd); - FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); - bool isCOMclass() const; - virtual bool isCOMinterface() const; - bool isCPPclass() const; - virtual bool isCPPinterface() const; - bool isAbstract(); - virtual int vtblOffset() const; - const char *kind() const; - - void addLocalClass(ClassDeclarations *); - - // Back end - Dsymbol *vtblsym; - Dsymbol *vtblSymbol(); - - ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class InterfaceDeclaration : public ClassDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - bool isBaseOf(ClassDeclaration *cd, int *poffset); - bool isBaseOf(BaseClass *bc, int *poffset); - const char *kind() const; - int vtblOffset() const; - bool isCPPinterface() const; - bool isCOMinterface() const; - - InterfaceDeclaration *isInterfaceDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/aliasthis.h b/src/dmd/aliasthis.h deleted file mode 100644 index 0a2b9ba3070b..000000000000 --- a/src/dmd/aliasthis.h +++ /dev/null @@ -1,28 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 2009-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/aliasthis.h - */ - -#pragma once - -#include "globals.h" -#include "dsymbol.h" - -/**************************************************************/ - -class AliasThis : public Dsymbol -{ -public: - // alias Identifier this; - Identifier *ident; - - Dsymbol *syntaxCopy(Dsymbol *); - const char *kind() const; - AliasThis *isAliasThis() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/attrib.h b/src/dmd/attrib.h deleted file mode 100644 index e8e3237e0e92..000000000000 --- a/src/dmd/attrib.h +++ /dev/null @@ -1,241 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/attrib.h - */ - -#pragma once - -#include "root/port.h" -#include "dsymbol.h" - -class Expression; -class Condition; -class StaticForeach; - -/**************************************************************/ - -class AttribDeclaration : public Dsymbol -{ -public: - Dsymbols *decl; // array of Dsymbol's - - virtual Dsymbols *include(Scope *sc); - int apply(Dsymbol_apply_ft_t fp, void *param); - virtual Scope *newScope(Scope *sc); - void addMember(Scope *sc, ScopeDsymbol *sds); - void setScope(Scope *sc); - void importAll(Scope *sc); - void addComment(const utf8_t *comment); - const char *kind() const; - bool oneMember(Dsymbol **ps, Identifier *ident); - void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion); - bool hasPointers(); - bool hasStaticCtorOrDtor(); - void checkCtorConstInit(); - void addLocalClass(ClassDeclarations *); - AttribDeclaration *isAttribDeclaration() { return this; } - - void accept(Visitor *v) { v->visit(this); } -}; - -class StorageClassDeclaration : public AttribDeclaration -{ -public: - StorageClass stc; - - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - bool oneMember(Dsymbol **ps, Identifier *ident); - void addMember(Scope *sc, ScopeDsymbol *sds); - StorageClassDeclaration *isStorageClassDeclaration() { return this; } - - void accept(Visitor *v) { v->visit(this); } -}; - -class DeprecatedDeclaration : public StorageClassDeclaration -{ -public: - Expression *msg; - const char *msgstr; - - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - void setScope(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class LinkDeclaration : public AttribDeclaration -{ -public: - LINK linkage; - - static LinkDeclaration *create(LINK p, Dsymbols *decl); - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - const char *toChars(); - void accept(Visitor *v) { v->visit(this); } -}; - -class CPPMangleDeclaration : public AttribDeclaration -{ -public: - CPPMANGLE cppmangle; - - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - const char *toChars(); - void accept(Visitor *v) { v->visit(this); } -}; - -class ProtDeclaration : public AttribDeclaration -{ -public: - Prot protection; - Identifiers* pkg_identifiers; - - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - void addMember(Scope *sc, ScopeDsymbol *sds); - const char *kind() const; - const char *toPrettyChars(bool unused); - ProtDeclaration *isProtDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class AlignDeclaration : public AttribDeclaration -{ -public: - Expression *ealign; - structalign_t salign; - - AlignDeclaration(const Loc &loc, Expression *ealign, Dsymbols *decl); - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class AnonDeclaration : public AttribDeclaration -{ -public: - bool isunion; - int sem; // 1 if successful semantic() - unsigned anonoffset; // offset of anonymous struct - unsigned anonstructsize; // size of anonymous struct - unsigned anonalignsize; // size of anonymous struct for alignment purposes - - Dsymbol *syntaxCopy(Dsymbol *s); - void setScope(Scope *sc); - void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion); - const char *kind() const; - AnonDeclaration *isAnonDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class PragmaDeclaration : public AttribDeclaration -{ -public: - Expressions *args; // array of Expression's - - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - const char *kind() const; - void accept(Visitor *v) { v->visit(this); } -}; - -class ConditionalDeclaration : public AttribDeclaration -{ -public: - Condition *condition; - Dsymbols *elsedecl; // array of Dsymbol's for else block - - Dsymbol *syntaxCopy(Dsymbol *s); - bool oneMember(Dsymbol **ps, Identifier *ident); - Dsymbols *include(Scope *sc); - void addComment(const utf8_t *comment); - void setScope(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class StaticIfDeclaration : public ConditionalDeclaration -{ -public: - ScopeDsymbol *scopesym; - bool addisdone; - bool onStack; - - Dsymbol *syntaxCopy(Dsymbol *s); - Dsymbols *include(Scope *sc); - void addMember(Scope *sc, ScopeDsymbol *sds); - void setScope(Scope *sc); - void importAll(Scope *sc); - const char *kind() const; - void accept(Visitor *v) { v->visit(this); } -}; - -class StaticForeachDeclaration : public ConditionalDeclaration -{ -public: - StaticForeach *sfe; - ScopeDsymbol *scopesym; - bool cached; - Dsymbols *cache; - - Dsymbol *syntaxCopy(Dsymbol *s); - bool oneMember(Dsymbol **ps, Identifier *ident); - Dsymbols *include(Scope *sc); - void addMember(Scope *sc, ScopeDsymbol *sds); - void addComment(const utf8_t *comment); - void setScope(Scope *sc); - void importAll(Scope *sc); - const char *kind() const; - void accept(Visitor *v) { v->visit(this); } -}; - -class ForwardingAttribDeclaration : AttribDeclaration -{ -public: - ForwardingScopeDsymbol *sym; - - Scope *newScope(Scope *sc); - void addMember(Scope *sc, ScopeDsymbol *sds); - ForwardingAttribDeclaration *isForwardingAttribDeclaration() { return this; } -}; - -// Mixin declarations - -class CompileDeclaration : public AttribDeclaration -{ -public: - Expressions *exps; - - ScopeDsymbol *scopesym; - bool compiled; - - Dsymbol *syntaxCopy(Dsymbol *s); - void addMember(Scope *sc, ScopeDsymbol *sds); - void setScope(Scope *sc); - const char *kind() const; - void accept(Visitor *v) { v->visit(this); } -}; - -/** - * User defined attributes look like: - * @(args, ...) - */ -class UserAttributeDeclaration : public AttribDeclaration -{ -public: - Expressions *atts; - - Dsymbol *syntaxCopy(Dsymbol *s); - Scope *newScope(Scope *sc); - void setScope(Scope *sc); - Expressions *getAttributes(); - const char *kind() const; - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/cond.h b/src/dmd/cond.h deleted file mode 100644 index 024a9b64714d..000000000000 --- a/src/dmd/cond.h +++ /dev/null @@ -1,94 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/cond.h - */ - -#pragma once - -#include "globals.h" -#include "visitor.h" - -class Expression; -class Identifier; -class Module; -struct Scope; -class DebugCondition; -class ForeachStatement; -class ForeachRangeStatement; - -int findCondition(Strings *ids, Identifier *ident); - -class Condition -{ -public: - Loc loc; - // 0: not computed yet - // 1: include - // 2: do not include - int inc; - - virtual Condition *syntaxCopy() = 0; - virtual int include(Scope *sc) = 0; - virtual DebugCondition *isDebugCondition() { return NULL; } - virtual void accept(Visitor *v) { v->visit(this); } -}; - -class StaticForeach -{ -public: - Loc loc; - - ForeachStatement *aggrfe; - ForeachRangeStatement *rangefe; - - bool needExpansion; - - StaticForeach *syntaxCopy(); -}; - -class DVCondition : public Condition -{ -public: - unsigned level; - Identifier *ident; - Module *mod; - - Condition *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -class DebugCondition : public DVCondition -{ -public: - static void addGlobalIdent(const char *ident); - - int include(Scope *sc); - DebugCondition *isDebugCondition() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class VersionCondition : public DVCondition -{ -public: - static void addGlobalIdent(const char *ident); - static void addPredefinedGlobalIdent(const char *ident); - - int include(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class StaticIfCondition : public Condition -{ -public: - Expression *exp; - int nest; // limit circular dependencies - - Condition *syntaxCopy(); - int include(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/ctfe.h b/src/dmd/ctfe.h deleted file mode 100644 index ed1947c75d15..000000000000 --- a/src/dmd/ctfe.h +++ /dev/null @@ -1,66 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/ctfe.h - */ - -#pragma once - -#include "tokens.h" -#include "expression.h" - -/** - A reference to a class, or an interface. We need this when we - point to a base class (we must record what the type is). - */ -class ClassReferenceExp : public Expression -{ -public: - StructLiteralExp *value; - ClassDeclaration *originalClass(); - - /// Return index of the field, or -1 if not found - /// Same as getFieldIndex, but checks for a direct match with the VarDeclaration - int findFieldIndexByName(VarDeclaration *v); - void accept(Visitor *v) { v->visit(this); } -}; - -/** - An uninitialized value - */ -class VoidInitExp : public Expression -{ -public: - VarDeclaration *var; - - const char *toChars(); - void accept(Visitor *v) { v->visit(this); } -}; - -/** - Fake class which holds the thrown exception. - Used for implementing exception handling. -*/ -class ThrownExceptionExp : public Expression -{ -public: - ClassReferenceExp *thrown; // the thing being tossed - const char *toChars(); - /// Generate an error message when this exception is not caught - void generateUncaughtError(); - void accept(Visitor *v) { v->visit(this); } -}; - -/****************************************************************/ - -// This type is only used by the interpreter. - -class CTFEExp : public Expression -{ -public: - const char *toChars(); -}; diff --git a/src/dmd/declaration.h b/src/dmd/declaration.h deleted file mode 100644 index b9934c5359c4..000000000000 --- a/src/dmd/declaration.h +++ /dev/null @@ -1,800 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/declaration.h - */ - -#pragma once - -#include "dsymbol.h" -#include "mtype.h" -#include "tokens.h" - -class Expression; -class Statement; -class LabelDsymbol; -class Initializer; -class ForeachStatement; -struct Ensure -{ - Identifier *id; - Statement *ensure; -}; -class FuncDeclaration; -class StructDeclaration; -struct CompiledCtfeFunction; -struct ObjcSelector; -struct IntRange; - -#define STCundefined 0LL -#define STCstatic 1LL -#define STCextern 2LL -#define STCconst 4LL -#define STCfinal 8LL -#define STCabstract 0x10LL -#define STCparameter 0x20LL -#define STCfield 0x40LL -#define STCoverride 0x80LL -#define STCauto 0x100LL -#define STCsynchronized 0x200LL -#define STCdeprecated 0x400LL -#define STCin 0x800LL // in parameter -#define STCout 0x1000LL // out parameter -#define STClazy 0x2000LL // lazy parameter -#define STCforeach 0x4000LL // variable for foreach loop -#define STCvariadic 0x10000LL // the 'variadic' parameter in: T foo(T a, U b, V variadic...) -#define STCctorinit 0x20000LL // can only be set inside constructor -#define STCtemplateparameter 0x40000LL // template parameter -#define STCscope 0x80000LL -#define STCimmutable 0x100000LL -#define STCref 0x200000LL -#define STCinit 0x400000LL // has explicit initializer -#define STCmanifest 0x800000LL // manifest constant -#define STCnodtor 0x1000000LL // don't run destructor -#define STCnothrow 0x2000000LL // never throws exceptions -#define STCpure 0x4000000LL // pure function -#define STCtls 0x8000000LL // thread local -#define STCalias 0x10000000LL // alias parameter -#define STCshared 0x20000000LL // accessible from multiple threads -// accessible from multiple threads -// but not typed as "shared" -#define STCgshared 0x40000000LL -#define STCwild 0x80000000LL // for "wild" type constructor -#define STC_TYPECTOR (STCconst | STCimmutable | STCshared | STCwild) -#define STC_FUNCATTR (STCref | STCnothrow | STCnogc | STCpure | STCproperty | STCsafe | STCtrusted | STCsystem) - -#define STCproperty 0x100000000LL -#define STCsafe 0x200000000LL -#define STCtrusted 0x400000000LL -#define STCsystem 0x800000000LL -#define STCctfe 0x1000000000LL // can be used in CTFE, even if it is static -#define STCdisable 0x2000000000LL // for functions that are not callable -#define STCresult 0x4000000000LL // for result variables passed to out contracts -#define STCnodefaultctor 0x8000000000LL // must be set inside constructor -#define STCtemp 0x10000000000LL // temporary variable -#define STCrvalue 0x20000000000LL // force rvalue for variables -#define STCnogc 0x40000000000LL // @nogc -#define STCvolatile 0x80000000000LL // destined for volatile in the back end -#define STCreturn 0x100000000000LL // 'return ref' or 'return scope' for function parameters -#define STCautoref 0x200000000000LL // Mark for the already deduced 'auto ref' parameter -#define STCinference 0x400000000000LL // do attribute inference -#define STCexptemp 0x800000000000LL // temporary variable that has lifetime restricted to an expression -#define STCmaybescope 0x1000000000000LL // parameter might be 'scope' -#define STCscopeinferred 0x2000000000000LL // 'scope' has been inferred and should not be part of mangling -#define STCfuture 0x4000000000000LL // introducing new base class function -#define STClocal 0x8000000000000LL // do not forward (see dmd.dsymbol.ForwardingScopeDsymbol). - -void ObjectNotFound(Identifier *id); - -/**************************************************************/ - -class Declaration : public Dsymbol -{ -public: - Type *type; - Type *originalType; // before semantic analysis - StorageClass storage_class; - Prot protection; - LINK linkage; - int inuse; // used to detect cycles - DArray mangleOverride; // overridden symbol with pragma(mangle, "...") - - const char *kind() const; - d_uns64 size(const Loc &loc); - - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - - bool isStatic() const { return (storage_class & STCstatic) != 0; } - virtual bool isDelete(); - virtual bool isDataseg(); - virtual bool isThreadlocal(); - virtual bool isCodeseg() const; - bool isCtorinit() const { return (storage_class & STCctorinit) != 0; } - bool isFinal() const { return (storage_class & STCfinal) != 0; } - virtual bool isAbstract() { return (storage_class & STCabstract) != 0; } - bool isConst() const { return (storage_class & STCconst) != 0; } - bool isImmutable() const { return (storage_class & STCimmutable) != 0; } - bool isWild() const { return (storage_class & STCwild) != 0; } - bool isAuto() const { return (storage_class & STCauto) != 0; } - bool isScope() const { return (storage_class & STCscope) != 0; } - bool isSynchronized() const { return (storage_class & STCsynchronized) != 0; } - bool isParameter() const { return (storage_class & STCparameter) != 0; } - bool isDeprecated() { return (storage_class & STCdeprecated) != 0; } - bool isOverride() const { return (storage_class & STCoverride) != 0; } - bool isResult() const { return (storage_class & STCresult) != 0; } - bool isField() const { return (storage_class & STCfield) != 0; } - - bool isIn() const { return (storage_class & STCin) != 0; } - bool isOut() const { return (storage_class & STCout) != 0; } - bool isRef() const { return (storage_class & STCref) != 0; } - - bool isFuture() const { return (storage_class & STCfuture) != 0; } - - Prot prot(); - - Declaration *isDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -/**************************************************************/ - -class TupleDeclaration : public Declaration -{ -public: - Objects *objects; - bool isexp; // true: expression tuple - - TypeTuple *tupletype; // !=NULL if this is a type tuple - - Dsymbol *syntaxCopy(Dsymbol *); - const char *kind() const; - Type *getType(); - Dsymbol *toAlias2(); - bool needThis(); - - TupleDeclaration *isTupleDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -/**************************************************************/ - -class AliasDeclaration : public Declaration -{ -public: - Dsymbol *aliassym; - Dsymbol *overnext; // next in overload list - Dsymbol *_import; // !=NULL if unresolved internal alias for selective import - - static AliasDeclaration *create(Loc loc, Identifier *id, Type *type); - Dsymbol *syntaxCopy(Dsymbol *); - bool overloadInsert(Dsymbol *s); - const char *kind() const; - Type *getType(); - Dsymbol *toAlias(); - Dsymbol *toAlias2(); - bool isOverloadable(); - - AliasDeclaration *isAliasDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -/**************************************************************/ - -class OverDeclaration : public Declaration -{ -public: - Dsymbol *overnext; // next in overload list - Dsymbol *aliassym; - bool hasOverloads; - - const char *kind() const; - bool equals(RootObject *o); - bool overloadInsert(Dsymbol *s); - - Dsymbol *toAlias(); - Dsymbol *isUnique(); - bool isOverloadable(); - - OverDeclaration *isOverDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -/**************************************************************/ - -class VarDeclaration : public Declaration -{ -public: - Initializer *_init; - unsigned offset; - unsigned sequenceNumber; // order the variables are declared - FuncDeclarations nestedrefs; // referenced by these lexically nested functions - structalign_t alignment; - bool isargptr; // if parameter that _argptr points to - bool ctorinit; // it has been initialized in a ctor - bool iscatchvar; // this is the exception object variable in catch() clause - bool onstack; // it is a class that was allocated on the stack - bool mynew; // it is a class new'd with custom operator new - int canassign; // it can be assigned to - bool overlapped; // if it is a field and has overlapping - bool overlapUnsafe; // if it is an overlapping field and the overlaps are unsafe - bool doNotInferScope; // do not infer 'scope' for this variable - unsigned char isdataseg; // private data for isDataseg - Dsymbol *aliassym; // if redone as alias to another symbol - VarDeclaration *lastVar; // Linked list of variables for goto-skips-init detection - unsigned endlinnum; // line number of end of scope that this var lives in - - // When interpreting, these point to the value (NULL if value not determinable) - // The index of this variable on the CTFE stack, -1 if not allocated - int ctfeAdrOnStack; - Expression *edtor; // if !=NULL, does the destruction of the variable - IntRange *range; // if !NULL, the variable is known to be within the range - - VarDeclarations *maybes; // STCmaybescope variables that are assigned to this STCmaybescope variable - - Dsymbol *syntaxCopy(Dsymbol *); - void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion); - const char *kind() const; - AggregateDeclaration *isThis(); - bool needThis(); - bool isExport() const; - bool isImportedSymbol() const; - bool isDataseg(); - bool isThreadlocal(); - bool isCTFE(); - bool isOverlappedWith(VarDeclaration *v); - bool hasPointers(); - bool canTakeAddressOf(); - bool needsScopeDtor(); - bool enclosesLifetimeOf(VarDeclaration *v) const; - Expression *callScopeDtor(Scope *sc); - Expression *getConstInitializer(bool needFullType = true); - Expression *expandInitializer(Loc loc); - void checkCtorConstInit(); - Dsymbol *toAlias(); - // Eliminate need for dynamic_cast - VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; } - void accept(Visitor *v) { v->visit(this); } -}; - -/**************************************************************/ - -// This is a shell around a back end symbol - -class SymbolDeclaration : public Declaration -{ -public: - StructDeclaration *dsym; - - // Eliminate need for dynamic_cast - SymbolDeclaration *isSymbolDeclaration() { return (SymbolDeclaration *)this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoDeclaration : public VarDeclaration -{ -public: - Type *tinfo; - - static TypeInfoDeclaration *create(Type *tinfo); - Dsymbol *syntaxCopy(Dsymbol *); - const char *toChars(); - - TypeInfoDeclaration *isTypeInfoDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoStructDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoStructDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoClassDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoClassDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoInterfaceDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoInterfaceDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoPointerDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoPointerDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoArrayDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoArrayDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoStaticArrayDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoStaticArrayDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoAssociativeArrayDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoAssociativeArrayDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoEnumDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoEnumDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoFunctionDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoFunctionDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoDelegateDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoDelegateDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoTupleDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoTupleDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoConstDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoConstDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoInvariantDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoInvariantDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoSharedDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoSharedDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoWildDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoWildDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeInfoVectorDeclaration : public TypeInfoDeclaration -{ -public: - static TypeInfoVectorDeclaration *create(Type *tinfo); - - void accept(Visitor *v) { v->visit(this); } -}; - -/**************************************************************/ - -class ThisDeclaration : public VarDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *); - ThisDeclaration *isThisDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -enum ILS -{ - ILSuninitialized, // not computed yet - ILSno, // cannot inline - ILSyes // can inline -}; - -/**************************************************************/ - -enum BUILTIN -{ - BUILTINunknown = -1, // not known if this is a builtin - BUILTINno, // this is not a builtin - BUILTINyes // this is a builtin -}; - -Expression *eval_builtin(Loc loc, FuncDeclaration *fd, Expressions *arguments); -BUILTIN isBuiltin(FuncDeclaration *fd); - -typedef Expression *(*builtin_fp)(Loc loc, FuncDeclaration *fd, Expressions *arguments); -void add_builtin(const char *mangle, builtin_fp fp); -void builtin_init(); - -class FuncDeclaration : public Declaration -{ -public: - Types *fthrows; // Array of Type's of exceptions (not used) - Statements *frequires; // in contracts - Ensures *fensures; // out contracts - Statement *frequire; // lowered in contract - Statement *fensure; // lowered out contract - Statement *fbody; - - FuncDeclarations foverrides; // functions this function overrides - FuncDeclaration *fdrequire; // function that does the in contract - FuncDeclaration *fdensure; // function that does the out contract - - const char *mangleString; // mangled symbol created from mangleExact() - - VarDeclaration *vresult; // result variable for out contracts - LabelDsymbol *returnLabel; // where the return goes - - // used to prevent symbols in different - // scopes from having the same name - DsymbolTable *localsymtab; - VarDeclaration *vthis; // 'this' parameter (member and nested) - VarDeclaration *v_arguments; // '_arguments' parameter - ObjcSelector* selector; // Objective-C method selector (member function only) - VarDeclaration *v_argptr; // '_argptr' variable - VarDeclarations *parameters; // Array of VarDeclaration's for parameters - DsymbolTable *labtab; // statement label symbol table - Dsymbol *overnext; // next in overload list - FuncDeclaration *overnext0; // next in overload list (only used during IFTI) - Loc endloc; // location of closing curly bracket - int vtblIndex; // for member functions, index into vtbl[] - bool naked; // true if naked - bool generated; // true if function was generated by the compiler rather than - // supplied by the user - ILS inlineStatusStmt; - ILS inlineStatusExp; - PINLINE inlining; - - CompiledCtfeFunction *ctfeCode; // Compiled code for interpreter - int inlineNest; // !=0 if nested inline - bool isArrayOp; // true if array operation - bool eh_none; /// true if no exception unwinding is needed - - // true if errors in semantic3 this function's frame ptr - bool semantic3Errors; - ForeachStatement *fes; // if foreach body, this is the foreach - BaseClass* interfaceVirtual; // if virtual, but only appears in interface vtbl[] - bool introducing; // true if 'introducing' function - // if !=NULL, then this is the type - // of the 'introducing' function - // this one is overriding - Type *tintro; - bool inferRetType; // true if return type is to be inferred - StorageClass storage_class2; // storage class for template onemember's - - // Things that should really go into Scope - - // 1 if there's a return exp; statement - // 2 if there's a throw statement - // 4 if there's an assert(0) - // 8 if there's inline asm - // 16 if there are multiple return statements - int hasReturnExp; - - // Support for NRVO (named return value optimization) - bool nrvo_can; // true means we can do it - VarDeclaration *nrvo_var; // variable to replace with shidden - Symbol *shidden; // hidden pointer passed to function - - ReturnStatements *returns; - - GotoStatements *gotos; // Gotos with forward references - - // set if this is a known, builtin function we can evaluate at compile time - BUILTIN builtin; - - // set if someone took the address of this function - int tookAddressOf; - bool requiresClosure; // this function needs a closure - - // local variables in this function which are referenced by nested functions - VarDeclarations closureVars; - // Sibling nested functions which called this one - FuncDeclarations siblingCallers; - - FuncDeclarations *inlinedNestedCallees; - - unsigned flags; // FUNCFLAGxxxxx - - static FuncDeclaration *create(const Loc &loc, const Loc &endloc, Identifier *id, StorageClass storage_class, Type *type); - Dsymbol *syntaxCopy(Dsymbol *); - bool functionSemantic(); - bool functionSemantic3(); - // called from semantic3 - VarDeclaration *declareThis(Scope *sc, AggregateDeclaration *ad); - bool equals(RootObject *o); - - int overrides(FuncDeclaration *fd); - int findVtblIndex(Dsymbols *vtbl, int dim, bool fix17349 = true); - BaseClass *overrideInterface(); - bool overloadInsert(Dsymbol *s); - FuncDeclaration *overloadExactMatch(Type *t); - FuncDeclaration *overloadModMatch(const Loc &loc, Type *tthis, bool &hasOverloads); - TemplateDeclaration *findTemplateDeclRoot(); - bool inUnittest(); - MATCH leastAsSpecialized(FuncDeclaration *g); - LabelDsymbol *searchLabel(Identifier *ident); - int getLevel(const Loc &loc, Scope *sc, FuncDeclaration *fd); // lexical nesting level difference - const char *toPrettyChars(bool QualifyTypes = false); - const char *toFullSignature(); // for diagnostics, e.g. 'int foo(int x, int y) pure' - bool isMain() const; - bool isCMain() const; - bool isWinMain() const; - bool isDllMain() const; - bool isExport() const; - bool isImportedSymbol() const; - bool isCodeseg() const; - bool isOverloadable(); - bool isAbstract(); - PURE isPure(); - PURE isPureBypassingInference(); - bool setImpure(); - bool isSafe(); - bool isSafeBypassingInference(); - bool isTrusted(); - bool setUnsafe(); - - bool isNogc(); - bool isNogcBypassingInference(); - bool setGC(); - - void printGCUsage(const Loc &loc, const char *warn); - bool isolateReturn(); - bool parametersIntersect(Type *t); - virtual bool isNested(); - AggregateDeclaration *isThis(); - bool needThis(); - bool isVirtualMethod(); - virtual bool isVirtual() const; - bool isFinalFunc() const; - virtual bool addPreInvariant(); - virtual bool addPostInvariant(); - const char *kind() const; - FuncDeclaration *isUnique(); - bool needsClosure(); - bool hasNestedFrameRefs(); - void buildResultVar(Scope *sc, Type *tret); - Statement *mergeFrequire(Statement *); - Statement *mergeFensure(Statement *, Identifier *oid); - Parameters *getParameters(int *pvarargs); - - static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, const char *name, StorageClass stc=0); - static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, Identifier *id, StorageClass stc=0); - - FuncDeclaration *isFuncDeclaration() { return this; } - - virtual FuncDeclaration *toAliasFunc() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class FuncAliasDeclaration : public FuncDeclaration -{ -public: - FuncDeclaration *funcalias; - bool hasOverloads; - - FuncAliasDeclaration *isFuncAliasDeclaration() { return this; } - const char *kind() const; - - FuncDeclaration *toAliasFunc(); - void accept(Visitor *v) { v->visit(this); } -}; - -class FuncLiteralDeclaration : public FuncDeclaration -{ -public: - TOK tok; // TOKfunction or TOKdelegate - Type *treq; // target of return type inference - - // backend - bool deferToObj; - - Dsymbol *syntaxCopy(Dsymbol *); - bool isNested(); - AggregateDeclaration *isThis(); - bool isVirtual() const; - bool addPreInvariant(); - bool addPostInvariant(); - - void modifyReturns(Scope *sc, Type *tret); - - FuncLiteralDeclaration *isFuncLiteralDeclaration() { return this; } - const char *kind() const; - const char *toPrettyChars(bool QualifyTypes = false); - void accept(Visitor *v) { v->visit(this); } -}; - -class CtorDeclaration : public FuncDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *); - const char *kind() const; - const char *toChars(); - bool isVirtual() const; - bool addPreInvariant(); - bool addPostInvariant(); - - CtorDeclaration *isCtorDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class PostBlitDeclaration : public FuncDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *); - bool isVirtual() const; - bool addPreInvariant(); - bool addPostInvariant(); - bool overloadInsert(Dsymbol *s); - - PostBlitDeclaration *isPostBlitDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class DtorDeclaration : public FuncDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *); - const char *kind() const; - const char *toChars(); - bool isVirtual() const; - bool addPreInvariant(); - bool addPostInvariant(); - bool overloadInsert(Dsymbol *s); - - DtorDeclaration *isDtorDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class StaticCtorDeclaration : public FuncDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *); - AggregateDeclaration *isThis(); - bool isVirtual() const; - bool addPreInvariant(); - bool addPostInvariant(); - bool hasStaticCtorOrDtor(); - - StaticCtorDeclaration *isStaticCtorDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class SharedStaticCtorDeclaration : public StaticCtorDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *); - - SharedStaticCtorDeclaration *isSharedStaticCtorDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class StaticDtorDeclaration : public FuncDeclaration -{ -public: - VarDeclaration *vgate; // 'gate' variable - - Dsymbol *syntaxCopy(Dsymbol *); - AggregateDeclaration *isThis(); - bool isVirtual() const; - bool hasStaticCtorOrDtor(); - bool addPreInvariant(); - bool addPostInvariant(); - - StaticDtorDeclaration *isStaticDtorDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class SharedStaticDtorDeclaration : public StaticDtorDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *); - - SharedStaticDtorDeclaration *isSharedStaticDtorDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class InvariantDeclaration : public FuncDeclaration -{ -public: - Dsymbol *syntaxCopy(Dsymbol *); - bool isVirtual() const; - bool addPreInvariant(); - bool addPostInvariant(); - - InvariantDeclaration *isInvariantDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class UnitTestDeclaration : public FuncDeclaration -{ -public: - char *codedoc; /** For documented unittest. */ - - // toObjFile() these nested functions after this one - FuncDeclarations deferredNested; - - Dsymbol *syntaxCopy(Dsymbol *); - AggregateDeclaration *isThis(); - bool isVirtual() const; - bool addPreInvariant(); - bool addPostInvariant(); - - UnitTestDeclaration *isUnitTestDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class NewDeclaration : public FuncDeclaration -{ -public: - Parameters *parameters; - int varargs; - - Dsymbol *syntaxCopy(Dsymbol *); - const char *kind() const; - bool isVirtual() const; - bool addPreInvariant(); - bool addPostInvariant(); - - NewDeclaration *isNewDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - - -class DeleteDeclaration : public FuncDeclaration -{ -public: - Parameters *parameters; - - Dsymbol *syntaxCopy(Dsymbol *); - const char *kind() const; - bool isDelete(); - bool isVirtual() const; - bool addPreInvariant(); - bool addPostInvariant(); - - DeleteDeclaration *isDeleteDeclaration() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/dsymbol.h b/src/dmd/dsymbol.h deleted file mode 100644 index 6504ce14ce1b..000000000000 --- a/src/dmd/dsymbol.h +++ /dev/null @@ -1,388 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/dsymbol.h - */ - -#pragma once - -#include "root/port.h" -#include "globals.h" -#include "arraytypes.h" -#include "visitor.h" - -class Identifier; -struct Scope; -class DsymbolTable; -class Declaration; -class ThisDeclaration; -class TypeInfoDeclaration; -class TupleDeclaration; -class AliasDeclaration; -class AggregateDeclaration; -class EnumDeclaration; -class ClassDeclaration; -class InterfaceDeclaration; -class StructDeclaration; -class UnionDeclaration; -class FuncDeclaration; -class FuncAliasDeclaration; -class OverDeclaration; -class FuncLiteralDeclaration; -class CtorDeclaration; -class PostBlitDeclaration; -class DtorDeclaration; -class StaticCtorDeclaration; -class StaticDtorDeclaration; -class SharedStaticCtorDeclaration; -class SharedStaticDtorDeclaration; -class InvariantDeclaration; -class UnitTestDeclaration; -class NewDeclaration; -class VarDeclaration; -class AttribDeclaration; -class ProtDeclaration; -class Package; -class Module; -class Import; -class Type; -class TypeTuple; -class WithStatement; -class LabelDsymbol; -class ScopeDsymbol; -class ForwardingScopeDsymbol; -class TemplateDeclaration; -class TemplateInstance; -class TemplateMixin; -class ForwardingAttribDeclaration; -class Nspace; -class EnumMember; -class WithScopeSymbol; -class ArrayScopeSymbol; -class SymbolDeclaration; -class Expression; -class ExpressionDsymbol; -class DeleteDeclaration; -class OverloadSet; -struct AA; -#ifdef IN_GCC -typedef union tree_node Symbol; -#else -struct Symbol; -#endif - -struct Ungag -{ - unsigned oldgag; - - Ungag(unsigned old) : oldgag(old) {} - ~Ungag() { global.gag = oldgag; } -}; - -void dsymbolSemantic(Dsymbol *dsym, Scope *sc); -void semantic2(Dsymbol *dsym, Scope *sc); -void semantic3(Dsymbol *dsym, Scope* sc); - -struct Prot -{ - enum Kind - { - undefined, - none, // no access - private_, - package_, - protected_, - public_, - export_ - }; - Kind kind; - Package *pkg; - - bool isMoreRestrictiveThan(const Prot other) const; - bool isSubsetOf(const Prot& other) const; -}; - -/* State of symbol in winding its way through the passes of the compiler - */ -enum PASS -{ - PASSinit, // initial state - PASSsemantic, // semantic() started - PASSsemanticdone, // semantic() done - PASSsemantic2, // semantic2() started - PASSsemantic2done, // semantic2() done - PASSsemantic3, // semantic3() started - PASSsemantic3done, // semantic3() done - PASSinline, // inline started - PASSinlinedone, // inline done - PASSobj // toObjFile() run -}; - -/* Flags for symbol search - */ -enum -{ - IgnoreNone = 0x00, // default - IgnorePrivateImports = 0x01, // don't search private imports - IgnoreErrors = 0x02, // don't give error messages - IgnoreAmbiguous = 0x04, // return NULL if ambiguous - SearchLocalsOnly = 0x08, // only look at locals (don't search imports) - SearchImportsOnly = 0x10, // only look in imports - SearchUnqualifiedModule = 0x20, // the module scope search is unqualified, - // meaning don't search imports in that scope, - // because qualified module searches search - // their imports - IgnoreSymbolVisibility = 0x80 // also find private and package protected symbols -}; - -typedef int (*Dsymbol_apply_ft_t)(Dsymbol *, void *); - -class Dsymbol : public RootObject -{ -public: - Identifier *ident; - Dsymbol *parent; - Symbol *csym; // symbol for code generator - Symbol *isym; // import version of csym - const utf8_t *comment; // documentation comment for this Dsymbol - Loc loc; // where defined - Scope *_scope; // !=NULL means context to use for semantic() - const utf8_t *prettystring; - bool errors; // this symbol failed to pass semantic() - PASS semanticRun; - DeprecatedDeclaration *depdecl; // customized deprecation message - UserAttributeDeclaration *userAttribDecl; // user defined attributes - UnitTestDeclaration *ddocUnittest; // !=NULL means there's a ddoc unittest associated with this symbol (only use this with ddoc) - - static Dsymbol *create(Identifier *); - const char *toChars(); - virtual const char *toPrettyCharsHelper(); // helper to print fully qualified (template) arguments - Loc& getLoc(); - const char *locToChars(); - bool equals(RootObject *o); - virtual bool isAnonymous(); - void error(Loc loc, const char *format, ...); - void error(const char *format, ...); - void deprecation(const Loc &loc, const char *format, ...); - void deprecation(const char *format, ...); - bool checkDeprecated(const Loc &loc, Scope *sc); - Module *getModule(); - Module *getAccessModule(); - Dsymbol *pastMixin(); - Dsymbol *toParent(); - Dsymbol *toParent2(); - TemplateInstance *isInstantiated(); - TemplateInstance *isSpeculative(); - Ungag ungagSpeculative(); - - // kludge for template.isSymbol() - int dyncast() const { return DYNCAST_DSYMBOL; } - - virtual Identifier *getIdent(); - virtual const char *toPrettyChars(bool QualifyTypes = false); - virtual const char *kind() const; - virtual Dsymbol *toAlias(); // resolve real symbol - virtual Dsymbol *toAlias2(); - virtual int apply(Dsymbol_apply_ft_t fp, void *param); - virtual void addMember(Scope *sc, ScopeDsymbol *sds); - virtual void setScope(Scope *sc); - virtual void importAll(Scope *sc); - virtual Dsymbol *search(const Loc &loc, Identifier *ident, int flags = IgnoreNone); - Dsymbol *search_correct(Identifier *id); - Dsymbol *searchX(const Loc &loc, Scope *sc, RootObject *id); - virtual bool overloadInsert(Dsymbol *s); - virtual d_uns64 size(const Loc &loc); - virtual bool isforwardRef(); - virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member - virtual bool isExport() const; // is Dsymbol exported? - virtual bool isImportedSymbol() const; // is Dsymbol imported? - virtual bool isDeprecated(); // is Dsymbol deprecated? - virtual bool isOverloadable(); - virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol? - AggregateDeclaration *isMember(); // is this a member of an AggregateDeclaration? - AggregateDeclaration *isMember2(); // is this a member of an AggregateDeclaration? - ClassDeclaration *isClassMember(); // is this a member of a ClassDeclaration? - virtual Type *getType(); // is this a type? - virtual bool needThis(); // need a 'this' pointer? - virtual Prot prot(); - virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees - virtual bool oneMember(Dsymbol **ps, Identifier *ident); - virtual void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion); - virtual bool hasPointers(); - virtual bool hasStaticCtorOrDtor(); - virtual void addLocalClass(ClassDeclarations *) { } - virtual void checkCtorConstInit() { } - - virtual void addComment(const utf8_t *comment); - - bool inNonRoot(); - - // Eliminate need for dynamic_cast - virtual Package *isPackage() { return NULL; } - virtual Module *isModule() { return NULL; } - virtual EnumMember *isEnumMember() { return NULL; } - virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; } - virtual TemplateInstance *isTemplateInstance() { return NULL; } - virtual TemplateMixin *isTemplateMixin() { return NULL; } - virtual ForwardingAttribDeclaration *isForwardingAttribDeclaration() { return NULL; } - virtual Nspace *isNspace() { return NULL; } - virtual Declaration *isDeclaration() { return NULL; } - virtual StorageClassDeclaration *isStorageClassDeclaration(){ return NULL; } - virtual ThisDeclaration *isThisDeclaration() { return NULL; } - virtual TypeInfoDeclaration *isTypeInfoDeclaration() { return NULL; } - virtual TupleDeclaration *isTupleDeclaration() { return NULL; } - virtual AliasDeclaration *isAliasDeclaration() { return NULL; } - virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; } - virtual FuncDeclaration *isFuncDeclaration() { return NULL; } - virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; } - virtual OverDeclaration *isOverDeclaration() { return NULL; } - virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; } - virtual CtorDeclaration *isCtorDeclaration() { return NULL; } - virtual PostBlitDeclaration *isPostBlitDeclaration() { return NULL; } - virtual DtorDeclaration *isDtorDeclaration() { return NULL; } - virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; } - virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; } - virtual SharedStaticCtorDeclaration *isSharedStaticCtorDeclaration() { return NULL; } - virtual SharedStaticDtorDeclaration *isSharedStaticDtorDeclaration() { return NULL; } - virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; } - virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; } - virtual NewDeclaration *isNewDeclaration() { return NULL; } - virtual ExpressionDsymbol *isExpressionDsymbol() { return NULL; } - virtual VarDeclaration *isVarDeclaration() { return NULL; } - virtual ClassDeclaration *isClassDeclaration() { return NULL; } - virtual StructDeclaration *isStructDeclaration() { return NULL; } - virtual UnionDeclaration *isUnionDeclaration() { return NULL; } - virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; } - virtual ScopeDsymbol *isScopeDsymbol() { return NULL; } - virtual ForwardingScopeDsymbol *isForwardingScopeDsymbol() { return NULL; } - virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; } - virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; } - virtual Import *isImport() { return NULL; } - virtual EnumDeclaration *isEnumDeclaration() { return NULL; } - virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; } - virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; } - virtual AttribDeclaration *isAttribDeclaration() { return NULL; } - virtual AnonDeclaration *isAnonDeclaration() { return NULL; } - virtual ProtDeclaration *isProtDeclaration() { return NULL; } - virtual OverloadSet *isOverloadSet() { return NULL; } - virtual void accept(Visitor *v) { v->visit(this); } -}; - -// Dsymbol that generates a scope - -class ScopeDsymbol : public Dsymbol -{ -public: - Dsymbols *members; // all Dsymbol's in this scope - DsymbolTable *symtab; // members[] sorted into table - unsigned endlinnum; // the linnumber of the statement after the scope (0 if unknown) - -private: - Dsymbols *importedScopes; // imported Dsymbol's - Prot::Kind *prots; // array of PROTKIND, one for each import - - BitArray accessiblePackages, privateAccessiblePackages; - -public: - Dsymbol *syntaxCopy(Dsymbol *s); - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - OverloadSet *mergeOverloadSet(Identifier *ident, OverloadSet *os, Dsymbol *s); - virtual void importScope(Dsymbol *s, Prot protection); - void addAccessiblePackage(Package *p, Prot protection); - virtual bool isPackageAccessible(Package *p, Prot protection, int flags = 0); - bool isforwardRef(); - static void multiplyDefined(const Loc &loc, Dsymbol *s1, Dsymbol *s2); - const char *kind() const; - FuncDeclaration *findGetMembers(); - virtual Dsymbol *symtabInsert(Dsymbol *s); - virtual Dsymbol *symtabLookup(Dsymbol *s, Identifier *id); - bool hasStaticCtorOrDtor(); - - ScopeDsymbol *isScopeDsymbol() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -// With statement scope - -class WithScopeSymbol : public ScopeDsymbol -{ -public: - WithStatement *withstate; - - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - - WithScopeSymbol *isWithScopeSymbol() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -// Array Index/Slice scope - -class ArrayScopeSymbol : public ScopeDsymbol -{ -public: - Expression *exp; // IndexExp or SliceExp - TypeTuple *type; // for tuple[length] - TupleDeclaration *td; // for tuples of objects - Scope *sc; - - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = IgnoreNone); - - ArrayScopeSymbol *isArrayScopeSymbol() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -// Overload Sets - -class OverloadSet : public Dsymbol -{ -public: - Dsymbols a; // array of Dsymbols - - void push(Dsymbol *s); - OverloadSet *isOverloadSet() { return this; } - const char *kind() const; - void accept(Visitor *v) { v->visit(this); } -}; - -// Forwarding ScopeDsymbol - -class ForwardingScopeDsymbol : public ScopeDsymbol -{ - ScopeDsymbol *forward; - - Dsymbol *symtabInsert(Dsymbol *s); - Dsymbol *symtabLookup(Dsymbol *s, Identifier *id); - void importScope(Dsymbol *s, Prot protection); - const char *kind() const; - - ForwardingScopeDsymbol *isForwardingScopeDsymbol() { return this; } -}; - -class ExpressionDsymbol : public Dsymbol -{ - Expression *exp; - - ExpressionDsymbol *isExpressionDsymbol() { return this; } -}; - -// Table of Dsymbol's - -class DsymbolTable : public RootObject -{ -public: - AA *tab; - - // Look up Identifier. Return Dsymbol if found, NULL if not. - Dsymbol *lookup(Identifier const * const ident); - - // Insert Dsymbol in table. Return NULL if already there. - Dsymbol *insert(Dsymbol *s); - - // Look for Dsymbol in table. If there, return it. If not, insert s and return that. - Dsymbol *update(Dsymbol *s); - Dsymbol *insert(Identifier const * const ident, Dsymbol *s); // when ident and s are not the same -}; diff --git a/src/dmd/enum.h b/src/dmd/enum.h deleted file mode 100644 index db4417d06e15..000000000000 --- a/src/dmd/enum.h +++ /dev/null @@ -1,88 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/enum.h - */ - -#pragma once - -#include "dsymbol.h" -#include "declaration.h" - -class Identifier; -class Type; -class Expression; - -class EnumDeclaration : public ScopeDsymbol -{ -public: - /* The separate, and distinct, cases are: - * 1. enum { ... } - * 2. enum : memtype { ... } - * 3. enum id { ... } - * 4. enum id : memtype { ... } - * 5. enum id : memtype; - * 6. enum id; - */ - Type *type; // the TypeEnum - Type *memtype; // type of the members - Prot protection; - - Expression *maxval; - Expression *minval; - Expression *defaultval; // default initializer - - bool isdeprecated; - bool added; - int inuse; - - Dsymbol *syntaxCopy(Dsymbol *s); - void addMember(Scope *sc, ScopeDsymbol *sds); - void setScope(Scope *sc); - bool oneMember(Dsymbol **ps, Identifier *ident); - Type *getType(); - const char *kind() const; - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - bool isDeprecated(); // is Dsymbol deprecated? - Prot prot(); - Expression *getMaxMinValue(const Loc &loc, Identifier *id); - bool isSpecial() const; - Expression *getDefaultValue(const Loc &loc); - Type *getMemtype(const Loc &loc); - - EnumDeclaration *isEnumDeclaration() { return this; } - - Symbol *sinit; - void accept(Visitor *v) { v->visit(this); } -}; - - -class EnumMember : public VarDeclaration -{ -public: - /* Can take the following forms: - * 1. id - * 2. id = value - * 3. type id = value - */ - Expression *&value(); - - // A cast() is injected to 'value' after semantic(), - // but 'origValue' will preserve the original value, - // or previous value + 1 if none was specified. - Expression *origValue; - Type *origType; - - EnumDeclaration *ed; - - Dsymbol *syntaxCopy(Dsymbol *s); - const char *kind() const; - Expression *getVarExp(const Loc &loc, Scope *sc); - - EnumMember *isEnumMember() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/expression.h b/src/dmd/expression.h deleted file mode 100644 index 83f2ceeca636..000000000000 --- a/src/dmd/expression.h +++ /dev/null @@ -1,1274 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/expression.h - */ - -#pragma once - -#include "complex_t.h" -#include "globals.h" -#include "arraytypes.h" -#include "visitor.h" -#include "tokens.h" - -#include "root/rmem.h" - -class Type; -class TypeVector; -struct Scope; -class TupleDeclaration; -class VarDeclaration; -class FuncDeclaration; -class FuncLiteralDeclaration; -class CtorDeclaration; -class NewDeclaration; -class Dsymbol; -class ScopeDsymbol; -class Expression; -class Declaration; -class StructDeclaration; -class TemplateInstance; -class TemplateDeclaration; -class ClassDeclaration; -class OverloadSet; -class StringExp; -struct UnionExp; -#ifdef IN_GCC -typedef union tree_node Symbol; -#else -struct Symbol; // back end symbol -#endif - -void expandTuples(Expressions *exps); -TupleDeclaration *isAliasThisTuple(Expression *e); -int expandAliasThisTuples(Expressions *exps, size_t starti = 0); -bool arrayExpressionSemantic(Expressions *exps, Scope *sc, bool preserveErrors = false); -TemplateDeclaration *getFuncTemplateDecl(Dsymbol *s); -bool isTrivialExp(Expression *e); - -Expression *toDelegate(Expression *e, Type* t, Scope *sc); -bool hasSideEffect(Expression *e); -bool canThrow(Expression *e, FuncDeclaration *func, bool mustNotThrow); - -enum OwnedBy -{ - OWNEDcode, // normal code expression in AST - OWNEDctfe, // value expression for CTFE - OWNEDcache // constant value cached for CTFE -}; - -class Expression : public RootObject -{ -public: - Loc loc; // file location - Type *type; // !=NULL means that semantic() has been run - TOK op; // to minimize use of dynamic_cast - unsigned char size; // # of bytes in Expression so we can copy() it - unsigned char parens; // if this is a parenthesized expression - - static void _init(); - Expression *copy(); - virtual Expression *syntaxCopy(); - - // kludge for template.isExpression() - int dyncast() const { return DYNCAST_EXPRESSION; } - - const char *toChars(); - void error(const char *format, ...) const; - void warning(const char *format, ...) const; - void deprecation(const char *format, ...) const; - - virtual dinteger_t toInteger(); - virtual uinteger_t toUInteger(); - virtual real_t toReal(); - virtual real_t toImaginary(); - virtual complex_t toComplex(); - virtual StringExp *toStringExp(); - virtual TupleExp *toTupleExp(); - virtual bool isLvalue(); - virtual Expression *toLvalue(Scope *sc, Expression *e); - virtual Expression *modifiableLvalue(Scope *sc, Expression *e); - Expression *implicitCastTo(Scope *sc, Type *t); - MATCH implicitConvTo(Type *t); - Expression *castTo(Scope *sc, Type *t); - virtual Expression *resolveLoc(const Loc &loc, Scope *sc); - virtual bool checkType(); - virtual bool checkValue(); - bool checkDeprecated(Scope *sc, Dsymbol *s); - virtual int checkModifiable(Scope *sc, int flag = 0); - virtual Expression *toBoolean(Scope *sc); - virtual Expression *addDtorHook(Scope *sc); - Expression *addressOf(); - Expression *deref(); - - Expression *optimize(int result, bool keepLvalue = false); - - // Entry point for CTFE. - // A compile-time result is required. Give an error if not possible - Expression *ctfeInterpret(); - int isConst(); - virtual bool isBool(bool result); - - virtual bool hasCode() - { - return true; - } - - virtual void accept(Visitor *v) { v->visit(this); } -}; - -class IntegerExp : public Expression -{ -public: - dinteger_t value; - - static IntegerExp *create(Loc loc, dinteger_t value, Type *type); - static IntegerExp *createi(Loc loc, int value, Type *type); - bool equals(RootObject *o); - dinteger_t toInteger(); - real_t toReal(); - real_t toImaginary(); - complex_t toComplex(); - bool isBool(bool result); - Expression *toLvalue(Scope *sc, Expression *e); - void accept(Visitor *v) { v->visit(this); } - dinteger_t getInteger() { return value; } - void setInteger(dinteger_t value); - void normalize(); -}; - -class ErrorExp : public Expression -{ -public: - Expression *toLvalue(Scope *sc, Expression *e); - void accept(Visitor *v) { v->visit(this); } - - static ErrorExp *errorexp; // handy shared value -}; - -class RealExp : public Expression -{ -public: - real_t value; - - static RealExp *create(Loc loc, real_t value, Type *type); - bool equals(RootObject *o); - dinteger_t toInteger(); - uinteger_t toUInteger(); - real_t toReal(); - real_t toImaginary(); - complex_t toComplex(); - bool isBool(bool result); - void accept(Visitor *v) { v->visit(this); } -}; - -class ComplexExp : public Expression -{ -public: - complex_t value; - - static ComplexExp *create(Loc loc, complex_t value, Type *type); - bool equals(RootObject *o); - dinteger_t toInteger(); - uinteger_t toUInteger(); - real_t toReal(); - real_t toImaginary(); - complex_t toComplex(); - bool isBool(bool result); - void accept(Visitor *v) { v->visit(this); } -}; - -class IdentifierExp : public Expression -{ -public: - Identifier *ident; - - static IdentifierExp *create(Loc loc, Identifier *ident); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - void accept(Visitor *v) { v->visit(this); } -}; - -class DollarExp : public IdentifierExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class DsymbolExp : public Expression -{ -public: - Dsymbol *s; - bool hasOverloads; - - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - void accept(Visitor *v) { v->visit(this); } -}; - -class ThisExp : public Expression -{ -public: - VarDeclaration *var; - - bool isBool(bool result); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - - void accept(Visitor *v) { v->visit(this); } -}; - -class SuperExp : public ThisExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class NullExp : public Expression -{ -public: - unsigned char committed; // !=0 if type is committed - - bool equals(RootObject *o); - bool isBool(bool result); - StringExp *toStringExp(); - void accept(Visitor *v) { v->visit(this); } -}; - -class StringExp : public Expression -{ -public: - void *string; // char, wchar, or dchar data - size_t len; // number of chars, wchars, or dchars - unsigned char sz; // 1: char, 2: wchar, 4: dchar - unsigned char committed; // !=0 if type is committed - utf8_t postfix; // 'c', 'w', 'd' - OwnedBy ownedByCtfe; - - static StringExp *create(Loc loc, char *s); - static StringExp *create(Loc loc, void *s, size_t len); - bool equals(RootObject *o); - StringExp *toStringExp(); - StringExp *toUTF8(Scope *sc); - int compare(RootObject *obj); - bool isBool(bool result); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - unsigned charAt(uinteger_t i) const; - void accept(Visitor *v) { v->visit(this); } - size_t numberOfCodeUnits(int tynto = 0) const; - void writeTo(void* dest, bool zero, int tyto = 0) const; - char *toPtr(); -}; - -// Tuple - -class TupleExp : public Expression -{ -public: - Expression *e0; // side-effect part - /* Tuple-field access may need to take out its side effect part. - * For example: - * foo().tupleof - * is rewritten as: - * (ref __tup = foo(); tuple(__tup.field0, __tup.field1, ...)) - * The declaration of temporary variable __tup will be stored in TupleExp::e0. - */ - Expressions *exps; - - TupleExp *toTupleExp(); - Expression *syntaxCopy(); - bool equals(RootObject *o); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ArrayLiteralExp : public Expression -{ -public: - Expression *basis; - Expressions *elements; - OwnedBy ownedByCtfe; - - static ArrayLiteralExp *create(Loc loc, Expressions *elements); - Expression *syntaxCopy(); - bool equals(RootObject *o); - Expression *getElement(d_size_t i); - bool isBool(bool result); - StringExp *toStringExp(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class AssocArrayLiteralExp : public Expression -{ -public: - Expressions *keys; - Expressions *values; - OwnedBy ownedByCtfe; - - bool equals(RootObject *o); - Expression *syntaxCopy(); - bool isBool(bool result); - - void accept(Visitor *v) { v->visit(this); } -}; - -class StructLiteralExp : public Expression -{ -public: - StructDeclaration *sd; // which aggregate this is for - Expressions *elements; // parallels sd->fields[] with NULL entries for fields to skip - Type *stype; // final type of result (can be different from sd's type) - - bool useStaticInit; // if this is true, use the StructDeclaration's init symbol - Symbol *sym; // back end symbol to initialize with literal - - OwnedBy ownedByCtfe; - - // pointer to the origin instance of the expression. - // once a new expression is created, origin is set to 'this'. - // anytime when an expression copy is created, 'origin' pointer is set to - // 'origin' pointer value of the original expression. - StructLiteralExp *origin; - - // those fields need to prevent a infinite recursion when one field of struct initialized with 'this' pointer. - StructLiteralExp *inlinecopy; - - // anytime when recursive function is calling, 'stageflags' marks with bit flag of - // current stage and unmarks before return from this function. - // 'inlinecopy' uses similar 'stageflags' and from multiple evaluation 'doInline' - // (with infinite recursion) of this expression. - int stageflags; - - static StructLiteralExp *create(Loc loc, StructDeclaration *sd, void *elements, Type *stype = NULL); - bool equals(RootObject *o); - Expression *syntaxCopy(); - Expression *getField(Type *type, unsigned offset); - int getFieldIndex(Type *type, unsigned offset); - Expression *addDtorHook(Scope *sc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeExp : public Expression -{ -public: - Expression *syntaxCopy(); - bool checkType(); - bool checkValue(); - void accept(Visitor *v) { v->visit(this); } -}; - -class ScopeExp : public Expression -{ -public: - ScopeDsymbol *sds; - - Expression *syntaxCopy(); - bool checkType(); - bool checkValue(); - void accept(Visitor *v) { v->visit(this); } -}; - -class TemplateExp : public Expression -{ -public: - TemplateDeclaration *td; - FuncDeclaration *fd; - - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - bool checkType(); - bool checkValue(); - void accept(Visitor *v) { v->visit(this); } -}; - -class NewExp : public Expression -{ -public: - /* thisexp.new(newargs) newtype(arguments) - */ - Expression *thisexp; // if !NULL, 'this' for class being allocated - Expressions *newargs; // Array of Expression's to call new operator - Type *newtype; - Expressions *arguments; // Array of Expression's - - Expression *argprefix; // expression to be evaluated just before arguments[] - - CtorDeclaration *member; // constructor function - NewDeclaration *allocator; // allocator function - bool onstack; // allocate on stack - bool thrownew; // this NewExp is the expression of a ThrowStatement - - static NewExp *create(Loc loc, Expression *thisexp, Expressions *newargs, Type *newtype, Expressions *arguments); - Expression *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class NewAnonClassExp : public Expression -{ -public: - /* thisexp.new(newargs) class baseclasses { } (arguments) - */ - Expression *thisexp; // if !NULL, 'this' for class being allocated - Expressions *newargs; // Array of Expression's to call new operator - ClassDeclaration *cd; // class being instantiated - Expressions *arguments; // Array of Expression's to call class constructor - - Expression *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -class SymbolExp : public Expression -{ -public: - Declaration *var; - bool hasOverloads; - - void accept(Visitor *v) { v->visit(this); } -}; - -// Offset from symbol - -class SymOffExp : public SymbolExp -{ -public: - dinteger_t offset; - - bool isBool(bool result); - - void accept(Visitor *v) { v->visit(this); } -}; - -// Variable - -class VarExp : public SymbolExp -{ -public: - static VarExp *create(Loc loc, Declaration *var, bool hasOverloads = true); - bool equals(RootObject *o); - int checkModifiable(Scope *sc, int flag); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - - void accept(Visitor *v) { v->visit(this); } -}; - -// Overload Set - -class OverExp : public Expression -{ -public: - OverloadSet *vars; - - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - void accept(Visitor *v) { v->visit(this); } -}; - -// Function/Delegate literal - -class FuncExp : public Expression -{ -public: - FuncLiteralDeclaration *fd; - TemplateDeclaration *td; - TOK tok; - - bool equals(RootObject *o); - Expression *syntaxCopy(); - const char *toChars(); - bool checkType(); - bool checkValue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -// Declaration of a symbol - -// D grammar allows declarations only as statements. However in AST representation -// it can be part of any expression. This is used, for example, during internal -// syntax re-writes to inject hidden symbols. -class DeclarationExp : public Expression -{ -public: - Dsymbol *declaration; - - Expression *syntaxCopy(); - - bool hasCode(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeidExp : public Expression -{ -public: - RootObject *obj; - - Expression *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -class TraitsExp : public Expression -{ -public: - Identifier *ident; - Objects *args; - - Expression *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -class HaltExp : public Expression -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class IsExp : public Expression -{ -public: - /* is(targ id tok tspec) - * is(targ id == tok2) - */ - Type *targ; - Identifier *id; // can be NULL - TOK tok; // ':' or '==' - Type *tspec; // can be NULL - TOK tok2; // 'struct', 'union', etc. - TemplateParameters *parameters; - - Expression *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -/****************************************************************/ - -class UnaExp : public Expression -{ -public: - Expression *e1; - Type *att1; // Save alias this type to detect recursion - - Expression *syntaxCopy(); - Expression *incompatibleTypes(); - Expression *resolveLoc(const Loc &loc, Scope *sc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class BinExp : public Expression -{ -public: - Expression *e1; - Expression *e2; - - Type *att1; // Save alias this type to detect recursion - Type *att2; // Save alias this type to detect recursion - - Expression *syntaxCopy(); - Expression *incompatibleTypes(); - - Expression *reorderSettingAAElem(Scope *sc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class BinAssignExp : public BinExp -{ -public: - - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *ex); - Expression *modifiableLvalue(Scope *sc, Expression *e); - void accept(Visitor *v) { v->visit(this); } -}; - -/****************************************************************/ - -class CompileExp : public UnaExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class ImportExp : public UnaExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class AssertExp : public UnaExp -{ -public: - Expression *msg; - - Expression *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class DotIdExp : public UnaExp -{ -public: - Identifier *ident; - bool noderef; // true if the result of the expression will never be dereferenced - bool wantsym; // do not replace Symbol with its initializer during semantic() - - static DotIdExp *create(Loc loc, Expression *e, Identifier *ident); - void accept(Visitor *v) { v->visit(this); } -}; - -class DotTemplateExp : public UnaExp -{ -public: - TemplateDeclaration *td; - - void accept(Visitor *v) { v->visit(this); } -}; - -class DotVarExp : public UnaExp -{ -public: - Declaration *var; - bool hasOverloads; - - int checkModifiable(Scope *sc, int flag); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - void accept(Visitor *v) { v->visit(this); } -}; - -class DotTemplateInstanceExp : public UnaExp -{ -public: - TemplateInstance *ti; - - Expression *syntaxCopy(); - bool findTempDecl(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class DelegateExp : public UnaExp -{ -public: - FuncDeclaration *func; - bool hasOverloads; - - - void accept(Visitor *v) { v->visit(this); } -}; - -class DotTypeExp : public UnaExp -{ -public: - Dsymbol *sym; // symbol that represents a type - - void accept(Visitor *v) { v->visit(this); } -}; - -class CallExp : public UnaExp -{ -public: - Expressions *arguments; // function arguments - FuncDeclaration *f; // symbol to call - bool directcall; // true if a virtual call is devirtualized - - static CallExp *create(Loc loc, Expression *e, Expressions *exps); - static CallExp *create(Loc loc, Expression *e); - static CallExp *create(Loc loc, Expression *e, Expression *earg1); - static CallExp *create(Loc loc, FuncDeclaration *fd, Expression *earg1); - - Expression *syntaxCopy(); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *addDtorHook(Scope *sc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class AddrExp : public UnaExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class PtrExp : public UnaExp -{ -public: - int checkModifiable(Scope *sc, int flag); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - - void accept(Visitor *v) { v->visit(this); } -}; - -class NegExp : public UnaExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class UAddExp : public UnaExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class ComExp : public UnaExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class NotExp : public UnaExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class DeleteExp : public UnaExp -{ -public: - bool isRAII; - Expression *toBoolean(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class CastExp : public UnaExp -{ -public: - // Possible to cast to one type while painting to another type - Type *to; // type to cast to - unsigned char mod; // MODxxxxx - - Expression *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class VectorExp : public UnaExp -{ -public: - TypeVector *to; // the target vector type before semantic() - unsigned dim; // number of elements in the vector - - static VectorExp *create(Loc loc, Expression *e, Type *t); - Expression *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -class SliceExp : public UnaExp -{ -public: - Expression *upr; // NULL if implicit 0 - Expression *lwr; // NULL if implicit [length - 1] - VarDeclaration *lengthVar; - bool upperIsInBounds; // true if upr <= e1.length - bool lowerIsLessThanUpper; // true if lwr <= upr - bool arrayop; // an array operation, rather than a slice - - Expression *syntaxCopy(); - int checkModifiable(Scope *sc, int flag); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - bool isBool(bool result); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ArrayLengthExp : public UnaExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class IntervalExp : public Expression -{ -public: - Expression *lwr; - Expression *upr; - - Expression *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -class DelegatePtrExp : public UnaExp -{ -public: - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - void accept(Visitor *v) { v->visit(this); } -}; - -class DelegateFuncptrExp : public UnaExp -{ -public: - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - void accept(Visitor *v) { v->visit(this); } -}; - -// e1[a0,a1,a2,a3,...] - -class ArrayExp : public UnaExp -{ -public: - Expressions *arguments; // Array of Expression's - size_t currentDimension; // for opDollar - VarDeclaration *lengthVar; - - Expression *syntaxCopy(); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - - void accept(Visitor *v) { v->visit(this); } -}; - -/****************************************************************/ - -class DotExp : public BinExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class CommaExp : public BinExp -{ -public: - bool isGenerated; - bool allowCommaExp; - int checkModifiable(Scope *sc, int flag); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - bool isBool(bool result); - Expression *toBoolean(Scope *sc); - Expression *addDtorHook(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class IndexExp : public BinExp -{ -public: - VarDeclaration *lengthVar; - bool modifiable; - bool indexIsInBounds; // true if 0 <= e2 && e2 <= e1.length - 1 - - Expression *syntaxCopy(); - int checkModifiable(Scope *sc, int flag); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - - Expression *markSettingAAElem(); - - void accept(Visitor *v) { v->visit(this); } -}; - -/* For both i++ and i-- - */ -class PostExp : public BinExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -/* For both ++i and --i - */ -class PreExp : public UnaExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -enum MemorySet -{ - blockAssign = 1, // setting the contents of an array - referenceInit = 2 // setting the reference of STCref variable -}; - -class AssignExp : public BinExp -{ -public: - int memset; // combination of MemorySet flags - - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *ex); - Expression *toBoolean(Scope *sc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ConstructExp : public AssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class BlitExp : public AssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class AddAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class MinAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class MulAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class DivAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class ModAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class AndAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class OrAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class XorAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class PowAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class ShlAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class ShrAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class UshrAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class CatAssignExp : public BinAssignExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class AddExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class MinExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class CatExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class MulExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class DivExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class ModExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class PowExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class ShlExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class ShrExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class UshrExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class AndExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class OrExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class XorExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class LogicalExp : public BinExp -{ -public: - Expression *toBoolean(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class CmpExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class InExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -class RemoveExp : public BinExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -// == and != - -class EqualExp : public BinExp -{ -public: - - void accept(Visitor *v) { v->visit(this); } -}; - -// is and !is - -class IdentityExp : public BinExp -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -/****************************************************************/ - -class CondExp : public BinExp -{ -public: - Expression *econd; - - Expression *syntaxCopy(); - int checkModifiable(Scope *sc, int flag); - bool isLvalue(); - Expression *toLvalue(Scope *sc, Expression *e); - Expression *modifiableLvalue(Scope *sc, Expression *e); - Expression *toBoolean(Scope *sc); - void hookDtors(Scope *sc); - - void accept(Visitor *v) { v->visit(this); } -}; - -/****************************************************************/ - -class DefaultInitExp : public Expression -{ -public: - TOK subop; // which of the derived classes this is - - void accept(Visitor *v) { v->visit(this); } -}; - -class FileInitExp : public DefaultInitExp -{ -public: - Expression *resolveLoc(const Loc &loc, Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class LineInitExp : public DefaultInitExp -{ -public: - Expression *resolveLoc(const Loc &loc, Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class ModuleInitExp : public DefaultInitExp -{ -public: - Expression *resolveLoc(const Loc &loc, Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class FuncInitExp : public DefaultInitExp -{ -public: - Expression *resolveLoc(const Loc &loc, Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class PrettyFuncInitExp : public DefaultInitExp -{ -public: - Expression *resolveLoc(const Loc &loc, Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -/****************************************************************/ - -/* A type meant as a union of all the Expression types, - * to serve essentially as a Variant that will sit on the stack - * during CTFE to reduce memory consumption. - */ -struct UnionExp -{ - UnionExp() { } // yes, default constructor does nothing - - UnionExp(Expression *e) - { - memcpy(this, (void *)e, e->size); - } - - /* Extract pointer to Expression - */ - Expression *exp() { return (Expression *)&u; } - - /* Convert to an allocated Expression - */ - Expression *copy(); - -private: - // Ensure that the union is suitably aligned. -#if defined(__GNUC__) || defined(__clang__) - __attribute__((aligned(8))) -#elif defined(_MSC_VER) - __declspec(align(8)) -#elif defined(__DMC__) - #pragma pack(8) -#endif - union - { - char exp [sizeof(Expression)]; - char integerexp[sizeof(IntegerExp)]; - char errorexp [sizeof(ErrorExp)]; - char realexp [sizeof(RealExp)]; - char complexexp[sizeof(ComplexExp)]; - char symoffexp [sizeof(SymOffExp)]; - char stringexp [sizeof(StringExp)]; - char arrayliteralexp [sizeof(ArrayLiteralExp)]; - char assocarrayliteralexp [sizeof(AssocArrayLiteralExp)]; - char structliteralexp [sizeof(StructLiteralExp)]; - char nullexp [sizeof(NullExp)]; - char dotvarexp [sizeof(DotVarExp)]; - char addrexp [sizeof(AddrExp)]; - char indexexp [sizeof(IndexExp)]; - char sliceexp [sizeof(SliceExp)]; - } u; -#if defined(__DMC__) - #pragma pack() -#endif -}; - -/****************************************************************/ - -class ObjcClassReferenceExp : public Expression -{ - ClassDeclaration* classDeclaration; - - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/hdrgen.h b/src/dmd/hdrgen.h deleted file mode 100644 index 840c0372817c..000000000000 --- a/src/dmd/hdrgen.h +++ /dev/null @@ -1,28 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Dave Fladebo - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/hdrgen.h - */ - -#pragma once - -#include "globals.h" -#include "dsymbol.h" -#include "mtype.h" - -class Module; - -void genhdrfile(Module *m); -void moduleToBuffer(OutBuffer *buf, Module *m); - -const char *parametersTypeToChars(Parameters *parameters, int varargs); -const char *stcToChars(StorageClass& stc); -void trustToBuffer(OutBuffer *buf, TRUST trust); -const char *trustToChars(TRUST trust); -const char *linkageToChars(LINK linkage); -void protectionToBuffer(OutBuffer *buf, Prot prot); -const char *protectionToChars(Prot::Kind kind); diff --git a/src/dmd/id.h b/src/dmd/id.h deleted file mode 100644 index 3eca8012dc3a..000000000000 --- a/src/dmd/id.h +++ /dev/null @@ -1,16 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 2017-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/id.h - */ - -#pragma once - -struct Id -{ - static void initialize(); -}; diff --git a/src/dmd/identifier.h b/src/dmd/identifier.h deleted file mode 100644 index 1503e63cbb05..000000000000 --- a/src/dmd/identifier.h +++ /dev/null @@ -1,41 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/identifier.h - */ - -#pragma once - -#include "root/dcompat.h" -#include "root/root.h" - -class Identifier : public RootObject -{ -private: - int value; - DArray string; - -public: - static Identifier* create(const char *string); - bool equals(RootObject *o); - int compare(RootObject *o); - const char *toChars(); - int getValue() const; - const char *toHChars2(); - int dyncast() const; - - static Identifier *generateId(const char *prefix); - static Identifier *generateId(const char *prefix, size_t i); - static Identifier *idPool(const char *s, unsigned len); - - static inline Identifier *idPool(const char *s) - { - return idPool(s, strlen(s)); - } - - static bool isValidIdentifier(const char *p); -}; diff --git a/src/dmd/import.h b/src/dmd/import.h deleted file mode 100644 index f743cb0f49ee..000000000000 --- a/src/dmd/import.h +++ /dev/null @@ -1,55 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/import.h - */ - -#pragma once - -#include "dsymbol.h" - -class Identifier; -struct Scope; -class Module; -class Package; - -class Import : public Dsymbol -{ -public: - /* static import aliasId = pkg1.pkg2.id : alias1 = name1, alias2 = name2; - */ - - Identifiers *packages; // array of Identifier's representing packages - Identifier *id; // module Identifier - Identifier *aliasId; - int isstatic; // !=0 if static import - Prot protection; - - // Pairs of alias=name to bind into current namespace - Identifiers names; - Identifiers aliases; - - Module *mod; - Package *pkg; // leftmost package/module - - AliasDeclarations aliasdecls; // corresponding AliasDeclarations for alias=name pairs - - void addAlias(Identifier *name, Identifier *alias); - const char *kind() const; - Prot prot(); - Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees - void load(Scope *sc); - void importAll(Scope *sc); - Dsymbol *toAlias(); - void addMember(Scope *sc, ScopeDsymbol *sds); - void setScope(Scope* sc); - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - bool overloadInsert(Dsymbol *s); - - Import *isImport() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/init.h b/src/dmd/init.h deleted file mode 100644 index 8fc9182b775b..000000000000 --- a/src/dmd/init.h +++ /dev/null @@ -1,98 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/init.h - */ - -#pragma once - -#include "globals.h" -#include "arraytypes.h" -#include "visitor.h" - -class Identifier; -class Expression; -class Type; -class ErrorInitializer; -class VoidInitializer; -class StructInitializer; -class ArrayInitializer; -class ExpInitializer; - -enum NeedInterpret { INITnointerpret, INITinterpret }; - -class Initializer : public RootObject -{ -public: - Loc loc; - unsigned char kind; - - const char *toChars(); - - ErrorInitializer *isErrorInitializer(); - VoidInitializer *isVoidInitializer(); - StructInitializer *isStructInitializer(); - ArrayInitializer *isArrayInitializer(); - ExpInitializer *isExpInitializer(); - - virtual void accept(Visitor *v) { v->visit(this); } -}; - -class VoidInitializer : public Initializer -{ -public: - Type *type; // type that this will initialize to - - void accept(Visitor *v) { v->visit(this); } -}; - -class ErrorInitializer : public Initializer -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -class StructInitializer : public Initializer -{ -public: - Identifiers field; // of Identifier *'s - Initializers value; // parallel array of Initializer *'s - - void addInit(Identifier *field, Initializer *value); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ArrayInitializer : public Initializer -{ -public: - Expressions index; // indices - Initializers value; // of Initializer *'s - unsigned dim; // length of array being initialized - Type *type; // type that array will be used to initialize - bool sem; // true if semantic() is run - - void addInit(Expression *index, Initializer *value); - bool isAssociativeArray(); - Expression *toAssocArrayLiteral(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ExpInitializer : public Initializer -{ -public: - bool expandTuples; - Expression *exp; - - void accept(Visitor *v) { v->visit(this); } -}; - -Expression *initializerToExpression(Initializer *init, Type *t = NULL); - -Initializer *syntaxCopy(Initializer *inx); - diff --git a/src/dmd/json.h b/src/dmd/json.h deleted file mode 100644 index 7e4a51255b81..000000000000 --- a/src/dmd/json.h +++ /dev/null @@ -1,17 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/json.h - */ - -#pragma once - -#include "arraytypes.h" - -struct OutBuffer; - -void json_generate(OutBuffer *, Modules *); diff --git a/src/dmd/module.h b/src/dmd/module.h deleted file mode 100644 index 782a361d405b..000000000000 --- a/src/dmd/module.h +++ /dev/null @@ -1,166 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/module.h - */ - -#pragma once - -#include "dsymbol.h" - -struct ModuleDeclaration; -struct Macro; -struct Escape; - -enum PKG -{ - PKGunknown, // not yet determined whether it's a package.d or not - PKGmodule, // already determined that's an actual package.d - PKGpackage // already determined that's an actual package -}; - -class Package : public ScopeDsymbol -{ -public: - PKG isPkgMod; - unsigned tag; // auto incremented tag, used to mask package tree in scopes - Module *mod; // != NULL if isPkgMod == PKGmodule - - const char *kind() const; - - Package *isPackage() { return this; } - - bool isAncestorPackageOf(const Package * const pkg) const; - - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - void accept(Visitor *v) { v->visit(this); } - - Module *isPackageMod(); -}; - -class Module : public Package -{ -public: - static Module *rootModule; - static DsymbolTable *modules; // symbol table of all modules - static Modules amodules; // array of all modules - static Dsymbols deferred; // deferred Dsymbol's needing semantic() run on them - static Dsymbols deferred2; // deferred Dsymbol's needing semantic2() run on them - static Dsymbols deferred3; // deferred Dsymbol's needing semantic3() run on them - static unsigned dprogress; // progress resolving the deferred list - - static void _init(); - - static AggregateDeclaration *moduleinfo; - - - const char *arg; // original argument name - ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration - File *srcfile; // input source file - File *objfile; // output .obj file - File *hdrfile; // 'header' file - File *docfile; // output documentation file - unsigned errors; // if any errors in file - unsigned numlines; // number of lines in source file - bool isHdrFile; // if it is a header (.di) file - bool isDocFile; // if it is a documentation input file, not D source - bool isPackageFile; // if it is a package.d - Strings contentImportedFiles; // array of files whose content was imported - int needmoduleinfo; - int selfimports; // 0: don't know, 1: does not, 2: does - bool selfImports(); // returns true if module imports itself - - int rootimports; // 0: don't know, 1: does not, 2: does - bool rootImports(); // returns true if module imports root module - - int insearch; - Identifier *searchCacheIdent; - Dsymbol *searchCacheSymbol; // cached value of search - int searchCacheFlags; // cached flags - - // module from command line we're imported from, - // i.e. a module that will be taken all the - // way to an object file - Module *importedFrom; - - Dsymbols *decldefs; // top level declarations for this Module - - Modules aimports; // all imported modules - - unsigned debuglevel; // debug level - Strings *debugids; // debug identifiers - Strings *debugidsNot; // forward referenced debug identifiers - - unsigned versionlevel; // version level - Strings *versionids; // version identifiers - Strings *versionidsNot; // forward referenced version identifiers - - Macro *macrotable; // document comment macros - Escape *escapetable; // document comment escapes - - size_t nameoffset; // offset of module name from start of ModuleInfo - size_t namelen; // length of module name in characters - - static Module* create(const char *arg, Identifier *ident, int doDocComment, int doHdrGen); - - static Module *load(Loc loc, Identifiers *packages, Identifier *ident); - - const char *kind() const; - File *setOutfile(const char *name, const char *dir, const char *arg, const char *ext); - void setDocfile(); - bool read(Loc loc); // read file, returns 'true' if succeed, 'false' otherwise. - Module *parse(); // syntactic parse - void importAll(Scope *sc); - int needModuleInfo(); - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - bool isPackageAccessible(Package *p, Prot protection, int flags = 0); - Dsymbol *symtabInsert(Dsymbol *s); - void deleteObjFile(); - static void addDeferredSemantic(Dsymbol *s); - static void addDeferredSemantic2(Dsymbol *s); - static void addDeferredSemantic3(Dsymbol *s); - static void runDeferredSemantic(); - static void runDeferredSemantic2(); - static void runDeferredSemantic3(); - static void clearCache(); - int imports(Module *m); - - bool isRoot() { return this->importedFrom == this; } - // true if the module source file is directly - // listed in command line. - bool isCoreModule(Identifier *ident); - - // Back end - - int doppelganger; // sub-module - Symbol *cov; // private uint[] __coverage; - unsigned *covb; // bit array of valid code line numbers - - Symbol *sictor; // module order independent constructor - Symbol *sctor; // module constructor - Symbol *sdtor; // module destructor - Symbol *ssharedctor; // module shared constructor - Symbol *sshareddtor; // module shared destructor - Symbol *stest; // module unit test - - Symbol *sfilename; // symbol for filename - - Module *isModule() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - - -struct ModuleDeclaration -{ - Loc loc; - Identifier *id; - Identifiers *packages; // array of Identifier's representing packages - bool isdeprecated; // if it is a deprecated module - Expression *msg; - - const char *toChars() const; -}; diff --git a/src/dmd/mtype.h b/src/dmd/mtype.h deleted file mode 100644 index cf8fdb660f09..000000000000 --- a/src/dmd/mtype.h +++ /dev/null @@ -1,824 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/mtype.h - */ - -#pragma once - -#include "root/rmem.h" // for d_size_t - -#include "arraytypes.h" -#include "globals.h" -#include "visitor.h" - -struct Scope; -class Identifier; -class Expression; -class StructDeclaration; -class ClassDeclaration; -class EnumDeclaration; -class TypeInfoDeclaration; -class Dsymbol; -class TemplateInstance; -class TemplateDeclaration; - -class TypeBasic; -class Parameter; - -// Back end -#ifdef IN_GCC -typedef union tree_node type; -#else -typedef struct TYPE type; -#endif - -void semanticTypeInfo(Scope *sc, Type *t); -MATCH deduceType(RootObject *o, Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes, unsigned *wm = NULL, size_t inferStart = 0); -StorageClass ModToStc(unsigned mod); - -enum ENUMTY -{ - Tarray, // slice array, aka T[] - Tsarray, // static array, aka T[dimension] - Taarray, // associative array, aka T[type] - Tpointer, - Treference, - Tfunction, - Tident, - Tclass, - Tstruct, - Tenum, - - Tdelegate, - Tnone, - Tvoid, - Tint8, - Tuns8, - Tint16, - Tuns16, - Tint32, - Tuns32, - Tint64, - - Tuns64, - Tfloat32, - Tfloat64, - Tfloat80, - Timaginary32, - Timaginary64, - Timaginary80, - Tcomplex32, - Tcomplex64, - Tcomplex80, - - Tbool, - Tchar, - Twchar, - Tdchar, - Terror, - Tinstance, - Ttypeof, - Ttuple, - Tslice, - Treturn, - - Tnull, - Tvector, - Tint128, - Tuns128, - TTraits, - TMAX -}; -typedef unsigned char TY; // ENUMTY - -extern int Tsize_t; -extern int Tptrdiff_t; - -#define SIZE_INVALID (~(d_uns64)0) // error return from size() functions - - -/** - * type modifiers - * pick this order of numbers so switch statements work better - */ -enum MODFlags -{ - MODconst = 1, // type is const - MODimmutable = 4, // type is immutable - MODshared = 2, // type is shared - MODwild = 8, // type is wild - MODwildconst = (MODwild | MODconst), // type is wild const - MODmutable = 0x10 // type is mutable (only used in wildcard matching) -}; -typedef unsigned char MOD; - -// These tables are for implicit conversion of binary ops; -// the indices are the type of operand one, followed by operand two. -extern unsigned char impcnvResult[TMAX][TMAX]; -extern unsigned char impcnvType1[TMAX][TMAX]; -extern unsigned char impcnvType2[TMAX][TMAX]; - -// If !=0, give warning on implicit conversion -extern unsigned char impcnvWarn[TMAX][TMAX]; - -class Type : public RootObject -{ -public: - TY ty; - MOD mod; // modifiers MODxxxx - char *deco; - - /* These are cached values that are lazily evaluated by constOf(), immutableOf(), etc. - * They should not be referenced by anybody but mtype.c. - * They can be NULL if not lazily evaluated yet. - * Note that there is no "shared immutable", because that is just immutable - * Naked == no MOD bits - */ - - Type *cto; // MODconst ? naked version of this type : const version - Type *ito; // MODimmutable ? naked version of this type : immutable version - Type *sto; // MODshared ? naked version of this type : shared mutable version - Type *scto; // MODshared | MODconst ? naked version of this type : shared const version - Type *wto; // MODwild ? naked version of this type : wild version - Type *wcto; // MODwildconst ? naked version of this type : wild const version - Type *swto; // MODshared | MODwild ? naked version of this type : shared wild version - Type *swcto; // MODshared | MODwildconst ? naked version of this type : shared wild const version - - Type *pto; // merged pointer to this type - Type *rto; // reference to this type - Type *arrayof; // array of this type - TypeInfoDeclaration *vtinfo; // TypeInfo object for this Type - - type *ctype; // for back end - - static Type *tvoid; - static Type *tint8; - static Type *tuns8; - static Type *tint16; - static Type *tuns16; - static Type *tint32; - static Type *tuns32; - static Type *tint64; - static Type *tuns64; - static Type *tint128; - static Type *tuns128; - static Type *tfloat32; - static Type *tfloat64; - static Type *tfloat80; - - static Type *timaginary32; - static Type *timaginary64; - static Type *timaginary80; - - static Type *tcomplex32; - static Type *tcomplex64; - static Type *tcomplex80; - - static Type *tbool; - static Type *tchar; - static Type *twchar; - static Type *tdchar; - - // Some special types - static Type *tshiftcnt; - static Type *tvoidptr; // void* - static Type *tstring; // immutable(char)[] - static Type *twstring; // immutable(wchar)[] - static Type *tdstring; // immutable(dchar)[] - static Type *tvalist; // va_list alias - static Type *terror; // for error recovery - static Type *tnull; // for null type - - static Type *tsize_t; // matches size_t alias - static Type *tptrdiff_t; // matches ptrdiff_t alias - static Type *thash_t; // matches hash_t alias - - static ClassDeclaration *dtypeinfo; - static ClassDeclaration *typeinfoclass; - static ClassDeclaration *typeinfointerface; - static ClassDeclaration *typeinfostruct; - static ClassDeclaration *typeinfopointer; - static ClassDeclaration *typeinfoarray; - static ClassDeclaration *typeinfostaticarray; - static ClassDeclaration *typeinfoassociativearray; - static ClassDeclaration *typeinfovector; - static ClassDeclaration *typeinfoenum; - static ClassDeclaration *typeinfofunction; - static ClassDeclaration *typeinfodelegate; - static ClassDeclaration *typeinfotypelist; - static ClassDeclaration *typeinfoconst; - static ClassDeclaration *typeinfoinvariant; - static ClassDeclaration *typeinfoshared; - static ClassDeclaration *typeinfowild; - - static TemplateDeclaration *rtinfo; - - static Type *basic[TMAX]; - - virtual const char *kind(); - Type *copy(); - virtual Type *syntaxCopy(); - bool equals(RootObject *o); - bool equivalent(Type *t); - // kludge for template.isType() - int dyncast() const { return DYNCAST_TYPE; } - int covariant(Type *t, StorageClass *pstc = NULL, bool fix17349 = true); - const char *toChars(); - char *toPrettyChars(bool QualifyTypes = false); - static void _init(); - - d_uns64 size(); - virtual d_uns64 size(const Loc &loc); - virtual unsigned alignsize(); - Type *trySemantic(const Loc &loc, Scope *sc); - Type *merge2(); - void modToBuffer(OutBuffer *buf); - char *modToChars(); - - virtual bool isintegral(); - virtual bool isfloating(); // real, imaginary, or complex - virtual bool isreal(); - virtual bool isimaginary(); - virtual bool iscomplex(); - virtual bool isscalar(); - virtual bool isunsigned(); - virtual bool isscope(); - virtual bool isString(); - virtual bool isAssignable(); - virtual bool isBoolean(); - virtual void checkDeprecated(const Loc &loc, Scope *sc); - bool isConst() const { return (mod & MODconst) != 0; } - bool isImmutable() const { return (mod & MODimmutable) != 0; } - bool isMutable() const { return (mod & (MODconst | MODimmutable | MODwild)) == 0; } - bool isShared() const { return (mod & MODshared) != 0; } - bool isSharedConst() const { return (mod & (MODshared | MODconst)) == (MODshared | MODconst); } - bool isWild() const { return (mod & MODwild) != 0; } - bool isWildConst() const { return (mod & MODwildconst) == MODwildconst; } - bool isSharedWild() const { return (mod & (MODshared | MODwild)) == (MODshared | MODwild); } - bool isNaked() const { return mod == 0; } - Type *nullAttributes(); - Type *constOf(); - Type *immutableOf(); - Type *mutableOf(); - Type *sharedOf(); - Type *sharedConstOf(); - Type *unSharedOf(); - Type *wildOf(); - Type *wildConstOf(); - Type *sharedWildOf(); - Type *sharedWildConstOf(); - void fixTo(Type *t); - void check(); - Type *addSTC(StorageClass stc); - Type *castMod(MOD mod); - Type *addMod(MOD mod); - virtual Type *addStorageClass(StorageClass stc); - Type *pointerTo(); - Type *referenceTo(); - Type *arrayOf(); - Type *sarrayOf(dinteger_t dim); - Type *aliasthisOf(); - virtual Type *makeConst(); - virtual Type *makeImmutable(); - virtual Type *makeShared(); - virtual Type *makeSharedConst(); - virtual Type *makeWild(); - virtual Type *makeWildConst(); - virtual Type *makeSharedWild(); - virtual Type *makeSharedWildConst(); - virtual Type *makeMutable(); - virtual Dsymbol *toDsymbol(Scope *sc); - virtual Type *toBasetype(); - virtual bool isBaseOf(Type *t, int *poffset); - virtual MATCH implicitConvTo(Type *to); - virtual MATCH constConv(Type *to); - virtual unsigned char deduceWild(Type *t, bool isRef); - virtual Type *substWildTo(unsigned mod); - - Type *unqualify(unsigned m); - - virtual Type *toHeadMutable(); - virtual ClassDeclaration *isClassHandle(); - virtual structalign_t alignment(); - virtual Expression *defaultInitLiteral(const Loc &loc); - virtual bool isZeroInit(const Loc &loc = Loc()); // if initializer is 0 - Identifier *getTypeInfoIdent(); - void resolveExp(Expression *e, Type **pt, Expression **pe, Dsymbol **ps); - virtual int hasWild() const; - virtual bool hasPointers(); - virtual bool hasVoidInitPointers(); - virtual Type *nextOf(); - Type *baseElemOf(); - uinteger_t sizemask(); - virtual bool needsDestruction(); - virtual bool needsNested(); - - // For eliminating dynamic_cast - virtual TypeBasic *isTypeBasic(); - virtual void accept(Visitor *v) { v->visit(this); } -}; - -class TypeError : public Type -{ -public: - Type *syntaxCopy(); - - d_uns64 size(const Loc &loc); - Expression *defaultInitLiteral(const Loc &loc); - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeNext : public Type -{ -public: - Type *next; - - void checkDeprecated(const Loc &loc, Scope *sc); - int hasWild() const; - Type *nextOf(); - Type *makeConst(); - Type *makeImmutable(); - Type *makeShared(); - Type *makeSharedConst(); - Type *makeWild(); - Type *makeWildConst(); - Type *makeSharedWild(); - Type *makeSharedWildConst(); - Type *makeMutable(); - MATCH constConv(Type *to); - unsigned char deduceWild(Type *t, bool isRef); - void transitive(); - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeBasic : public Type -{ -public: - const char *dstring; - unsigned flags; - - const char *kind(); - Type *syntaxCopy(); - d_uns64 size(const Loc &loc) /*const*/; - unsigned alignsize(); - bool isintegral(); - bool isfloating() /*const*/; - bool isreal() /*const*/; - bool isimaginary() /*const*/; - bool iscomplex() /*const*/; - bool isscalar() /*const*/; - bool isunsigned() /*const*/; - MATCH implicitConvTo(Type *to); - bool isZeroInit(const Loc &loc) /*const*/; - - // For eliminating dynamic_cast - TypeBasic *isTypeBasic(); - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeVector : public Type -{ -public: - Type *basetype; - - static TypeVector *create(Type *basetype); - const char *kind(); - Type *syntaxCopy(); - d_uns64 size(const Loc &loc); - unsigned alignsize(); - bool isintegral(); - bool isfloating(); - bool isscalar(); - bool isunsigned(); - bool isBoolean() /*const*/; - MATCH implicitConvTo(Type *to); - Expression *defaultInitLiteral(const Loc &loc); - TypeBasic *elementType(); - bool isZeroInit(const Loc &loc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeArray : public TypeNext -{ -public: - void accept(Visitor *v) { v->visit(this); } -}; - -// Static array, one with a fixed dimension -class TypeSArray : public TypeArray -{ -public: - Expression *dim; - - const char *kind(); - Type *syntaxCopy(); - d_uns64 size(const Loc &loc); - unsigned alignsize(); - bool isString(); - bool isZeroInit(const Loc &loc); - structalign_t alignment(); - MATCH constConv(Type *to); - MATCH implicitConvTo(Type *to); - Expression *defaultInitLiteral(const Loc &loc); - bool hasPointers(); - bool needsDestruction(); - bool needsNested(); - - void accept(Visitor *v) { v->visit(this); } -}; - -// Dynamic array, no dimension -class TypeDArray : public TypeArray -{ -public: - const char *kind(); - Type *syntaxCopy(); - d_uns64 size(const Loc &loc) /*const*/; - unsigned alignsize() /*const*/; - bool isString(); - bool isZeroInit(const Loc &loc) /*const*/; - bool isBoolean() /*const*/; - MATCH implicitConvTo(Type *to); - bool hasPointers() /*const*/; - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeAArray : public TypeArray -{ -public: - Type *index; // key type - Loc loc; - Scope *sc; - - static TypeAArray *create(Type *t, Type *index); - const char *kind(); - Type *syntaxCopy(); - d_uns64 size(const Loc &loc); - bool isZeroInit(const Loc &loc) /*const*/; - bool isBoolean() /*const*/; - bool hasPointers() /*const*/; - MATCH implicitConvTo(Type *to); - MATCH constConv(Type *to); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypePointer : public TypeNext -{ -public: - static TypePointer *create(Type *t); - const char *kind(); - Type *syntaxCopy(); - d_uns64 size(const Loc &loc) /*const*/; - MATCH implicitConvTo(Type *to); - MATCH constConv(Type *to); - bool isscalar() /*const*/; - bool isZeroInit(const Loc &loc) /*const*/; - bool hasPointers() /*const*/; - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeReference : public TypeNext -{ -public: - const char *kind(); - Type *syntaxCopy(); - d_uns64 size(const Loc &loc) /*const*/; - bool isZeroInit(const Loc &loc) /*const*/; - void accept(Visitor *v) { v->visit(this); } -}; - -enum RET -{ - RETregs = 1, // returned in registers - RETstack = 2 // returned on stack -}; - -enum TRUST -{ - TRUSTdefault = 0, - TRUSTsystem = 1, // @system (same as TRUSTdefault) - TRUSTtrusted = 2, // @trusted - TRUSTsafe = 3 // @safe -}; - -enum TRUSTformat -{ - TRUSTformatDefault, // do not emit @system when trust == TRUSTdefault - TRUSTformatSystem // emit @system when trust == TRUSTdefault -}; - -enum PURE -{ - PUREimpure = 0, // not pure at all - PUREfwdref = 1, // it's pure, but not known which level yet - PUREweak = 2, // no mutable globals are read or written - PUREconst = 3, // parameters are values or const - PUREstrong = 4 // parameters are values or immutable -}; - -class TypeFunction : public TypeNext -{ -public: - // .next is the return type - - Parameters *parameters; // function parameters - int varargs; // 1: T t, ...) style for variable number of arguments - // 2: T t ...) style for variable number of arguments - bool isnothrow; // true: nothrow - bool isnogc; // true: is @nogc - bool isproperty; // can be called without parentheses - bool isref; // true: returns a reference - bool isreturn; // true: 'this' is returned by ref - bool isscope; // true: 'this' is scope - bool isscopeinferred; // true: 'this' is scope from inference - LINK linkage; // calling convention - TRUST trust; // level of trust - PURE purity; // PURExxxx - unsigned char iswild; // bit0: inout on params, bit1: inout on qualifier - Expressions *fargs; // function arguments - - int inuse; - - static TypeFunction *create(Parameters *parameters, Type *treturn, int varargs, LINK linkage, StorageClass stc = 0); - const char *kind(); - Type *syntaxCopy(); - void purityLevel(); - bool hasLazyParameters(); - bool parameterEscapes(Parameter *p); - StorageClass parameterStorageClass(Parameter *p); - Type *addStorageClass(StorageClass stc); - - Type *substWildTo(unsigned mod); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeDelegate : public TypeNext -{ -public: - // .next is a TypeFunction - - static TypeDelegate *create(Type *t); - const char *kind(); - Type *syntaxCopy(); - Type *addStorageClass(StorageClass stc); - d_uns64 size(const Loc &loc) /*const*/; - unsigned alignsize() /*const*/; - MATCH implicitConvTo(Type *to); - bool isZeroInit(const Loc &loc) /*const*/; - bool isBoolean() /*const*/; - bool hasPointers() /*const*/; - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeTraits : public Type -{ - Loc loc; - /// The expression to resolve as type or symbol. - TraitsExp *exp; - /// The symbol when exp doesn't represent a type. - Dsymbol *sym; - Type *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeQualified : public Type -{ -public: - Loc loc; - // array of Identifier and TypeInstance, - // representing ident.ident!tiargs.ident. ... etc. - Objects idents; - - void syntaxCopyHelper(TypeQualified *t); - void addIdent(Identifier *ident); - void addInst(TemplateInstance *inst); - void addIndex(RootObject *expr); - d_uns64 size(const Loc &loc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeIdentifier : public TypeQualified -{ -public: - Identifier *ident; - Dsymbol *originalSymbol; // The symbol representing this identifier, before alias resolution - - const char *kind(); - Type *syntaxCopy(); - Dsymbol *toDsymbol(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -/* Similar to TypeIdentifier, but with a TemplateInstance as the root - */ -class TypeInstance : public TypeQualified -{ -public: - TemplateInstance *tempinst; - - const char *kind(); - Type *syntaxCopy(); - Dsymbol *toDsymbol(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeTypeof : public TypeQualified -{ -public: - Expression *exp; - int inuse; - - const char *kind(); - Type *syntaxCopy(); - Dsymbol *toDsymbol(Scope *sc); - d_uns64 size(const Loc &loc); - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeReturn : public TypeQualified -{ -public: - const char *kind(); - Type *syntaxCopy(); - Dsymbol *toDsymbol(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -// Whether alias this dependency is recursive or not. -enum AliasThisRec -{ - RECno = 0, // no alias this recursion - RECyes = 1, // alias this has recursive dependency - RECfwdref = 2, // not yet known - RECtypeMask = 3,// mask to read no/yes/fwdref - - RECtracing = 0x4, // mark in progress of implicitConvTo/deduceWild - RECtracingDT = 0x8 // mark in progress of deduceType -}; - -class TypeStruct : public Type -{ -public: - StructDeclaration *sym; - AliasThisRec att; - CPPMANGLE cppmangle; - - static TypeStruct *create(StructDeclaration *sym); - const char *kind(); - d_uns64 size(const Loc &loc); - unsigned alignsize(); - Type *syntaxCopy(); - Dsymbol *toDsymbol(Scope *sc); - structalign_t alignment(); - Expression *defaultInitLiteral(const Loc &loc); - bool isZeroInit(const Loc &loc) /*const*/; - bool isAssignable(); - bool isBoolean() /*const*/; - bool needsDestruction() /*const*/; - bool needsNested(); - bool hasPointers(); - bool hasVoidInitPointers(); - MATCH implicitConvTo(Type *to); - MATCH constConv(Type *to); - unsigned char deduceWild(Type *t, bool isRef); - Type *toHeadMutable(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeEnum : public Type -{ -public: - EnumDeclaration *sym; - - const char *kind(); - Type *syntaxCopy(); - d_uns64 size(const Loc &loc); - unsigned alignsize(); - Dsymbol *toDsymbol(Scope *sc); - bool isintegral(); - bool isfloating(); - bool isreal(); - bool isimaginary(); - bool iscomplex(); - bool isscalar(); - bool isunsigned(); - bool isBoolean(); - bool isString(); - bool isAssignable(); - bool needsDestruction(); - bool needsNested(); - MATCH implicitConvTo(Type *to); - MATCH constConv(Type *to); - Type *toBasetype(); - bool isZeroInit(const Loc &loc); - bool hasPointers(); - bool hasVoidInitPointers(); - Type *nextOf(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeClass : public Type -{ -public: - ClassDeclaration *sym; - AliasThisRec att; - CPPMANGLE cppmangle; - - const char *kind(); - d_uns64 size(const Loc &loc) /*const*/; - Type *syntaxCopy(); - Dsymbol *toDsymbol(Scope *sc); - ClassDeclaration *isClassHandle(); - bool isBaseOf(Type *t, int *poffset); - MATCH implicitConvTo(Type *to); - MATCH constConv(Type *to); - unsigned char deduceWild(Type *t, bool isRef); - Type *toHeadMutable(); - bool isZeroInit(const Loc &loc) /*const*/; - bool isscope() /*const*/; - bool isBoolean() /*const*/; - bool hasPointers() /*const*/; - - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeTuple : public Type -{ -public: - Parameters *arguments; // types making up the tuple - - static TypeTuple *create(Parameters *arguments); - const char *kind(); - Type *syntaxCopy(); - bool equals(RootObject *o); - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeSlice : public TypeNext -{ -public: - Expression *lwr; - Expression *upr; - - const char *kind(); - Type *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -class TypeNull : public Type -{ -public: - const char *kind(); - - Type *syntaxCopy(); - MATCH implicitConvTo(Type *to); - bool isBoolean() /*const*/; - - d_uns64 size(const Loc &loc) /*const*/; - void accept(Visitor *v) { v->visit(this); } -}; - -/**************************************************************/ - -//enum InOut { None, In, Out, InOut, Lazy }; - -class Parameter : public RootObject -{ -public: - //enum InOut inout; - StorageClass storageClass; - Type *type; - Identifier *ident; - Expression *defaultArg; - UserAttributeDeclaration *userAttribDecl; // user defined attributes - - static Parameter *create(StorageClass storageClass, Type *type, Identifier *ident, - Expression *defaultArg, UserAttributeDeclaration *userAttribDecl); - Parameter *syntaxCopy(); - Type *isLazyArray(); - // kludge for template.isType() - int dyncast() const { return DYNCAST_PARAMETER; } - virtual void accept(Visitor *v) { v->visit(this); } - - static size_t dim(Parameters *parameters); - static Parameter *getNth(Parameters *parameters, d_size_t nth, d_size_t *pn = NULL); - const char *toChars(); - bool isCovariant(bool returnByRef, const Parameter *p) const; -}; - -bool arrayTypeCompatible(Loc loc, Type *t1, Type *t2); -bool arrayTypeCompatibleWithoutCasting(Type *t1, Type *t2); diff --git a/src/dmd/nspace.h b/src/dmd/nspace.h deleted file mode 100644 index c430af6e5643..000000000000 --- a/src/dmd/nspace.h +++ /dev/null @@ -1,35 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/nspace.h - */ - -#pragma once - -#include "dsymbol.h" - -/* A namespace corresponding to a C++ namespace. - * Implies extern(C++). - */ - -class Nspace : public ScopeDsymbol -{ - public: - bool mangleOnly; - Expression *identExp; - Dsymbol *syntaxCopy(Dsymbol *s); - void addMember(Scope *sc, ScopeDsymbol *sds); - void setScope(Scope *sc); - bool oneMember(Dsymbol **ps, Identifier *ident); - Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); - int apply(Dsymbol_apply_ft_t fp, void *param); - bool hasPointers(); - void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion); - const char *kind() const; - Nspace *isNspace() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/objc.h b/src/dmd/objc.h deleted file mode 100644 index 2e1c03231cec..000000000000 --- a/src/dmd/objc.h +++ /dev/null @@ -1,54 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 2015-2018 by The D Language Foundation, All Rights Reserved - * written by Michel Fortin - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/objc.h - */ - -#pragma once - -class AggregateDeclaration; -class FuncDeclaration; -class ClassDeclaration; -class InterfaceDeclaration; -struct Scope; - -struct ObjcSelector -{ - const char *stringvalue; - size_t stringlen; - size_t paramCount; - - static void _init(); - - ObjcSelector(const char *sv, size_t len, size_t pcount); - - static ObjcSelector *create(FuncDeclaration *fdecl); -}; - -struct ObjcClassDeclaration -{ - bool isMeta; - ClassDeclaration* metaclass; -}; - -class Objc -{ -public: - static void _init(); - - virtual void setObjc(ClassDeclaration* cd) = 0; - virtual void setObjc(InterfaceDeclaration*) = 0; - - virtual void setSelector(FuncDeclaration*, Scope* sc) = 0; - virtual void validateSelector(FuncDeclaration* fd) = 0; - virtual void checkLinkage(FuncDeclaration* fd) = 0; - virtual AggregateDeclaration* isThis(FuncDeclaration* fd) = 0; - - virtual void setMetaclass(InterfaceDeclaration* id) = 0; - virtual void setMetaclass(ClassDeclaration* id) = 0; - virtual ClassDeclaration* getRuntimeMetaclass(ClassDeclaration* cd) = 0; -}; diff --git a/src/dmd/scope.h b/src/dmd/scope.h deleted file mode 100644 index df98f37e73a2..000000000000 --- a/src/dmd/scope.h +++ /dev/null @@ -1,142 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/scope.h - */ - -#pragma once - -class Identifier; -class Module; -class Statement; -class SwitchStatement; -class TryFinallyStatement; -class LabelStatement; -class ForeachStatement; -class ClassDeclaration; -class AggregateDeclaration; -class FuncDeclaration; -class UserAttributeDeclaration; -struct DocComment; -struct AA; -class TemplateInstance; - -#include "dsymbol.h" - -#define CSXthis_ctor 1 // called this() -#define CSXsuper_ctor 2 // called super() -#define CSXthis 4 // referenced this -#define CSXsuper 8 // referenced super -#define CSXlabel 0x10 // seen a label -#define CSXreturn 0x20 // seen a return statement -#define CSXany_ctor 0x40 // either this() or super() was called -#define CSXhalt 0x80 // assert(0) - -// Flags that would not be inherited beyond scope nesting -#define SCOPEctor 0x0001 // constructor type -#define SCOPEcondition 0x0004 // inside static if/assert condition -#define SCOPEdebug 0x0008 // inside debug conditional - -// Flags that would be inherited beyond scope nesting -#define SCOPEnoaccesscheck 0x0002 // don't do access checks -#define SCOPEconstraint 0x0010 // inside template constraint -#define SCOPEinvariant 0x0020 // inside invariant code -#define SCOPErequire 0x0040 // inside in contract code -#define SCOPEensure 0x0060 // inside out contract code -#define SCOPEcontract 0x0060 // [mask] we're inside contract code -#define SCOPEctfe 0x0080 // inside a ctfe-only expression -#define SCOPEcompile 0x0100 // inside __traits(compile) -#define SCOPEignoresymbolvisibility 0x0200 // ignore symbol visibility (Bugzilla 15907) -#define SCOPEfullinst 0x1000 // fully instantiate templates - -#define SCOPEfree 0x8000 // is on free list - -struct Scope -{ - Scope *enclosing; // enclosing Scope - - Module *_module; // Root module - ScopeDsymbol *scopesym; // current symbol - FuncDeclaration *func; // function we are in - Dsymbol *parent; // parent to use - LabelStatement *slabel; // enclosing labelled statement - SwitchStatement *sw; // enclosing switch statement - TryFinallyStatement *tf; // enclosing try finally statement - OnScopeStatement *os; // enclosing scope(xxx) statement - Statement *sbreak; // enclosing statement that supports "break" - Statement *scontinue; // enclosing statement that supports "continue" - ForeachStatement *fes; // if nested function for ForeachStatement, this is it - Scope *callsc; // used for __FUNCTION__, __PRETTY_FUNCTION__ and __MODULE__ - bool inunion; // true if processing members of a union - bool nofree; // true if shouldn't free it - bool inLoop; // true if inside a loop (where constructor calls aren't allowed) - int intypeof; // in typeof(exp) - VarDeclaration *lastVar; // Previous symbol used to prevent goto-skips-init - - /* If minst && !tinst, it's in definitely non-speculative scope (eg. module member scope). - * If !minst && !tinst, it's in definitely speculative scope (eg. template constraint). - * If minst && tinst, it's in instantiated code scope without speculation. - * If !minst && tinst, it's in instantiated code scope with speculation. - */ - Module *minst; // root module where the instantiated templates should belong to - TemplateInstance *tinst; // enclosing template instance - - unsigned char callSuper; // primitive flow analysis for constructors - unsigned char *fieldinit; - size_t fieldinit_dim; - - AlignDeclaration *aligndecl; // alignment for struct members - - LINK linkage; // linkage for external functions - CPPMANGLE cppmangle; // C++ mangle type - PINLINE inlining; // inlining strategy for functions - - Prot protection; // protection for class members - int explicitProtection; // set if in an explicit protection attribute - - StorageClass stc; // storage class - - DeprecatedDeclaration *depdecl; // customized deprecation message - - unsigned flags; - - UserAttributeDeclaration *userAttribDecl; // user defined attributes - - DocComment *lastdc; // documentation comment for last symbol at this scope - AA *anchorCounts; // lookup duplicate anchor name count - Identifier *prevAnchor; // qualified symbol name of last doc anchor - - Scope(); - - Scope *copy(); - - Scope *push(); - Scope *push(ScopeDsymbol *ss); - Scope *pop(); - - Scope *startCTFE(); - Scope *endCTFE(); - - void mergeCallSuper(Loc loc, unsigned cs); - - unsigned *saveFieldInit(); - void mergeFieldInit(Loc loc, unsigned *cses); - - Module *instantiatingModule(); - - Dsymbol *search(Loc loc, Identifier *ident, Dsymbol **pscopesym, int flags = IgnoreNone); - Dsymbol *search_correct(Identifier *ident); - Dsymbol *insert(Dsymbol *s); - - ClassDeclaration *getClassScope(); - AggregateDeclaration *getStructClassScope(); - void setNoFree(); - - structalign_t alignment(); - - bool isDeprecated(); -}; diff --git a/src/dmd/statement.h b/src/dmd/statement.h deleted file mode 100644 index 7260009d6eaa..000000000000 --- a/src/dmd/statement.h +++ /dev/null @@ -1,722 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/statement.h - */ - -#pragma once - -#include "arraytypes.h" -#include "dsymbol.h" -#include "visitor.h" -#include "tokens.h" - -struct Scope; -class Expression; -class LabelDsymbol; -class Identifier; -class IfStatement; -class ExpStatement; -class DefaultStatement; -class VarDeclaration; -class Condition; -class ErrorStatement; -class ReturnStatement; -class CompoundStatement; -class Parameter; -class StaticAssert; -class AsmStatement; -class GotoStatement; -class ScopeStatement; -class TryCatchStatement; -class TryFinallyStatement; -class CaseStatement; -class DefaultStatement; -class LabelStatement; -class StaticForeach; - -// Back end -struct code; - -bool inferAggregate(ForeachStatement *fes, Scope *sc, Dsymbol *&sapply); -bool inferApplyArgTypes(ForeachStatement *fes, Scope *sc, Dsymbol *&sapply); - -/* How a statement exits; this is returned by blockExit() - */ -enum BE -{ - BEnone = 0, - BEfallthru = 1, - BEthrow = 2, - BEreturn = 4, - BEgoto = 8, - BEhalt = 0x10, - BEbreak = 0x20, - BEcontinue = 0x40, - BEerrthrow = 0x80, - BEany = (BEfallthru | BEthrow | BEreturn | BEgoto | BEhalt) -}; - -class Statement : public RootObject -{ -public: - Loc loc; - - virtual Statement *syntaxCopy(); - - const char *toChars(); - - void error(const char *format, ...); - void warning(const char *format, ...); - void deprecation(const char *format, ...); - virtual Statement *getRelatedLabeled() { return this; } - virtual bool hasBreak(); - virtual bool hasContinue(); - bool usesEH(); - bool comeFrom(); - bool hasCode(); - virtual Statement *scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally); - virtual Statements *flatten(Scope *sc); - virtual Statement *last(); - - // Avoid dynamic_cast - virtual ErrorStatement *isErrorStatement() { return NULL; } - virtual ScopeStatement *isScopeStatement() { return NULL; } - virtual ExpStatement *isExpStatement() { return NULL; } - virtual CompoundStatement *isCompoundStatement() { return NULL; } - virtual ReturnStatement *isReturnStatement() { return NULL; } - virtual IfStatement *isIfStatement() { return NULL; } - virtual CaseStatement *isCaseStatement() { return NULL; } - virtual DefaultStatement *isDefaultStatement() { return NULL; } - virtual LabelStatement *isLabelStatement() { return NULL; } - virtual GotoDefaultStatement *isGotoDefaultStatement() { return NULL; } - virtual GotoCaseStatement *isGotoCaseStatement() { return NULL; } - virtual BreakStatement *isBreakStatement() { return NULL; } - virtual DtorExpStatement *isDtorExpStatement() { return NULL; } - virtual ForwardingStatement *isForwardingStatement() { return NULL; } - virtual void accept(Visitor *v) { v->visit(this); } -}; - -/** Any Statement that fails semantic() or has a component that is an ErrorExp or - * a TypeError should return an ErrorStatement from semantic(). - */ -class ErrorStatement : public Statement -{ -public: - Statement *syntaxCopy(); - - ErrorStatement *isErrorStatement() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class PeelStatement : public Statement -{ -public: - Statement *s; - - void accept(Visitor *v) { v->visit(this); } -}; - -class ExpStatement : public Statement -{ -public: - Expression *exp; - - static ExpStatement *create(Loc loc, Expression *exp); - Statement *syntaxCopy(); - Statement *scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally); - Statements *flatten(Scope *sc); - - ExpStatement *isExpStatement() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class DtorExpStatement : public ExpStatement -{ -public: - /* Wraps an expression that is the destruction of 'var' - */ - - VarDeclaration *var; - - Statement *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } - - DtorExpStatement *isDtorExpStatement() { return this; } -}; - -class CompileStatement : public Statement -{ -public: - Expressions *exps; - - Statement *syntaxCopy(); - Statements *flatten(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class CompoundStatement : public Statement -{ -public: - Statements *statements; - - static CompoundStatement *create(Loc loc, Statement *s1, Statement *s2); - Statement *syntaxCopy(); - Statements *flatten(Scope *sc); - ReturnStatement *isReturnStatement(); - Statement *last(); - - CompoundStatement *isCompoundStatement() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class CompoundDeclarationStatement : public CompoundStatement -{ -public: - Statement *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -/* The purpose of this is so that continue will go to the next - * of the statements, and break will go to the end of the statements. - */ -class UnrolledLoopStatement : public Statement -{ -public: - Statements *statements; - - Statement *syntaxCopy(); - bool hasBreak(); - bool hasContinue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ScopeStatement : public Statement -{ -public: - Statement *statement; - Loc endloc; // location of closing curly bracket - - Statement *syntaxCopy(); - ScopeStatement *isScopeStatement() { return this; } - ReturnStatement *isReturnStatement(); - bool hasBreak(); - bool hasContinue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ForwardingStatement : public Statement -{ - ForwardingScopeDsymbol *sym; - Statement *statement; - - Statement *syntaxCopy(); - Statements *flatten(Scope *sc); - ForwardingStatement *isForwardingStatement() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class WhileStatement : public Statement -{ -public: - Expression *condition; - Statement *_body; - Loc endloc; // location of closing curly bracket - - Statement *syntaxCopy(); - bool hasBreak(); - bool hasContinue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class DoStatement : public Statement -{ -public: - Statement *_body; - Expression *condition; - Loc endloc; // location of ';' after while - - Statement *syntaxCopy(); - bool hasBreak(); - bool hasContinue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ForStatement : public Statement -{ -public: - Statement *_init; - Expression *condition; - Expression *increment; - Statement *_body; - Loc endloc; // location of closing curly bracket - - // When wrapped in try/finally clauses, this points to the outermost one, - // which may have an associated label. Internal break/continue statements - // treat that label as referring to this loop. - Statement *relatedLabeled; - - Statement *syntaxCopy(); - Statement *scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally); - Statement *getRelatedLabeled() { return relatedLabeled ? relatedLabeled : this; } - bool hasBreak(); - bool hasContinue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ForeachStatement : public Statement -{ -public: - TOK op; // TOKforeach or TOKforeach_reverse - Parameters *parameters; // array of Parameter*'s - Expression *aggr; - Statement *_body; - Loc endloc; // location of closing curly bracket - - VarDeclaration *key; - VarDeclaration *value; - - FuncDeclaration *func; // function we're lexically in - - Statements *cases; // put breaks, continues, gotos and returns here - ScopeStatements *gotos; // forward referenced goto's go here - - Statement *syntaxCopy(); - bool hasBreak(); - bool hasContinue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ForeachRangeStatement : public Statement -{ -public: - TOK op; // TOKforeach or TOKforeach_reverse - Parameter *prm; // loop index variable - Expression *lwr; - Expression *upr; - Statement *_body; - Loc endloc; // location of closing curly bracket - - VarDeclaration *key; - - Statement *syntaxCopy(); - bool hasBreak(); - bool hasContinue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class IfStatement : public Statement -{ -public: - Parameter *prm; - Expression *condition; - Statement *ifbody; - Statement *elsebody; - VarDeclaration *match; // for MatchExpression results - Loc endloc; // location of closing curly bracket - - Statement *syntaxCopy(); - IfStatement *isIfStatement() { return this; } - - void accept(Visitor *v) { v->visit(this); } -}; - -class ConditionalStatement : public Statement -{ -public: - Condition *condition; - Statement *ifbody; - Statement *elsebody; - - Statement *syntaxCopy(); - Statements *flatten(Scope *sc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class StaticForeachStatement : public Statement -{ -public: - StaticForeach *sfe; - - Statement *syntaxCopy(); - Statements *flatten(Scope *sc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class PragmaStatement : public Statement -{ -public: - Identifier *ident; - Expressions *args; // array of Expression's - Statement *_body; - - Statement *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class StaticAssertStatement : public Statement -{ -public: - StaticAssert *sa; - - Statement *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class SwitchStatement : public Statement -{ -public: - Expression *condition; - Statement *_body; - bool isFinal; - - DefaultStatement *sdefault; - TryFinallyStatement *tf; - GotoCaseStatements gotoCases; // array of unresolved GotoCaseStatement's - CaseStatements *cases; // array of CaseStatement's - int hasNoDefault; // !=0 if no default statement - int hasVars; // !=0 if has variable case values - VarDeclaration *lastVar; - - Statement *syntaxCopy(); - bool hasBreak(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class CaseStatement : public Statement -{ -public: - Expression *exp; - Statement *statement; - - int index; // which case it is (since we sort this) - VarDeclaration *lastVar; - - Statement *syntaxCopy(); - int compare(RootObject *obj); - CaseStatement *isCaseStatement() { return this; } - - void accept(Visitor *v) { v->visit(this); } -}; - - -class CaseRangeStatement : public Statement -{ -public: - Expression *first; - Expression *last; - Statement *statement; - - Statement *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - - -class DefaultStatement : public Statement -{ -public: - Statement *statement; - VarDeclaration *lastVar; - - Statement *syntaxCopy(); - DefaultStatement *isDefaultStatement() { return this; } - - void accept(Visitor *v) { v->visit(this); } -}; - -class GotoDefaultStatement : public Statement -{ -public: - SwitchStatement *sw; - - Statement *syntaxCopy(); - GotoDefaultStatement *isGotoDefaultStatement() { return this; } - - void accept(Visitor *v) { v->visit(this); } -}; - -class GotoCaseStatement : public Statement -{ -public: - Expression *exp; // NULL, or which case to goto - CaseStatement *cs; // case statement it resolves to - - Statement *syntaxCopy(); - GotoCaseStatement *isGotoCaseStatement() { return this; } - - void accept(Visitor *v) { v->visit(this); } -}; - -class SwitchErrorStatement : public Statement -{ -public: - Expression *exp; - - void accept(Visitor *v) { v->visit(this); } -}; - -class ReturnStatement : public Statement -{ -public: - Expression *exp; - size_t caseDim; - - Statement *syntaxCopy(); - - ReturnStatement *isReturnStatement() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class BreakStatement : public Statement -{ -public: - Identifier *ident; - - Statement *syntaxCopy(); - - BreakStatement *isBreakStatement() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class ContinueStatement : public Statement -{ -public: - Identifier *ident; - - Statement *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class SynchronizedStatement : public Statement -{ -public: - Expression *exp; - Statement *_body; - - Statement *syntaxCopy(); - bool hasBreak(); - bool hasContinue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class WithStatement : public Statement -{ -public: - Expression *exp; - Statement *_body; - VarDeclaration *wthis; - Loc endloc; - - Statement *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class TryCatchStatement : public Statement -{ -public: - Statement *_body; - Catches *catches; - - Statement *syntaxCopy(); - bool hasBreak(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class Catch : public RootObject -{ -public: - Loc loc; - Type *type; - Identifier *ident; - VarDeclaration *var; - Statement *handler; - - // set if semantic processing errors - bool errors; - - // was generated by the compiler, - // wasn't present in source code - bool internalCatch; - - Catch *syntaxCopy(); -}; - -class TryFinallyStatement : public Statement -{ -public: - Statement *_body; - Statement *finalbody; - - bool bodyFallsThru; // true if _body falls through to finally - - static TryFinallyStatement *create(Loc loc, Statement *body, Statement *finalbody); - Statement *syntaxCopy(); - bool hasBreak(); - bool hasContinue(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class OnScopeStatement : public Statement -{ -public: - TOK tok; - Statement *statement; - - Statement *syntaxCopy(); - Statement *scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ThrowStatement : public Statement -{ -public: - Expression *exp; - // was generated by the compiler, - // wasn't present in source code - bool internalThrow; - - Statement *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class DebugStatement : public Statement -{ -public: - Statement *statement; - - Statement *syntaxCopy(); - Statements *flatten(Scope *sc); - void accept(Visitor *v) { v->visit(this); } -}; - -class GotoStatement : public Statement -{ -public: - Identifier *ident; - LabelDsymbol *label; - TryFinallyStatement *tf; - OnScopeStatement *os; - VarDeclaration *lastVar; - - Statement *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; - -class LabelStatement : public Statement -{ -public: - Identifier *ident; - Statement *statement; - TryFinallyStatement *tf; - OnScopeStatement *os; - VarDeclaration *lastVar; - Statement *gotoTarget; // interpret - - bool breaks; // someone did a 'break ident' - - Statement *syntaxCopy(); - Statements *flatten(Scope *sc); - Statement *scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally); - - LabelStatement *isLabelStatement() { return this; } - - void accept(Visitor *v) { v->visit(this); } -}; - -class LabelDsymbol : public Dsymbol -{ -public: - LabelStatement *statement; - - static LabelDsymbol *create(Identifier *ident); - LabelDsymbol *isLabel(); - void accept(Visitor *v) { v->visit(this); } -}; - -Statement* asmSemantic(AsmStatement *s, Scope *sc); - -class AsmStatement : public Statement -{ -public: - Token *tokens; - - Statement *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -class InlineAsmStatement : public AsmStatement -{ -public: - code *asmcode; - unsigned asmalign; // alignment of this statement - unsigned regs; // mask of registers modified (must match regm_t in back end) - bool refparam; // true if function parameter is referenced - bool naked; // true if function is to be naked - - Statement *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -// A GCC asm statement - assembler instructions with D expression operands -class GccAsmStatement : public AsmStatement -{ -public: - StorageClass stc; // attributes of the asm {} block - Expression *insn; // string expression that is the template for assembler code - Expressions *args; // input and output operands of the statement - unsigned outputargs; // of the operands in 'args', the number of output operands - Identifiers *names; // list of symbolic names for the operands - Expressions *constraints; // list of string constants specifying constraints on operands - Expressions *clobbers; // list of string constants specifying clobbers and scratch registers - Identifiers *labels; // list of goto labels - GotoStatements *gotos; // of the goto labels, the equivalent statements they represent - - Statement *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -// a complete asm {} block -class CompoundAsmStatement : public CompoundStatement -{ -public: - StorageClass stc; // postfix attributes like nothrow/pure/@trusted - - CompoundAsmStatement *syntaxCopy(); - Statements *flatten(Scope *sc); - - void accept(Visitor *v) { v->visit(this); } -}; - -class ImportStatement : public Statement -{ -public: - Dsymbols *imports; // Array of Import's - - Statement *syntaxCopy(); - - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/staticassert.h b/src/dmd/staticassert.h deleted file mode 100644 index 2d4293211df9..000000000000 --- a/src/dmd/staticassert.h +++ /dev/null @@ -1,28 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/staticassert.h - */ - -#pragma once - -#include "dsymbol.h" - -class Expression; - -class StaticAssert : public Dsymbol -{ -public: - Expression *exp; - Expression *msg; - - Dsymbol *syntaxCopy(Dsymbol *s); - void addMember(Scope *sc, ScopeDsymbol *sds); - bool oneMember(Dsymbol **ps, Identifier *ident); - const char *kind() const; - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/dmd/target.h b/src/dmd/target.h deleted file mode 100644 index 85e25f5d9282..000000000000 --- a/src/dmd/target.h +++ /dev/null @@ -1,86 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 2013-2018 by The D Language Foundation, All Rights Reserved - * written by Iain Buclaw - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/target.h - */ - -#pragma once - -// This file contains a data structure that describes a back-end target. -// At present it is incomplete, but in future it should grow to contain -// most or all target machine and target O/S specific information. -#include "globals.h" -#include "tokens.h" - -class ClassDeclaration; -class Dsymbol; -class Expression; -class Parameter; -class Type; -class TypeTuple; -class TypeFunction; - -struct Target -{ - // D ABI - static unsigned ptrsize; - static unsigned realsize; // size a real consumes in memory - static unsigned realpad; // 'padding' added to the CPU real size to bring it up to realsize - static unsigned realalignsize; // alignment for reals - static unsigned classinfosize; // size of 'ClassInfo' - static unsigned long long maxStaticDataSize; // maximum size of static data - - // C ABI - static unsigned c_longsize; // size of a C 'long' or 'unsigned long' type - static unsigned c_long_doublesize; // size of a C 'long double' - - // C++ ABI - static bool reverseCppOverloads; // with dmc and cl, overloaded functions are grouped and in reverse order - static bool cppExceptions; // set if catching C++ exceptions is supported - static bool twoDtorInVtable; // target C++ ABI puts deleting and non-deleting destructor into vtable - - template - struct FPTypeProperties - { - static real_t max; - static real_t min_normal; - static real_t nan; - static real_t snan; - static real_t infinity; - static real_t epsilon; - - static d_int64 dig; - static d_int64 mant_dig; - static d_int64 max_exp; - static d_int64 min_exp; - static d_int64 max_10_exp; - static d_int64 min_10_exp; - }; - - typedef FPTypeProperties FloatProperties; - typedef FPTypeProperties DoubleProperties; - typedef FPTypeProperties RealProperties; - - static void _init(); - // Type sizes and support. - static unsigned alignsize(Type *type); - static unsigned fieldalign(Type *type); - static unsigned critsecsize(); - static Type *va_listType(); // get type of va_list - static int isVectorTypeSupported(int sz, Type *type); - static bool isVectorOpSupported(Type *type, TOK op, Type *t2 = NULL); - // ABI and backend. - static const char *toCppMangle(Dsymbol *s); - static const char *cppTypeInfoMangle(ClassDeclaration *cd); - static const char *cppTypeMangle(Type *t); - static Type *cppParameterType(Parameter *p); - static LINK systemLinkage(); - static TypeTuple *toArgTypes(Type *t); - static bool isReturnOnStack(TypeFunction *tf, bool needsThis); - static d_uns64 parameterSize(const Loc& loc, Type *t); - static Expression *getTargetInfo(const char* name, const Loc& loc); -}; diff --git a/src/dmd/template.h b/src/dmd/template.h deleted file mode 100644 index c915f13d7dc9..000000000000 --- a/src/dmd/template.h +++ /dev/null @@ -1,329 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/template.h - */ - -#pragma once - -#include "arraytypes.h" -#include "dsymbol.h" - -class Identifier; -class TemplateInstance; -class TemplateParameter; -class TemplateTypeParameter; -class TemplateThisParameter; -class TemplateValueParameter; -class TemplateAliasParameter; -class TemplateTupleParameter; -class Type; -class TypeQualified; -struct Scope; -class Expression; -class FuncDeclaration; -class Parameter; - -class Tuple : public RootObject -{ -public: - Objects objects; - - // kludge for template.isType() - int dyncast() const { return DYNCAST_TUPLE; } - - const char *toChars() { return objects.toChars(); } -}; - -struct TemplatePrevious -{ - TemplatePrevious *prev; - Scope *sc; - Objects *dedargs; -}; - -class TemplateDeclaration : public ScopeDsymbol -{ -public: - TemplateParameters *parameters; // array of TemplateParameter's - - TemplateParameters *origParameters; // originals for Ddoc - Expression *constraint; - - // Hash table to look up TemplateInstance's of this TemplateDeclaration - void *instances; - - TemplateDeclaration *overnext; // next overloaded TemplateDeclaration - TemplateDeclaration *overroot; // first in overnext list - FuncDeclaration *funcroot; // first function in unified overload list - - Dsymbol *onemember; // if !=NULL then one member of this template - - bool literal; // this template declaration is a literal - bool ismixin; // template declaration is only to be used as a mixin - bool isstatic; // this is static template declaration - Prot protection; - int inuse; // for recursive expansion detection - - TemplatePrevious *previous; // threaded list of previous instantiation attempts on stack - - Dsymbol *syntaxCopy(Dsymbol *); - bool overloadInsert(Dsymbol *s); - bool hasStaticCtorOrDtor(); - const char *kind() const; - const char *toChars(); - - Prot prot(); - - MATCH leastAsSpecialized(Scope *sc, TemplateDeclaration *td2, Expressions *fargs); - RootObject *declareParameter(Scope *sc, TemplateParameter *tp, RootObject *o); - - TemplateDeclaration *isTemplateDeclaration() { return this; } - - TemplateTupleParameter *isVariadic(); - bool isOverloadable(); - - void accept(Visitor *v) { v->visit(this); } -}; - -/* For type-parameter: - * template Foo(ident) // specType is set to NULL - * template Foo(ident : specType) - * For value-parameter: - * template Foo(valType ident) // specValue is set to NULL - * template Foo(valType ident : specValue) - * For alias-parameter: - * template Foo(alias ident) - * For this-parameter: - * template Foo(this ident) - */ -class TemplateParameter : public RootObject -{ -public: - Loc loc; - Identifier *ident; - - /* True if this is a part of precedent parameter specialization pattern. - * - * template A(T : X!TL, alias X, TL...) {} - * // X and TL are dependent template parameter - * - * A dependent template parameter should return MATCHexact in matchArg() - * to respect the match level of the corresponding precedent parameter. - */ - bool dependent; - - virtual TemplateTypeParameter *isTemplateTypeParameter(); - virtual TemplateValueParameter *isTemplateValueParameter(); - virtual TemplateAliasParameter *isTemplateAliasParameter(); - virtual TemplateThisParameter *isTemplateThisParameter(); - virtual TemplateTupleParameter *isTemplateTupleParameter(); - - virtual TemplateParameter *syntaxCopy() = 0; - virtual bool declareParameter(Scope *sc) = 0; - virtual void print(RootObject *oarg, RootObject *oded) = 0; - virtual RootObject *specialization() = 0; - virtual RootObject *defaultArg(Loc instLoc, Scope *sc) = 0; - virtual bool hasDefaultArg() = 0; - - /* Match actual argument against parameter. - */ - virtual MATCH matchArg(Loc instLoc, Scope *sc, Objects *tiargs, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); - virtual MATCH matchArg(Scope *sc, RootObject *oarg, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam) = 0; - - /* Create dummy argument based on parameter. - */ - virtual void *dummyArg() = 0; - virtual void accept(Visitor *v) { v->visit(this); } -}; - -/* Syntax: - * ident : specType = defaultType - */ -class TemplateTypeParameter : public TemplateParameter -{ - using TemplateParameter::matchArg; -public: - Type *specType; // type parameter: if !=NULL, this is the type specialization - Type *defaultType; - - TemplateTypeParameter *isTemplateTypeParameter(); - TemplateParameter *syntaxCopy(); - bool declareParameter(Scope *sc); - void print(RootObject *oarg, RootObject *oded); - RootObject *specialization(); - RootObject *defaultArg(Loc instLoc, Scope *sc); - bool hasDefaultArg(); - MATCH matchArg(Scope *sc, RootObject *oarg, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); - void *dummyArg(); - void accept(Visitor *v) { v->visit(this); } -}; - -/* Syntax: - * this ident : specType = defaultType - */ -class TemplateThisParameter : public TemplateTypeParameter -{ -public: - TemplateThisParameter *isTemplateThisParameter(); - TemplateParameter *syntaxCopy(); - void accept(Visitor *v) { v->visit(this); } -}; - -/* Syntax: - * valType ident : specValue = defaultValue - */ -class TemplateValueParameter : public TemplateParameter -{ - using TemplateParameter::matchArg; -public: - Type *valType; - Expression *specValue; - Expression *defaultValue; - - TemplateValueParameter *isTemplateValueParameter(); - TemplateParameter *syntaxCopy(); - bool declareParameter(Scope *sc); - void print(RootObject *oarg, RootObject *oded); - RootObject *specialization(); - RootObject *defaultArg(Loc instLoc, Scope *sc); - bool hasDefaultArg(); - MATCH matchArg(Scope *sc, RootObject *oarg, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); - void *dummyArg(); - void accept(Visitor *v) { v->visit(this); } -}; - -/* Syntax: - * specType ident : specAlias = defaultAlias - */ -class TemplateAliasParameter : public TemplateParameter -{ - using TemplateParameter::matchArg; -public: - Type *specType; - RootObject *specAlias; - RootObject *defaultAlias; - - TemplateAliasParameter *isTemplateAliasParameter(); - TemplateParameter *syntaxCopy(); - bool declareParameter(Scope *sc); - void print(RootObject *oarg, RootObject *oded); - RootObject *specialization(); - RootObject *defaultArg(Loc instLoc, Scope *sc); - bool hasDefaultArg(); - MATCH matchArg(Scope *sc, RootObject *oarg, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); - void *dummyArg(); - void accept(Visitor *v) { v->visit(this); } -}; - -/* Syntax: - * ident ... - */ -class TemplateTupleParameter : public TemplateParameter -{ -public: - TemplateTupleParameter *isTemplateTupleParameter(); - TemplateParameter *syntaxCopy(); - bool declareParameter(Scope *sc); - void print(RootObject *oarg, RootObject *oded); - RootObject *specialization(); - RootObject *defaultArg(Loc instLoc, Scope *sc); - bool hasDefaultArg(); - MATCH matchArg(Loc loc, Scope *sc, Objects *tiargs, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); - MATCH matchArg(Scope *sc, RootObject *oarg, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); - void *dummyArg(); - void accept(Visitor *v) { v->visit(this); } -}; - -/* Given: - * foo!(args) => - * name = foo - * tiargs = args - */ -class TemplateInstance : public ScopeDsymbol -{ -public: - Identifier *name; - - // Array of Types/Expressions of template - // instance arguments [int*, char, 10*10] - Objects *tiargs; - - // Array of Types/Expressions corresponding - // to TemplateDeclaration.parameters - // [int, char, 100] - Objects tdtypes; - - Dsymbol *tempdecl; // referenced by foo.bar.abc - Dsymbol *enclosing; // if referencing local symbols, this is the context - Dsymbol *aliasdecl; // !=NULL if instance is an alias for its sole member - TemplateInstance *inst; // refer to existing instance - ScopeDsymbol *argsym; // argument symbol table - int inuse; // for recursive expansion detection - int nest; // for recursive pretty printing detection - bool semantictiargsdone; // has semanticTiargs() been done? - bool havetempdecl; // if used second constructor - bool gagged; // if the instantiation is done with error gagging - hash_t hash; // cached result of toHash() - Expressions *fargs; // for function template, these are the function arguments - - TemplateInstances* deferred; - - Module *memberOf; // if !null, then this TemplateInstance appears in memberOf.members[] - - // Used to determine the instance needs code generation. - // Note that these are inaccurate until semantic analysis phase completed. - TemplateInstance *tinst; // enclosing template instance - TemplateInstance *tnext; // non-first instantiated instances - Module *minst; // the top module that instantiated this instance - - Dsymbol *syntaxCopy(Dsymbol *); - Dsymbol *toAlias(); // resolve real symbol - const char *kind() const; - bool oneMember(Dsymbol **ps, Identifier *ident); - const char *toChars(); - const char* toPrettyCharsHelper(); - void printInstantiationTrace(); - Identifier *getIdent(); - int compare(RootObject *o); - hash_t toHash(); - - bool needsCodegen(); - - TemplateInstance *isTemplateInstance() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -class TemplateMixin : public TemplateInstance -{ -public: - TypeQualified *tqual; - - Dsymbol *syntaxCopy(Dsymbol *s); - const char *kind() const; - bool oneMember(Dsymbol **ps, Identifier *ident); - int apply(Dsymbol_apply_ft_t fp, void *param); - bool hasPointers(); - void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion); - const char *toChars(); - - TemplateMixin *isTemplateMixin() { return this; } - void accept(Visitor *v) { v->visit(this); } -}; - -Expression *isExpression(RootObject *o); -Dsymbol *isDsymbol(RootObject *o); -Type *isType(RootObject *o); -Tuple *isTuple(RootObject *o); -Parameter *isParameter(RootObject *o); -TemplateParameter *isTemplateParameter(RootObject *o); -bool arrayObjectIsError(const Objects *args); -bool isError(const RootObject *const o); -Type *getType(RootObject *o); -Dsymbol *getDsymbol(RootObject *o); - -RootObject *objectSyntaxCopy(RootObject *o); diff --git a/src/dmd/tokens.h b/src/dmd/tokens.h deleted file mode 100644 index 69a296da18a7..000000000000 --- a/src/dmd/tokens.h +++ /dev/null @@ -1,230 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/tokens.h - */ - -#pragma once - -#include "root/port.h" -#include "globals.h" - -class Identifier; - -/* Tokens: - ( ) - [ ] - { } - < > <= >= == != === !== - << >> <<= >>= >>> >>>= - + - += -= - * / % *= /= %= - & | ^ &= |= ^= - = ! ~ @ - ^^ ^^= - ++ -- - . -> : , => - ? && || - */ - -enum TOK -{ - TOKreserved, - - // Other - TOKlparen, TOKrparen, - TOKlbracket, TOKrbracket, - TOKlcurly, TOKrcurly, - TOKcolon, TOKneg, - TOKsemicolon, TOKdotdotdot, - TOKeof, TOKcast, - TOKnull, TOKassert, - TOKtrue, TOKfalse, - TOKarray, TOKcall, - TOKaddress, - TOKtype, TOKthrow, - TOKnew, TOKdelete, - TOKstar, TOKsymoff, - TOKvar, TOKdotvar, - TOKdotid, TOKdotti, - TOKdottype, TOKslice, - TOKarraylength, TOKversion, - TOKmodule, TOKdollar, - TOKtemplate, TOKdottd, - TOKdeclaration, TOKtypeof, - TOKpragma, TOKdsymbol, - TOKtypeid, TOKuadd, - TOKremove, - TOKnewanonclass, TOKcomment, - TOKarrayliteral, TOKassocarrayliteral, - TOKstructliteral, - TOKclassreference, - TOKthrownexception, - TOKdelegateptr, - TOKdelegatefuncptr, - -// 54 - // Operators - TOKlt, TOKgt, - TOKle, TOKge, - TOKequal, TOKnotequal, - TOKidentity, TOKnotidentity, - TOKindex, TOKis, - -// 64 - TOKshl, TOKshr, - TOKshlass, TOKshrass, - TOKushr, TOKushrass, - TOKcat, TOKcatass, TOKcatelemass, TOKcatdcharass, // ~ ~= - TOKadd, TOKmin, TOKaddass, TOKminass, - TOKmul, TOKdiv, TOKmod, - TOKmulass, TOKdivass, TOKmodass, - TOKand, TOKor, TOKxor, - TOKandass, TOKorass, TOKxorass, - TOKassign, TOKnot, TOKtilde, - TOKplusplus, TOKminusminus, TOKconstruct, TOKblit, - TOKdot, TOKarrow, TOKcomma, - TOKquestion, TOKandand, TOKoror, - TOKpreplusplus, TOKpreminusminus, - -// 105 - // Numeric literals - TOKint32v, TOKuns32v, - TOKint64v, TOKuns64v, - TOKint128v, TOKuns128v, - TOKfloat32v, TOKfloat64v, TOKfloat80v, - TOKimaginary32v, TOKimaginary64v, TOKimaginary80v, - - // Char constants - TOKcharv, TOKwcharv, TOKdcharv, - - // Leaf operators - TOKidentifier, TOKstring, TOKxstring, - TOKthis, TOKsuper, - TOKhalt, TOKtuple, - TOKerror, - - // Basic types - TOKvoid, - TOKint8, TOKuns8, - TOKint16, TOKuns16, - TOKint32, TOKuns32, - TOKint64, TOKuns64, - TOKint128, TOKuns128, - TOKfloat32, TOKfloat64, TOKfloat80, - TOKimaginary32, TOKimaginary64, TOKimaginary80, - TOKcomplex32, TOKcomplex64, TOKcomplex80, - TOKchar, TOKwchar, TOKdchar, TOKbool, - -// 152 - // Aggregates - TOKstruct, TOKclass, TOKinterface, TOKunion, TOKenum, TOKimport, - TOKalias, TOKoverride, TOKdelegate, TOKfunction, - TOKmixin, - - TOKalign, TOKextern, TOKprivate, TOKprotected, TOKpublic, TOKexport, - TOKstatic, TOKfinal, TOKconst, TOKabstract, - TOKdebug, TOKdeprecated, TOKin, TOKout, TOKinout, TOKlazy, - TOKauto, TOKpackage, TOKmanifest, TOKimmutable, - -// 183 - // Statements - TOKif, TOKelse, TOKwhile, TOKfor, TOKdo, TOKswitch, - TOKcase, TOKdefault, TOKbreak, TOKcontinue, TOKwith, - TOKsynchronized, TOKreturn, TOKgoto, TOKtry, TOKcatch, TOKfinally, - TOKasm, TOKforeach, TOKforeach_reverse, - TOKscope, - TOKon_scope_exit, TOKon_scope_failure, TOKon_scope_success, - -// 207 - // Contracts - TOKinvariant, - - // Testing - TOKunittest, - - // Added after 1.0 - TOKargTypes, - TOKref, - TOKmacro, - -// 212 - TOKparameters, - TOKtraits, - TOKoverloadset, - TOKpure, - TOKnothrow, - TOKgshared, - TOKline, - TOKfile, - TOKfilefullpath, - TOKmodulestring, - TOKfuncstring, - TOKprettyfunc, - TOKshared, - TOKat, - TOKpow, - TOKpowass, - TOKgoesto, - TOKvector, - TOKpound, - -// 231 - TOKinterval, - TOKvoidexp, - TOKcantexp, - TOKshowctfecontext, - - TOKobjc_class_reference, - - TOKMAX -}; - -#define TOKwild TOKinout - -// Token has an anonymous struct, which is not strict ISO C++. -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" -#endif - -struct Token -{ - Token *next; - Loc loc; - const utf8_t *ptr; // pointer to first character of this token within buffer - TOK value; - const utf8_t *blockComment; // doc comment string prior to this token - const utf8_t *lineComment; // doc comment for previous token - union - { - // Integers - sinteger_t intvalue; - uinteger_t unsvalue; - - // Floats - real_t floatvalue; - - struct - { utf8_t *ustring; // UTF8 string - unsigned len; - unsigned char postfix; // 'c', 'w', 'd' - }; - - Identifier *ident; - }; - - void free(); - - Token() : next(NULL) {} - int isKeyword(); - const char *toChars() const; -}; - -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif diff --git a/src/dmd/version.h b/src/dmd/version.h deleted file mode 100644 index 94ec38abe44d..000000000000 --- a/src/dmd/version.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Compiler implementation of the D programming language - * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved - * written by Walter Bright - * http://www.digitalmars.com - * Distributed under the Boost Software License, Version 1.0. - * http://www.boost.org/LICENSE_1_0.txt - * https://github.com/dlang/dmd/blob/master/src/dmd/version.h - */ - -#pragma once - -#include "dsymbol.h" - -class DebugSymbol : public Dsymbol -{ -public: - unsigned level; - - Dsymbol *syntaxCopy(Dsymbol *); - - const char *toChars(); - void addMember(Scope *sc, ScopeDsymbol *sds); - const char *kind() const; - void accept(Visitor *v) { v->visit(this); } -}; - -class VersionSymbol : public Dsymbol -{ -public: - unsigned level; - - Dsymbol *syntaxCopy(Dsymbol *); - - const char *toChars(); - void addMember(Scope *sc, ScopeDsymbol *sds); - const char *kind() const; - void accept(Visitor *v) { v->visit(this); } -}; diff --git a/src/posix.mak b/src/posix.mak index c8870ac4520b..d11232b842c8 100644 --- a/src/posix.mak +++ b/src/posix.mak @@ -412,13 +412,8 @@ TK_SRC = \ ######## CXX header files (only needed for cxx-unittest) -SRC = $(addprefix $D/, aggregate.h aliasthis.h arraytypes.h \ - attrib.h compiler.h complex_t.h cond.h ctfe.h ctfe.h declaration.h doc.h dsymbol.h \ - enum.h errors.h expression.h globals.h hdrgen.h identifier.h \ - id.h import.h init.h json.h \ - mangle.h mars.h module.h mtype.h nspace.h objc.h \ - scope.h statement.h staticassert.h target.h template.h tokens.h \ - version.h visitor.h libomf.d scanomf.d libmscoff.d scanmscoff.d) \ +SRC = $(addprefix $D/, complex_t.h compiler.h errors.h globals.h mars.h \ + visitor.h libomf.d scanomf.d libmscoff.d scanmscoff.d) \ $(DMD_SRCS) ROOT_SRC = $(addprefix $(ROOT)/, array.h ctfloat.h dcompat.h file.h filename.h \ From baa47778b6f6db3f39c4336491bdf472c284259b Mon Sep 17 00:00:00 2001 From: Nicholas Lindsay Wilson Date: Sun, 18 Nov 2018 13:54:44 +0800 Subject: [PATCH 5/7] Improve dtoh Factor out compiler specific parts Attempt to make cross platform --- src/dmd/dtoh.d | 2135 ++++++++++++++++++++++++++---------------------- src/posix.mak | 2 +- 2 files changed, 1181 insertions(+), 956 deletions(-) diff --git a/src/dmd/dtoh.d b/src/dmd/dtoh.d index 1eaf4ddea043..a9cafc0fb8e5 100644 --- a/src/dmd/dtoh.d +++ b/src/dmd/dtoh.d @@ -1,11 +1,14 @@ -// Compiler implementation of the D programming language -// Copyright (c) 1999-2015 by Digital Mars -// All Rights Reserved -// written by Walter Bright -// http://www.digitalmars.com -// Distributed under the Boost Software License, Version 1.0. -// http://www.boost.org/LICENSE_1_0.txt - +/** + * Compiler implementation of the + * $(LINK2 http://www.dlang.org, D programming language). + * + * Copyright: Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved + * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright) + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) + * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/dtohd, _dtoh.d) + * Documentation: https://dlang.org/phobos/dmd_dtoh.html + * Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dtoh.d + */ module dmd.dtoh; import core.stdc.stdio; @@ -16,643 +19,947 @@ import dmd.astcodegen; import dmd.arraytypes; import dmd.globals; import dmd.identifier; +import dmd.json; +import dmd.mars; +import dmd.root.array; +import dmd.root.file; +import dmd.root.filename; +import dmd.root.rmem; import dmd.visitor; import dmd.root.outbuffer; - -immutable string[] frontendSources = [ - "access.d", "aggregate.d", "aliasthis.d", "apply.d", "argtypes.d", "arrayop.d", "arraytypes.d", "attrib.d", - "blockexit.d", "builtin.d", - "canthrow.d", "clone.d", "compiler.d", "complex.d", "cond.d", "console.d", "constfold.d", "cppmangle.d", "cppmanglewin.d", "ctfeexpr.d", "ctorflow.d", - "dcast.d", "dclass.d", "declaration.d", "delegatize.d", "denum.d", "dimport.d", "dinterpret.d", - "dmacro.d", "dmangle.d", "dmodule.d", "doc.d", "dscope.d", "dstruct.d", "dsymbol.d", "dsymbolsem.d", "dtemplate.d", "dversion.d", - "entity.d", "errors.d", "escape.d", "expression.d", "expressionsem.d", - "func.d", - "globals.d", "gluelayer.d", - "hdrgen.d", - "iasm.d", "id.d", "identifier.d", "impcnvtab.d", "imphint.d", "init.d", "initsem.d", "inline.d", "inlinecost.d", "intrange.d", - "json.d", - "lambdacomp.d", "lexer.d", - "mtype.d", - "nogc.d", "nspace.d", - "objc.d", "opover.d", "optimize.d", - "parse.d", "printast.d", - "safe.d", "sapply.d", "semantic2.d", "semantic3.d", "sideeffect.d", "statement.d", - "statementsem.d", "staticassert.d", "staticcond.d", - "target.d", "templateparamsem.d", "tokens.d", "traits.d", "typesem.d", "typinf.d", - "utf.d", "utils.d", -]; - -private bool isIdentifierClass(ASTCodegen.ClassDeclaration cd) +version(BUILD_COMPILER) { - return (cd.ident == Identifier.idPool("Identifier") && - cd.parent !is null && - cd.parent.ident == Identifier.idPool("identifier") && - cd.parent.parent && cd.parent.parent.ident == Identifier.idPool("dmd") && - !cd.parent.parent.parent); + immutable string[] sources = [ + "access.d", "aggregate.d", "aliasthis.d", "apply.d", "argtypes.d", "arrayop.d", "arraytypes.d", "attrib.d", + "blockexit.d", "builtin.d", + "canthrow.d", "clone.d", "compiler.d", "complex.d", "cond.d", "console.d", "constfold.d", "cppmangle.d", "cppmanglewin.d", "ctfeexpr.d", "ctorflow.d", + "dcast.d", "dclass.d", "declaration.d", "delegatize.d", "denum.d", "dimport.d", "dinterpret.d", + "dmacro.d", "dmangle.d", "dmodule.d", "doc.d", "dscope.d", "dstruct.d", "dsymbol.d", "dsymbolsem.d", "dtemplate.d", "dversion.d", + "entity.d", "errors.d", "escape.d", "expression.d", "expressionsem.d", + "func.d", + "globals.d", "gluelayer.d", + "hdrgen.d", + "iasm.d", "id.d", "identifier.d", "impcnvtab.d", "imphint.d", "init.d", "initsem.d", "inline.d", "inlinecost.d", "intrange.d", + "json.d", + "lambdacomp.d", "lexer.d", + "mtype.d", + "nogc.d", "nspace.d", + "objc.d", "opover.d", "optimize.d", + "parse.d", "printast.d", + "safe.d", "sapply.d", "semantic2.d", "semantic3.d", "sideeffect.d", "statement.d", + "statementsem.d", "staticassert.d", "staticcond.d", + "target.d", "templateparamsem.d", "tokens.d", "traits.d", "typesem.d", "typinf.d", + "utf.d", "utils.d", + ]; } -private bool isVisitorClass(ASTCodegen.ClassDeclaration cd) +int main(string[] args) { - for (auto cdb = cd; cdb; cdb = cdb.baseClass) + import std.algorithm.sorting : sort; + import std.array : array; + import std.file : readText; + import std.path : baseName, buildPath, dirName; + import std.string : toStringz; + + import dmd.dsymbolsem; + import dmd.errors; + import dmd.id; + import dmd.dinifile; + import dmd.parse; + + import dmd.semantic2; + import dmd.semantic3; + import dmd.builtin : builtin_init; + import dmd.dmodule : Module; + import dmd.expression : Expression; + import dmd.frontend; + import dmd.objc : Objc; + import dmd.root.response; + import dmd.root.stringtable; + import dmd.target : Target; + + import core.memory; + import core.stdc.stdio : printf; + + GC.disable(); + initDMD(); + + Strings arguments = Strings(args.length); + for (size_t i = 0; i < args.length; i++) { - if (cdb.ident == Identifier.idPool("Visitor") || - cdb.ident == Identifier.idPool("ParseTimeVisitor")) - return true; + arguments[i] = args[i].ptr; } - return false; -} - -private bool isFrontendModule(ASTCodegen.Module m) -{ - if (!m || !m.parent) - return false; + if (response_expand(&arguments)) // expand response files + error(Loc.initial, "can't open response file"); + auto files = Strings(arguments.dim - 1); + global.params.argv0 = args[0]; + + + global.inifilename = parse_conf_arg(&arguments); + if (global.inifilename) + { + // can be empty as in -conf= + if (strlen(global.inifilename) && !FileName.exists(global.inifilename)) + error(Loc.initial, "Config file '%s' does not exist.", global.inifilename); + } + else + { + version (Windows) + { + global.inifilename = findConfFile(global.params.argv0, "sc.ini").ptr; + } + else version (Posix) + { + global.inifilename = findConfFile(global.params.argv0, "dmd.conf").ptr; + } + else + { + static assert(0, "fix this"); + } + } + // Read the configurarion file + auto inifile = File(global.inifilename); + inifile.read(); + /* Need path of configuration file, for use in expanding @P macro + */ + const(char)* inifilepath = FileName.path(global.inifilename); + Strings sections; + StringTable environment; + environment._init(7); + /* Read the [Environment] section, so we can later + * pick up any DFLAGS settings. + */ + sections.push("Environment"); + parseConfFile(&environment, global.inifilename, inifilepath, inifile.len, inifile.buffer, §ions); + + const(char)* arch = global.params.is64bit ? "64" : "32"; // use default + arch = parse_arch_arg(&arguments, arch); + + // parse architecture from DFLAGS read from [Environment] section + { + Strings dflags; + getenv_setargv(readFromEnv(&environment, "DFLAGS"), &dflags); + environment.reset(7); // erase cached environment updates + arch = parse_arch_arg(&dflags, arch); + } + + bool is64bit = arch[0] == '6'; + + version(Windows) // delete LIB entry in [Environment] (necessary for optlink) to allow inheriting environment for MS-COFF + if (is64bit || strcmp(arch, "32mscoff") == 0) + environment.update("LIB", 3).ptrvalue = null; + + // read from DFLAGS in [Environment{arch}] section + char[80] envsection = void; + sprintf(envsection.ptr, "Environment%s", arch); + sections.push(envsection.ptr); + parseConfFile(&environment, global.inifilename, inifilepath, inifile.len, inifile.buffer, §ions); + getenv_setargv(readFromEnv(&environment, "DFLAGS"), &arguments); + updateRealEnvironment(&environment); + environment.reset(1); // don't need environment cache any more + + if (parseCommandLine(arguments, args.length, global.params, files)) + { + Loc loc; + errorSupplemental(loc, "run 'dmd -man' to open browser on manual"); + return 1; + } + - // Ignore dmd.root - if (m.parent.ident == Identifier.idPool("root") && - m.parent.parent && m.parent.parent.ident == Identifier.idPool("dmd") && - !m.parent.parent.parent) + version(BUILD_COMPILER) { - return false; + global.path.push(druntimeFullPath.toStringz()); + //TODO: fixme for LDC + global.filePath.push(__FILE_FULL_PATH__.dirName.buildPath("../../").toStringz()); + global.filePath.push(__FILE_FULL_PATH__.dirName.buildPath("../../res/").toStringz()); + } + + DMDType._init(); + version(BUILD_COMPILER) + { + DMDModule._init(); + DMDClass._init(); } - // Ignore dmd.visitor and derivatives - if ((m.ident == Identifier.idPool("visitor") || - m.ident == Identifier.idPool("parsetimevisitor") || - m.ident == Identifier.idPool("permissivevisitor") || - m.ident == Identifier.idPool("strictvisitor") || - m.ident == Identifier.idPool("transitivevisitor")) && - m.parent && m.parent.ident == Identifier.idPool("dmd") && - !m.parent.parent) + setVersions(); + + Modules modules; + + string path = __FILE_FULL_PATH__.dirName.buildPath("../dmd/"); + version (BUILD_COMPILER) + auto srcs = sources; + else + auto srcs = args [1 .. $]; + foreach (f; srcs) { - return false; + string fn = buildPath(path, f); + + auto id = Identifier.idPool(baseName(fn, ".d")); + auto m = new Module(fn.toStringz(), id, false, false); + auto input = readText(fn); + + if (!Module.rootModule) + Module.rootModule = m; + + m.importedFrom = m; + m.srcfile.setbuffer(cast(void*)input.ptr, input.length); + m.srcfile._ref = 1; + m.parse(); + modules.push(m); } + + foreach (m; modules) + m.importAll(null); + foreach (m; modules) + m.dsymbolSemantic(null); + + Module.dprogress = 1; + Module.runDeferredSemantic(); + + foreach (m; modules) + m.semantic2(null); + Module.runDeferredSemantic2(); - return ((m.parent.ident == Identifier.idPool("dmd") && !m.parent.parent) || - (m.parent.parent.ident == Identifier.idPool("dmd") && !m.parent.parent.parent)); + foreach (m; modules) + m.semantic3(null); + Module.runDeferredSemantic3(); + + OutBuffer buf; + genCppFiles(&buf, &modules); + + printf("%s\n", buf.peekString()); + return 0; } -/**************************************************** - */ -void genCppFiles(OutBuffer* buf, Modules *ms) +void setVersions() { - import dmd.tokens; - - extern(C++) final class ToCppBuffer(AST) : Visitor - { - alias visit = super.visit; - public: - bool[void*] visited; - bool[void*] forwarded; - OutBuffer *fwdbuf; - OutBuffer *checkbuf; - OutBuffer *donebuf; - OutBuffer *buf; - AST.AggregateDeclaration adparent; - AST.ClassDeclaration cdparent; - AST.TemplateDeclaration tdparent; - Identifier ident; - LINK linkage = LINK.d; + import dmd.cond : VersionCondition; + version(BUILD_COMPILER) + { + VersionCondition.addPredefinedGlobalIdent("NoBackend"); + VersionCondition.addPredefinedGlobalIdent("NoMain"); + } +} - this(OutBuffer* checkbuf, OutBuffer* fwdbuf, OutBuffer* donebuf, OutBuffer* buf) +struct DMDType +{ + static Identifier c_long; + static Identifier c_ulong; + static Identifier c_longlong; + static Identifier c_ulonglong; + static Identifier c_long_double; + version(BUILD_COMPILER) + { + static Identifier AssocArray; + static Identifier Array; + } + static void _init() + { + c_long = Identifier.idPool("__c_long"); + c_ulong = Identifier.idPool("__c_ulong"); + c_longlong = Identifier.idPool("__c_longlong"); + c_ulonglong = Identifier.idPool("__c_ulonglong"); + c_long_double = Identifier.idPool("__c_long_double"); + version(BUILD_COMPILER) { - this.checkbuf = checkbuf; - this.fwdbuf = fwdbuf; - this.donebuf = donebuf; - this.buf = buf; + AssocArray = Identifier.idPool("AssocArray"); + Array = Identifier.idPool("Array"); } - private void indent() + } +} +version(BUILD_COMPILER) +{ + struct DMDModule + { + static Identifier identifier; + static Identifier root; + static Identifier visitor; + static Identifier parsetimevisitor; + static Identifier permissivevisitor; + static Identifier strictvisitor; + static Identifier transitivevisitor; + static Identifier dmd; + static void _init() { - if (adparent) - buf.writestring(" "); + identifier = Identifier.idPool("identifier"); + root = Identifier.idPool("root"); + visitor = Identifier.idPool("visitor"); + parsetimevisitor = Identifier.idPool("parsetimevisitor"); + permissivevisitor = Identifier.idPool("permissivevisitor"); + strictvisitor = Identifier.idPool("strictvisitor"); + transitivevisitor = Identifier.idPool("transitivevisitor"); + dmd = Identifier.idPool("dmd"); } - - override void visit(AST.Dsymbol s) + } + struct DMDClass + { + static Identifier ID; ////Identifier + static Identifier Visitor; + static Identifier ParseTimeVisitor; + static void _init() { - if (s.getModule() && s.getModule().isFrontendModule()) - { - indent(); - buf.printf("// ignored %s %s\n", s.kind(), s.toPrettyChars()); - } + ID = Identifier.idPool("Identifier"); + Visitor = Identifier.idPool("Visitor"); + ParseTimeVisitor = Identifier.idPool("ParseTimeVisitor"); } - - override void visit(AST.Import) + + } + + private bool isIdentifierClass(ASTCodegen.ClassDeclaration cd) + { + return (cd.ident == DMDClass.ID && + cd.parent !is null && + cd.parent.ident == DMDModule.identifier && + cd.parent.parent && cd.parent.parent.ident == DMDModule.dmd && + !cd.parent.parent.parent); + } + + private bool isVisitorClass(ASTCodegen.ClassDeclaration cd) + { + for (auto cdb = cd; cdb; cdb = cdb.baseClass) { + if (cdb.ident == DMClass.Visitor || + cdb.ident == DMClass.ParseTimeVisitor) + return true; } - - override void visit(AST.AttribDeclaration pd) + return false; + } + + private bool isFrontendModule(ASTCodegen.Module m) + { + if (!m || !m.parent) + return false; + + // Ignore dmd.root + if (m.parent.ident == DMDModule.root && + m.parent.parent && m.parent.parent.ident == DMDModule.dmd && + !m.parent.parent.parent) { - Dsymbols* decl = pd.include(null); - if (decl) - { - foreach (s; *decl) - { - if (!adparent && s.prot().kind < AST.Prot.Kind.public_) - continue; - s.accept(this); - } - } + return false; } + + // Ignore dmd.visitor and derivatives + if ((m.ident == DMDModule.visitor || + m.ident == DMDModule.parsetimevisitor || + m.ident == DMDModule.permissivevisitor || + m.ident == DMDModule.strictvisitor || + m.ident == DMDModule.transitivevisitor) && + m.parent && m.parent.ident == DMDModule.dmd && + !m.parent.parent) + { + return false; + } + + return ((m.parent.ident == DMDModule.dmd && !m.parent.parent) || + (m.parent.parent.ident == DMDModule.dmd && !m.parent.parent.parent)); + } + + string druntimeFullPath() + { + version (IN_LLVM) + string path = "../runtime/druntime/src"; + else + string path = "../../../druntime/src/"; + + return __FILE_FULL_PATH__.dirName.buildPath(path); + } +} - override void visit(AST.LinkDeclaration ld) +/**************************************************** + */ +extern(C++) final class ToCppBuffer(AST) : Visitor +{ + alias visit = Visitor.visit; +public: + bool[void*] visited; + bool[void*] forwarded; + OutBuffer *fwdbuf; + OutBuffer *checkbuf; + OutBuffer *donebuf; + OutBuffer *buf; + AST.AggregateDeclaration adparent; + AST.ClassDeclaration cdparent; + AST.TemplateDeclaration tdparent; + Identifier ident; + LINK linkage = LINK.d; + + this(OutBuffer* checkbuf, OutBuffer* fwdbuf, OutBuffer* donebuf, OutBuffer* buf) + { + this.checkbuf = checkbuf; + this.fwdbuf = fwdbuf; + this.donebuf = donebuf; + this.buf = buf; + } + + private void indent() + { + if (adparent) + buf.writestring(" "); + } + + override void visit(AST.Dsymbol s) + { + version(BUILD_COMPILER) { - auto save = linkage; - linkage = ld.linkage; - if (ld.linkage != LINK.c && ld.linkage != LINK.cpp) + if (s.getModule() && s.getModule().isFrontendModule()) { indent(); - buf.printf("// ignoring %s block because of linkage\n", ld.toPrettyChars()); + buf.printf("// ignored %s %s\n", s.kind(), s.toPrettyChars()); } - else - visit(cast(AST.AttribDeclaration)ld); - linkage = save; } - - override void visit(AST.Module m) + + } + + override void visit(AST.Import) + { + } + + override void visit(AST.AttribDeclaration pd) + { + Dsymbols* decl = pd.include(null); + if (decl) { - foreach (s; *m.members) + foreach (s; *decl) { - if (s.prot().kind < AST.Prot.Kind.public_) + if (!adparent && s.prot().kind < AST.Prot.Kind.public_) continue; s.accept(this); } } - - override void visit(AST.FuncDeclaration fd) + } + + override void visit(AST.LinkDeclaration ld) + { + auto save = linkage; + linkage = ld.linkage; + if (ld.linkage != LINK.c && ld.linkage != LINK.cpp) + { + indent(); + buf.printf("// ignoring %s block because of linkage\n", ld.toPrettyChars()); + } + else + visit(cast(AST.AttribDeclaration)ld); + linkage = save; + } + + override void visit(AST.Module m) + { + foreach (s; *m.members) + { + if (s.prot().kind < AST.Prot.Kind.public_) + continue; + s.accept(this); + } + } + + override void visit(AST.FuncDeclaration fd) + { + if (cast(void*)fd in visited) + return; + version(BUILD_COMPILER) { - if (cast(void*)fd in visited) - return; if (fd.getModule() && !fd.getModule().isFrontendModule()) + return; + } + + // printf("FuncDeclaration %s %s\n", fd.toPrettyChars(), fd.type.toChars()); + visited[cast(void*)fd] = true; + + auto tf = cast(AST.TypeFunction)fd.type; + indent(); + if (!tf || !tf.deco) + { + buf.printf("// ignoring function %s because semantic hasn't been run\n", fd.toPrettyChars()); + return; + } + if (tf.linkage != LINK.c && tf.linkage != LINK.cpp) + { + buf.printf("// ignoring function %s because of linkage\n", fd.toPrettyChars()); + return; + } + if (!adparent && !fd.fbody) + { + buf.printf("// ignoring function %s because it's extern\n", fd.toPrettyChars()); + return; + } + + if (tf.linkage == LINK.c) + buf.writestring("extern \"C\" "); + else if (!adparent) + buf.writestring("extern "); + if (adparent && fd.isStatic()) + buf.writestring("static "); + if (adparent && fd.vtblIndex != -1) + { + if (!fd.isOverride()) + buf.writestring("virtual "); + + auto s = adparent.search(Loc.initial, fd.ident); + if (!(adparent.storage_class & AST.STC.abstract_) && + !(cast(AST.ClassDeclaration)adparent).isAbstract() && + s is fd && !fd.overnext) + { + auto save = buf; + buf = checkbuf; + buf.writestring(" assert(getSlotNumber<"); + buf.writestring(adparent.ident.toChars()); + buf.writestring(">(0, &"); + buf.writestring(adparent.ident.toChars()); + buf.writestring("::"); + buf.writestring(fd.ident.toChars()); + buf.printf(") == %d);\n", fd.vtblIndex); + buf = save; + } + } + funcToBuffer(tf, fd.ident); + if (adparent && tf.isConst()) + buf.writestring(" const"); + if (adparent && fd.isAbstract()) + buf.writestring(" = 0"); + buf.printf(";\n"); + if (!adparent) + buf.printf("\n"); + } + + override void visit(AST.UnitTestDeclaration fd) + { + } + + override void visit(AST.VarDeclaration vd) + { + if (cast(void*)vd in visited) + return; + version(BUILD_COMPILER) + { + if (vd.getModule() && !vd.getModule().isFrontendModule()) return; - // printf("FuncDeclaration %s %s\n", fd.toPrettyChars(), fd.type.toChars()); - visited[cast(void*)fd] = true; - - auto tf = cast(AST.TypeFunction)fd.type; + } + + visited[cast(void*)vd] = true; + + if (vd.storage_class & AST.STC.manifest && + vd.type.isintegral() && + vd._init && vd._init.isExpInitializer()) + { indent(); - if (!tf || !tf.deco) + buf.writestring("#define "); + buf.writestring(vd.ident.toChars()); + buf.writestring(" "); + auto e = AST.initializerToExpression(vd._init); + if (e.type.ty == AST.Tbool) + buf.printf("%d", e.toInteger()); + else + AST.initializerToExpression(vd._init).accept(this); + buf.writestring("\n"); + if (!adparent) + buf.printf("\n"); + return; + } + + if (tdparent && vd.type && !vd.type.deco) + { + indent(); + if (linkage != LINK.c && linkage != LINK.cpp) { - buf.printf("// ignoring function %s because semantic hasn't been run\n", fd.toPrettyChars()); + buf.printf("// ignoring variable %s because of linkage\n", vd.toPrettyChars()); return; } - if (tf.linkage != LINK.c && tf.linkage != LINK.cpp) + typeToBuffer(vd.type, vd.ident); + buf.writestring(";\n"); + return; + } + + if (vd.storage_class & (AST.STC.static_ | AST.STC.extern_ | AST.STC.tls | AST.STC.gshared) || + vd.parent && vd.parent.isModule()) + { + indent(); + if (vd.linkage != LINK.c && vd.linkage != LINK.cpp) { - buf.printf("// ignoring function %s because of linkage\n", fd.toPrettyChars()); + buf.printf("// ignoring variable %s because of linkage\n", vd.toPrettyChars()); return; } - if (!adparent && !fd.fbody) + if (vd.storage_class & AST.STC.tls) { - buf.printf("// ignoring function %s because it's extern\n", fd.toPrettyChars()); + buf.printf("// ignoring variable %s because of thread-local storage\n", vd.toPrettyChars()); return; } - - if (tf.linkage == LINK.c) + if (vd.linkage == LINK.c) buf.writestring("extern \"C\" "); else if (!adparent) buf.writestring("extern "); - if (adparent && fd.isStatic()) + if (adparent) buf.writestring("static "); - if (adparent && fd.vtblIndex != -1) - { - if (!fd.isOverride()) - buf.writestring("virtual "); - - auto s = adparent.search(Loc.initial, fd.ident); - if (!(adparent.storage_class & AST.STC.abstract_) && - !(cast(AST.ClassDeclaration)adparent).isAbstract() && - s is fd && !fd.overnext) - { - auto save = buf; - buf = checkbuf; - buf.writestring(" assert(getSlotNumber<"); - buf.writestring(adparent.ident.toChars()); - buf.writestring(">(0, &"); - buf.writestring(adparent.ident.toChars()); - buf.writestring("::"); - buf.writestring(fd.ident.toChars()); - buf.printf(") == %d);\n", fd.vtblIndex); - buf = save; - } - } - funcToBuffer(tf, fd.ident); - if (adparent && tf.isConst()) - buf.writestring(" const"); - if (adparent && fd.isAbstract()) - buf.writestring(" = 0"); - buf.printf(";\n"); + typeToBuffer(vd.type, vd.ident); + buf.writestring(";\n"); if (!adparent) buf.printf("\n"); + return; } - - override void visit(AST.UnitTestDeclaration fd) - { - } - - override void visit(AST.VarDeclaration vd) + + if (adparent && vd.type && vd.type.deco) { - if (cast(void*)vd in visited) - return; - if (vd.getModule() && !vd.getModule().isFrontendModule()) - return; - visited[cast(void*)vd] = true; - - if (vd.storage_class & AST.STC.manifest && - vd.type.isintegral() && - vd._init && vd._init.isExpInitializer()) - { - indent(); - buf.writestring("#define "); - buf.writestring(vd.ident.toChars()); - buf.writestring(" "); - auto e = AST.initializerToExpression(vd._init); - if (e.type.ty == AST.Tbool) - buf.printf("%d", e.toInteger()); - else - AST.initializerToExpression(vd._init).accept(this); - buf.writestring("\n"); - if (!adparent) - buf.printf("\n"); - return; - } - - if (tdparent && vd.type && !vd.type.deco) - { - indent(); - if (linkage != LINK.c && linkage != LINK.cpp) - { - buf.printf("// ignoring variable %s because of linkage\n", vd.toPrettyChars()); - return; - } - typeToBuffer(vd.type, vd.ident); - buf.writestring(";\n"); - return; - } - - if (vd.storage_class & (AST.STC.static_ | AST.STC.extern_ | AST.STC.tls | AST.STC.gshared) || - vd.parent && vd.parent.isModule()) - { - indent(); - if (vd.linkage != LINK.c && vd.linkage != LINK.cpp) - { - buf.printf("// ignoring variable %s because of linkage\n", vd.toPrettyChars()); - return; - } - if (vd.storage_class & AST.STC.tls) - { - buf.printf("// ignoring variable %s because of thread-local storage\n", vd.toPrettyChars()); - return; - } - if (vd.linkage == LINK.c) - buf.writestring("extern \"C\" "); - else if (!adparent) - buf.writestring("extern "); - if (adparent) - buf.writestring("static "); - typeToBuffer(vd.type, vd.ident); - buf.writestring(";\n"); - if (!adparent) - buf.printf("\n"); - return; - } - - if (adparent && vd.type && vd.type.deco) + indent(); + auto save = cdparent; + cdparent = vd.isField() ? adparent.isClassDeclaration() : null; + typeToBuffer(vd.type, vd.ident); + cdparent = save; + buf.writestring(";\n"); + if (vd.type.ty == AST.Tstruct) { - indent(); - auto save = cdparent; - cdparent = vd.isField() ? adparent.isClassDeclaration() : null; - typeToBuffer(vd.type, vd.ident); - cdparent = save; - buf.writestring(";\n"); - if (vd.type.ty == AST.Tstruct) - { - auto t = cast(AST.TypeStruct)vd.type; - includeSymbol(t.sym); - } - auto savex = buf; - buf = checkbuf; - buf.writestring(" assert(offsetof("); - buf.writestring(adparent.ident.toChars()); - buf.writestring(", "); - buf.writestring(vd.ident.toChars()); - buf.printf(") == %d);\n", vd.offset); - buf = savex; - return; + auto t = cast(AST.TypeStruct)vd.type; + includeSymbol(t.sym); } - - visit(cast(AST.Dsymbol)vd); + auto savex = buf; + buf = checkbuf; + buf.writestring(" assert(offsetof("); + buf.writestring(adparent.ident.toChars()); + buf.writestring(", "); + buf.writestring(vd.ident.toChars()); + buf.printf(") == %d);\n", vd.offset); + buf = savex; + return; } - - override void visit(AST.TypeInfoDeclaration) + + visit(cast(AST.Dsymbol)vd); + } + + override void visit(AST.TypeInfoDeclaration) + { + } + + override void visit(AST.AliasDeclaration ad) + { + version(BUILD_COMPILER) { + if (ad.getModule() && !ad.getModule().isFrontendModule()) + return; } - - override void visit(AST.AliasDeclaration ad) + + if (auto t = ad.type) { - if (ad.getModule() && !ad.getModule().isFrontendModule()) - return; - if (auto t = ad.type) + if (t.ty == AST.Tdelegate) { - if (t.ty == AST.Tdelegate) - { - visit(cast(AST.Dsymbol)ad); - return; - } - buf.writestring("typedef "); - typeToBuffer(t, ad.ident); - buf.writestring(";\n"); - if (!adparent) - buf.printf("\n"); + visit(cast(AST.Dsymbol)ad); return; } - if (!ad.aliassym) - { - ad.print(); - assert(0); - } - if (auto ti = ad.aliassym.isTemplateInstance()) - { - visitTi(ti); - return; - } - if (auto sd = ad.aliassym.isStructDeclaration()) - { - buf.writestring("typedef "); - sd.type.accept(this); - buf.writestring(" "); - buf.writestring(ad.ident.toChars()); - buf.writestring(";\n"); - if (!adparent) - buf.printf("\n"); - return; - } - indent(); - buf.printf("// ignored %s %s\n", ad.aliassym.kind(), ad.aliassym.toPrettyChars()); + buf.writestring("typedef "); + typeToBuffer(t, ad.ident); + buf.writestring(";\n"); + if (!adparent) + buf.printf("\n"); + return; } - - override void visit(AST.AnonDeclaration ad) + if (!ad.aliassym) { - buf.writestring(ad.isunion ? "union" : "struct"); - buf.writestring("\n{\n"); - foreach (s; *ad.decl) - { - s.accept(this); - } - buf.writestring("};\n"); + //ad.print(); + assert(0); } - - private bool memberField(AST.VarDeclaration vd) - { - if (!vd.type || !vd.type.deco || !vd.ident) - return false; - if (!vd.isField()) - return false; - if (vd.type.ty == AST.Tfunction) - return false; - if (vd.type.ty == AST.Tsarray) - return false; - return true; + if (auto ti = ad.aliassym.isTemplateInstance()) + { + visitTi(ti); + return; } - - override void visit(AST.StructDeclaration sd) + if (auto sd = ad.aliassym.isStructDeclaration()) + { + buf.writestring("typedef "); + sd.type.accept(this); + buf.writestring(" "); + buf.writestring(ad.ident.toChars()); + buf.writestring(";\n"); + if (!adparent) + buf.printf("\n"); + return; + } + indent(); + buf.printf("// ignored %s %s\n", ad.aliassym.kind(), ad.aliassym.toPrettyChars()); + } + + override void visit(AST.AnonDeclaration ad) + { + buf.writestring(ad.isunion ? "union" : "struct"); + buf.writestring("\n{\n"); + foreach (s; *ad.decl) + { + s.accept(this); + } + buf.writestring("};\n"); + } + + private bool memberField(AST.VarDeclaration vd) + { + if (!vd.type || !vd.type.deco || !vd.ident) + return false; + if (!vd.isField()) + return false; + if (vd.type.ty == AST.Tfunction) + return false; + if (vd.type.ty == AST.Tsarray) + return false; + return true; + } + + override void visit(AST.StructDeclaration sd) + { + if (sd.isInstantiated()) + return; + if (cast(void*)sd in visited) + return; + if (!sd.type || !sd.type.deco) + return; + version(BUILD_COMPILER) { - if (sd.isInstantiated()) - return; - if (cast(void*)sd in visited) - return; - if (!sd.type || !sd.type.deco) - return; if (sd.getModule() && !sd.getModule().isFrontendModule()) - return; - visited[cast(void*)sd] = true; - - if (sd.alignment == 1) - buf.writestring("#pragma pack(push, 1)\n"); - buf.writestring(sd.isUnionDeclaration() ? "union " : "struct "); - buf.writestring(sd.ident.toChars()); - if (sd.members) + return; + } + + visited[cast(void*)sd] = true; + + if (sd.alignment == 1) + buf.writestring("#pragma pack(push, 1)\n"); + buf.writestring(sd.isUnionDeclaration() ? "union " : "struct "); + buf.writestring(sd.ident.toChars()); + if (sd.members) + { + buf.writestring("\n{\n"); + auto save = adparent; + adparent = sd; + foreach (m; *sd.members) { - buf.writestring("\n{\n"); - auto save = adparent; - adparent = sd; - foreach (m; *sd.members) + m.accept(this); + } + adparent = save; + // Generate default ctor + buf.printf(" %s(", sd.ident.toChars()); + buf.printf(") {"); + size_t varCount; + foreach (m; *sd.members) + { + if (auto vd = m.isVarDeclaration()) { - m.accept(this); + if (!memberField(vd)) + continue; + varCount++; + if (!vd._init && !vd.type.isTypeBasic()) + continue; + buf.printf(" this->%s = ", vd.ident.toChars()); + if (vd._init) + AST.initializerToExpression(vd._init).accept(this); + else if (vd.type.isTypeBasic()) + vd.type.defaultInitLiteral(Loc.initial).accept(this); + buf.printf(";"); } - adparent = save; - // Generate default ctor + } + buf.printf(" }\n"); + + if (varCount) + { buf.printf(" %s(", sd.ident.toChars()); - buf.printf(") {"); - size_t varCount; + bool first = true; foreach (m; *sd.members) { if (auto vd = m.isVarDeclaration()) { if (!memberField(vd)) continue; - varCount++; - if (!vd._init && !vd.type.isTypeBasic()) - continue; - buf.printf(" this->%s = ", vd.ident.toChars()); - if (vd._init) - AST.initializerToExpression(vd._init).accept(this); - else if (vd.type.isTypeBasic()) - vd.type.defaultInitLiteral(Loc.initial).accept(this); - buf.printf(";"); + if (first) + first = false; + else + buf.writestring(", "); + assert(vd.type); + assert(vd.ident); + typeToBuffer(vd.type, vd.ident); } } - buf.printf(" }\n"); - - if (varCount) + buf.printf(") {"); + foreach (m; *sd.members) { - buf.printf(" %s(", sd.ident.toChars()); - bool first = true; - foreach (m; *sd.members) - { - if (auto vd = m.isVarDeclaration()) - { - if (!memberField(vd)) - continue; - if (first) - first = false; - else - buf.writestring(", "); - assert(vd.type); - assert(vd.ident); - typeToBuffer(vd.type, vd.ident); - } - } - buf.printf(") {"); - foreach (m; *sd.members) + if (auto vd = m.isVarDeclaration()) { - if (auto vd = m.isVarDeclaration()) - { - if (!memberField(vd)) - continue; - buf.printf(" this->%s = %s;", vd.ident.toChars(), vd.ident.toChars()); - } + if (!memberField(vd)) + continue; + buf.printf(" this->%s = %s;", vd.ident.toChars(), vd.ident.toChars()); } - buf.printf(" }\n"); } - - buf.writestring("};\n\n"); - - if (sd.alignment == 1) - buf.writestring("#pragma pack(pop)\n"); - - auto savex = buf; - buf = checkbuf; - buf.writestring(" assert(sizeof("); - buf.writestring(sd.ident.toChars()); - buf.printf(") == %d);\n", sd.size(Loc.initial)); - buf = savex; + buf.printf(" }\n"); } - else - buf.writestring(";\n\n"); + + buf.writestring("};\n\n"); + + if (sd.alignment == 1) + buf.writestring("#pragma pack(pop)\n"); + + auto savex = buf; + buf = checkbuf; + buf.writestring(" assert(sizeof("); + buf.writestring(sd.ident.toChars()); + buf.printf(") == %d);\n", sd.size(Loc.initial)); + buf = savex; } - - private void includeSymbol(AST.Dsymbol ds) + else + buf.writestring(";\n\n"); + } + + private void includeSymbol(AST.Dsymbol ds) + { + // printf("Forward declaring %s %d\n", ds.toChars(), level); + if (cast(void*)ds !in visited) { - // printf("Forward declaring %s %d\n", ds.toChars(), level); - if (cast(void*)ds !in visited) - { - OutBuffer decl; - auto save = buf; - buf = &decl; - ds.accept(this); - buf = save; - donebuf.writestring(decl.peekString()); - } + OutBuffer decl; + auto save = buf; + buf = &decl; + ds.accept(this); + buf = save; + donebuf.writestring(decl.peekString()); } - - override void visit(AST.ClassDeclaration cd) + } + + override void visit(AST.ClassDeclaration cd) + { + if (cast(void*)cd in visited) + return; + version(BUILD_COMPILER) { - if (cast(void*)cd in visited) - return; if (cd.getModule() && !cd.getModule().isFrontendModule()) - return; + return; if (cd.isVisitorClass()) - return; - visited[cast(void*)cd] = true; - if (!cd.isCPPclass()) - { - buf.printf("// ignoring non-cpp class %s\n", cd.toChars()); - return; - } - - buf.writestring("class "); - buf.writestring(cd.ident.toChars()); - if (cd.baseClass) + return; + } + + visited[cast(void*)cd] = true; + if (!cd.isCPPclass()) + { + buf.printf("// ignoring non-cpp class %s\n", cd.toChars()); + return; + } + + buf.writestring("class "); + buf.writestring(cd.ident.toChars()); + if (cd.baseClass) + { + buf.writestring(" : public "); + buf.writestring(cd.baseClass.ident.toChars()); + + includeSymbol(cd.baseClass); + } + if (cd.members) + { + buf.writestring("\n{\npublic:\n"); + auto save = adparent; + adparent = cd; + foreach (m; *cd.members) { - buf.writestring(" : public "); - buf.writestring(cd.baseClass.ident.toChars()); - - includeSymbol(cd.baseClass); + m.accept(this); } - if (cd.members) + adparent = save; + version(BUILD_COMPILER) { - buf.writestring("\n{\npublic:\n"); - auto save = adparent; - adparent = cd; - foreach (m; *cd.members) - { - m.accept(this); - } - adparent = save; // Generate special static inline function. if (cd.isIdentifierClass()) { buf.writestring(" static inline Identifier *idPool(const char *s) { return idPool(s, strlen(s)); }\n"); } - buf.writestring("};\n\n"); } - else - buf.writestring(";\n\n"); + + buf.writestring("};\n\n"); } - - override void visit(AST.EnumDeclaration ed) + else + buf.writestring(";\n\n"); + } + + override void visit(AST.EnumDeclaration ed) + { + if (cast(void*)ed in visited) + return; + version(BUILD_COMPILER) { - if (cast(void*)ed in visited) - return; if (ed.getModule() && !ed.getModule().isFrontendModule()) - return; - visited[cast(void*)ed] = true; - if (ed.isSpecial()) - return; - buf.writestring("enum"); - const(char)* ident = null; - if (ed.ident) - ident = ed.ident.toChars(); - if (ident) - { - buf.writeByte(' '); - buf.writestring(ident); - } - if (ed.members) - { - buf.writestring("\n{\n"); - foreach (i, m; *ed.members) - { - if (i) - buf.writestring(",\n"); - buf.writestring(" "); - if (ident) - { - foreach (c; ident[0 .. strlen(ident)]) - buf.writeByte(toupper(c)); - } - m.accept(this); - } - buf.writestring("\n};\n\n"); - } - else - buf.writestring(";\n\n"); + return; } - - override void visit(AST.EnumMember em) + + visited[cast(void*)ed] = true; + if (ed.isSpecial()) + return; + buf.writestring("enum"); + const(char)* ident = null; + if (ed.ident) + ident = ed.ident.toChars(); + if (ident) { - buf.writestring(em.ident.toChars()); - buf.writestring(" = "); - assert(em.value.op == TOK.int64); - auto ie = cast(AST.IntegerExp)em.value; - visitInteger(ie.toInteger(), em.ed.memtype); + buf.writeByte(' '); + buf.writestring(ident); } - - private void typeToBuffer(AST.Type t, Identifier ident) + if (ed.members) { - this.ident = ident; - t.accept(this); - if (this.ident) - { - buf.writeByte(' '); - buf.writestring(ident.toChars()); - } - this.ident = null; - if (t.ty == AST.Tsarray) + buf.writestring("\n{\n"); + foreach (i, m; *ed.members) { - auto tsa = cast(AST.TypeSArray)t; - buf.writeByte('['); - tsa.dim.accept(this); - buf.writeByte(']'); + if (i) + buf.writestring(",\n"); + buf.writestring(" "); + if (ident) + { + foreach (c; ident[0 .. strlen(ident)]) + buf.writeByte(toupper(c)); + } + m.accept(this); } + buf.writestring("\n};\n\n"); } - - override void visit(AST.Type t) + else + buf.writestring(";\n\n"); + } + + override void visit(AST.EnumMember em) + { + buf.writestring(em.ident.toChars()); + buf.writestring(" = "); + if (cast(AST.StringExp)em.value) { - printf("Invalid type: %s\n", t.toPrettyChars()); - assert(0); + em.value.error("cannot convert string enum"); + return ; } - - override void visit(AST.TypeIdentifier t) + auto ie = cast(AST.IntegerExp)em.value; + visitInteger(ie.toInteger(), em.ed.memtype); + } + + private void typeToBuffer(AST.Type t, Identifier ident) + { + this.ident = ident; + t.accept(this); + if (this.ident) { - buf.writestring(t.ident.toChars()); + buf.writeByte(' '); + buf.writestring(ident.toChars()); } - - override void visit(AST.TypeBasic t) + this.ident = null; + if (t.ty == AST.Tsarray) + { + auto tsa = cast(AST.TypeSArray)t; + buf.writeByte('['); + tsa.dim.accept(this); + buf.writeByte(']'); + } + } + + override void visit(AST.Type t) + { + printf("Invalid type: %s\n", t.toPrettyChars()); + assert(0); + } + + override void visit(AST.TypeIdentifier t) + { + buf.writestring(t.ident.toChars()); + } + + override void visit(AST.TypeBasic t) + { + if (!cdparent && t.isConst()) + buf.writestring("const "); + switch (t.ty) { - if (!cdparent && t.isConst()) - buf.writestring("const "); - switch (t.ty) - { case AST.Tbool, AST.Tvoid: case AST.Tchar, AST.Twchar, AST.Tdchar: case AST.Tint8, AST.Tuns8: @@ -664,361 +971,376 @@ void genCppFiles(OutBuffer* buf, Modules *ms) buf.writestring(t.dstring); break; default: - t.print(); + //t.print(); assert(0); - } - } - - override void visit(AST.TypePointer t) - { - if (t.next.ty == AST.Tstruct && - !strcmp((cast(AST.TypeStruct)t.next).sym.ident.toChars(), "__va_list_tag")) - { - buf.writestring("va_list"); - return; - } - t.next.accept(this); - if (t.next.ty != AST.Tfunction) - buf.writeByte('*'); - if (!cdparent && t.isConst()) - buf.writestring(" const"); } - - override void visit(AST.TypeSArray t) + } + + override void visit(AST.TypePointer t) + { + if (t.next.ty == AST.Tstruct && + !strcmp((cast(AST.TypeStruct)t.next).sym.ident.toChars(), "__va_list_tag")) { - t.next.accept(this); + buf.writestring("va_list"); + return; } - - override void visit(AST.TypeAArray t) + t.next.accept(this); + if (t.next.ty != AST.Tfunction) + buf.writeByte('*'); + if (!cdparent && t.isConst()) + buf.writestring(" const"); + } + + override void visit(AST.TypeSArray t) + { + t.next.accept(this); + } + + override void visit(AST.TypeAArray t) + { + AST.Type.tvoidptr.accept(this); + } + + override void visit(AST.TypeFunction tf) + { + tf.next.accept(this); + buf.writeByte('('); + buf.writeByte('*'); + if (ident) + buf.writestring(ident.toChars()); + ident = null; + buf.writeByte(')'); + buf.writeByte('('); + foreach (i; 0 .. AST.Parameter.dim(tf.parameters)) { - AST.Type.tvoidptr.accept(this); + if (i) + buf.writestring(", "); + auto fparam = AST.Parameter.getNth(tf.parameters, i); + fparam.accept(this); } - - override void visit(AST.TypeFunction tf) - { - tf.next.accept(this); - buf.writeByte('('); - buf.writeByte('*'); - if (ident) - buf.writestring(ident.toChars()); - ident = null; - buf.writeByte(')'); - buf.writeByte('('); - foreach (i; 0 .. AST.Parameter.dim(tf.parameters)) - { - if (i) - buf.writestring(", "); - auto fparam = AST.Parameter.getNth(tf.parameters, i); - fparam.accept(this); - } - if (tf.varargs) - { - if (tf.parameters.dim && tf.varargs == 1) - buf.writestring(", "); - buf.writestring("..."); - } - buf.writeByte(')'); + if (tf.varargs) + { + if (tf.parameters.dim && tf.varargs == 1) + buf.writestring(", "); + buf.writestring("..."); } - - private void enumToBuffer(AST.EnumDeclaration ed) + buf.writeByte(')'); + } + + private void enumToBuffer(AST.EnumDeclaration ed) + { + if (ed.isSpecial()) { - if (ed.isSpecial()) + if (ed.ident == DMDType.c_long) + buf.writestring("long"); + else if (ed.ident == DMDType.c_ulong) + buf.writestring("unsigned long"); + else if (ed.ident == DMDType.c_longlong) + buf.writestring("long long"); + else if (ed.ident == DMDType.c_ulonglong) + buf.writestring("unsigned long long"); + else if (ed.ident == DMDType.c_long_double) + buf.writestring("long double"); + else { - if (ed.ident == Identifier.idPool("__c_long")) - buf.writestring("long"); - else if (ed.ident == Identifier.idPool("__c_ulong")) - buf.writestring("unsigned long"); - else if (ed.ident == Identifier.idPool("__c_longlong")) - buf.writestring("long long"); - else if (ed.ident == Identifier.idPool("__c_ulonglong")) - buf.writestring("unsigned long long"); - else if (ed.ident == Identifier.idPool("__c_long_double")) - buf.writestring("long double"); - else - { - ed.print(); - assert(0); - } + //ed.print(); + assert(0); } - else - buf.writestring(ed.toChars()); } - - override void visit(AST.TypeEnum t) + else + buf.writestring(ed.toChars()); + } + + override void visit(AST.TypeEnum t) + { + if (cast(void*)t.sym !in forwarded) { - if (cast(void*)t.sym !in forwarded) - { - forwarded[cast(void*)t.sym] = true; - auto save = buf; - buf = fwdbuf; - t.sym.accept(this); - buf = save; - } - if (!cdparent && t.isConst()) - buf.writestring("const "); - enumToBuffer(t.sym); + forwarded[cast(void*)t.sym] = true; + auto save = buf; + buf = fwdbuf; + t.sym.accept(this); + buf = save; } - - override void visit(AST.TypeStruct t) + if (!cdparent && t.isConst()) + buf.writestring("const "); + enumToBuffer(t.sym); + } + + override void visit(AST.TypeStruct t) + { + if (cast(void*)t.sym !in forwarded && + !t.sym.parent.isTemplateInstance()) { - if (cast(void*)t.sym !in forwarded && - !t.sym.parent.isTemplateInstance()) - { - forwarded[cast(void*)t.sym] = true; - fwdbuf.writestring(t.sym.isUnionDeclaration() ? "union " : "struct "); - fwdbuf.writestring(t.sym.toChars()); - fwdbuf.writestring(";\n"); - } - - if (!cdparent && t.isConst()) - buf.writestring("const "); - if (auto ti = t.sym.parent.isTemplateInstance()) - { - visitTi(ti); - return; - } - buf.writestring(t.sym.toChars()); + forwarded[cast(void*)t.sym] = true; + fwdbuf.writestring(t.sym.isUnionDeclaration() ? "union " : "struct "); + fwdbuf.writestring(t.sym.toChars()); + fwdbuf.writestring(";\n"); } - - override void visit(AST.TypeDArray t) + + if (!cdparent && t.isConst()) + buf.writestring("const "); + if (auto ti = t.sym.parent.isTemplateInstance()) { - if (!cdparent && t.isConst()) - buf.writestring("const "); - buf.writestring("DArray<"); - t.next.accept(this); - buf.writestring(">"); + visitTi(ti); + return; } - - private void visitTi(AST.TemplateInstance ti) + buf.writestring(t.sym.toChars()); + } + + override void visit(AST.TypeDArray t) + { + if (!cdparent && t.isConst()) + buf.writestring("const "); + buf.writestring("DArray<"); + t.next.accept(this); + buf.writestring(">"); + } + + private void visitTi(AST.TemplateInstance ti) + { + version(BUILD_COMPILER) { - if (ti.tempdecl.ident == Identifier.idPool("AssocArray")) + if (ti.tempdecl.ident == DMDType.AssocArray) { buf.writestring("AA*"); return; } - if (ti.tempdecl.ident == Identifier.idPool("Array")) + if (ti.tempdecl.ident == DMDType.Array) buf.writestring("Array"); else { foreach (o; *ti.tiargs) { if (!AST.isType(o)) - return; + return; } buf.writestring(ti.tempdecl.ident.toChars()); } - buf.writeByte('<'); - foreach (i, o; *ti.tiargs) - { - if (i) - buf.writestring(", "); - if (auto tt = AST.isType(o)) - { - tt.accept(this); - } - else - { - ti.print(); - o.print(); - assert(0); - } - } - buf.writeByte('>'); } - - override void visit(AST.TemplateDeclaration td) + else { - if (cast(void*)td in visited) - return; - visited[cast(void*)td] = true; - - if (td.getModule() && !td.getModule().isFrontendModule()) - return; - if (!td.parameters || !td.onemember || !td.onemember.isStructDeclaration()) - { - visit(cast(AST.Dsymbol)td); - return; - } - - // Explcitly disallow templates with non-type parameters or specialization. - foreach (p; *td.parameters) - { - if (!p.isTemplateTypeParameter() || p.specialization()) - { - visit(cast(AST.Dsymbol)td); - return; - } - } - - if (linkage != LINK.c && linkage != LINK.cpp) + foreach (o; *ti.tiargs) { - buf.printf("// ignoring template %s because of linkage\n", td.toPrettyChars()); + if (!AST.isType(o)) return; } - - auto sd = td.onemember.isStructDeclaration(); - auto save = tdparent; - tdparent = td; - indent(); - buf.writestring("template <"); - bool first = true; - foreach (p; *td.parameters) + buf.writestring(ti.tempdecl.ident.toChars()); + } + buf.writeByte('<'); + foreach (i, o; *ti.tiargs) + { + if (i) + buf.writestring(", "); + if (auto tt = AST.isType(o)) { - if (first) - first = false; - else - buf.writestring(", "); - buf.writestring("typename "); - buf.writestring(p.ident.toChars()); + tt.accept(this); } - buf.writestring(">\n"); - buf.writestring(sd.isUnionDeclaration() ? "union " : "struct "); - buf.writestring(sd.ident.toChars()); - if (sd.members) + else { - buf.writestring("\n{\n"); - auto savex = adparent; - adparent = sd; - foreach (m; *sd.members) - { - m.accept(this); - } - adparent = savex; - buf.writestring("};\n\n"); + //ti.print(); + //o.print(); + assert(0); } - else - buf.writestring(";\n\n"); - tdparent = save; } - - override void visit(AST.TypeClass t) + buf.writeByte('>'); + } + + override void visit(AST.TemplateDeclaration td) + { + if (cast(void*)td in visited) + return; + visited[cast(void*)td] = true; + version(BUILD_COMPILER) { - if (cast(void*)t.sym !in forwarded) - { - forwarded[cast(void*)t.sym] = true; - fwdbuf.writestring("class "); - fwdbuf.writestring(t.sym.toChars()); - fwdbuf.writestring(";\n"); - } - - if (!cdparent && t.isConst()) - buf.writestring("const "); - buf.writestring(t.sym.toChars()); - buf.writeByte('*'); - if (!cdparent && t.isConst()) - buf.writestring(" const"); + if (td.getModule() && !td.getModule().isFrontendModule()) + return; } - - private void funcToBuffer(AST.TypeFunction tf, Identifier ident) + + if (!td.parameters || !td.onemember || !td.onemember.isStructDeclaration()) { - assert(tf.next); - tf.next.accept(this); - if (tf.isref) - buf.writeByte('&'); - buf.writeByte(' '); - buf.writestring(ident.toChars()); - - buf.writeByte('('); - foreach (i; 0 .. AST.Parameter.dim(tf.parameters)) - { - if (i) - buf.writestring(", "); - auto fparam = AST.Parameter.getNth(tf.parameters, i); - fparam.accept(this); - } - if (tf.varargs) + visit(cast(AST.Dsymbol)td); + return; + } + + // Explicitly disallow templates with non-type parameters or specialization. + foreach (p; *td.parameters) + { + if (!p.isTemplateTypeParameter() || p.specialization()) { - if (tf.parameters.dim && tf.varargs == 1) - buf.writestring(", "); - buf.writestring("..."); + visit(cast(AST.Dsymbol)td); + return; } - buf.writeByte(')'); } - - override void visit(AST.Parameter p) + + if (linkage != LINK.c && linkage != LINK.cpp) { - ident = p.ident; - p.type.accept(this); - assert(!(p.storageClass & ~(AST.STC.ref_))); - if (p.storageClass & AST.STC.ref_) - buf.writeByte('&'); - buf.writeByte(' '); - if (ident) - buf.writestring(ident.toChars()); - ident = null; - if (p.defaultArg) + buf.printf("// ignoring template %s because of linkage\n", td.toPrettyChars()); + return; + } + + auto sd = td.onemember.isStructDeclaration(); + auto save = tdparent; + tdparent = td; + indent(); + buf.writestring("template <"); + bool first = true; + foreach (p; *td.parameters) + { + if (first) + first = false; + else + buf.writestring(", "); + buf.writestring("typename "); + buf.writestring(p.ident.toChars()); + } + buf.writestring(">\n"); + buf.writestring(sd.isUnionDeclaration() ? "union " : "struct "); + buf.writestring(sd.ident.toChars()); + if (sd.members) + { + buf.writestring("\n{\n"); + auto savex = adparent; + adparent = sd; + foreach (m; *sd.members) { - // buf.writestring("/*"); - buf.writestring(" = "); - p.defaultArg.accept(this); - // buf.writestring("*/"); + m.accept(this); } + adparent = savex; + buf.writestring("};\n\n"); } - - override void visit(AST.Expression e) + else + buf.writestring(";\n\n"); + tdparent = save; + } + + override void visit(AST.TypeClass t) + { + if (cast(void*)t.sym !in forwarded) { - e.print(); - assert(0); + forwarded[cast(void*)t.sym] = true; + fwdbuf.writestring("class "); + fwdbuf.writestring(t.sym.toChars()); + fwdbuf.writestring(";\n"); } - - override void visit(AST.NullExp e) + + if (!cdparent && t.isConst()) + buf.writestring("const "); + buf.writestring(t.sym.toChars()); + buf.writeByte('*'); + if (!cdparent && t.isConst()) + buf.writestring(" const"); + } + + private void funcToBuffer(AST.TypeFunction tf, Identifier ident) + { + assert(tf.next); + tf.next.accept(this); + if (tf.isref) + buf.writeByte('&'); + buf.writeByte(' '); + buf.writestring(ident.toChars()); + + buf.writeByte('('); + foreach (i; 0 .. AST.Parameter.dim(tf.parameters)) { - buf.writestring("_d_null"); + if (i) + buf.writestring(", "); + auto fparam = AST.Parameter.getNth(tf.parameters, i); + fparam.accept(this); } - - override void visit(AST.ArrayLiteralExp e) + if (tf.varargs) { - buf.writestring("arrayliteral"); + if (tf.parameters.dim && tf.varargs == 1) + buf.writestring(", "); + buf.writestring("..."); } - - override void visit(AST.StringExp e) - { - assert(e.sz == 1 || e.sz == 2); - if (e.sz == 2) - buf.writeByte('L'); - buf.writeByte('"'); - size_t o = buf.offset; - for (size_t i = 0; i < e.len; i++) + buf.writeByte(')'); + } + + override void visit(AST.Parameter p) + { + ident = p.ident; + p.type.accept(this); + assert(!(p.storageClass & ~(AST.STC.ref_))); + if (p.storageClass & AST.STC.ref_) + buf.writeByte('&'); + buf.writeByte(' '); + if (ident) + buf.writestring(ident.toChars()); + ident = null; + if (p.defaultArg) + { + // buf.writestring("/*"); + buf.writestring(" = "); + p.defaultArg.accept(this); + // buf.writestring("*/"); + } + } + + override void visit(AST.Expression e) + { + //e.print(); + assert(0); + } + + override void visit(AST.NullExp e) + { + buf.writestring("_d_null"); + } + + override void visit(AST.ArrayLiteralExp e) + { + buf.writestring("arrayliteral"); + } + + override void visit(AST.StringExp e) + { + assert(e.sz == 1 || e.sz == 2); + if (e.sz == 2) + buf.writeByte('L'); + buf.writeByte('"'); + size_t o = buf.offset; + for (size_t i = 0; i < e.len; i++) + { + uint c = e.charAt(i); + switch (c) { - uint c = e.charAt(i); - switch (c) - { case '"': case '\\': - buf.writeByte('\\'); - goto default; + buf.writeByte('\\'); + goto default; default: - if (c <= 0xFF) - { - if (c <= 0x7F && isprint(c)) - buf.writeByte(c); - else - buf.printf("\\x%02x", c); - } - else if (c <= 0xFFFF) - buf.printf("\\x%02x\\x%02x", c & 0xFF, c >> 8); + if (c <= 0xFF) + { + if (c <= 0x7F && isprint(c)) + buf.writeByte(c); else - buf.printf("\\x%02x\\x%02x\\x%02x\\x%02x", c & 0xFF, (c >> 8) & 0xFF, (c >> 16) & 0xFF, c >> 24); - break; + buf.printf("\\x%02x", c); } + else if (c <= 0xFFFF) + buf.printf("\\x%02x\\x%02x", c & 0xFF, c >> 8); + else + buf.printf("\\x%02x\\x%02x\\x%02x\\x%02x", c & 0xFF, (c >> 8) & 0xFF, (c >> 16) & 0xFF, c >> 24); + break; } - buf.writeByte('"'); - } - - override void visit(AST.RealExp e) - { - buf.writestring("0"); - } - - override void visit(AST.IntegerExp e) - { - visitInteger(e.toInteger, e.type); } - - private void visitInteger(dinteger_t v, AST.Type t) + buf.writeByte('"'); + } + + override void visit(AST.RealExp e) + { + buf.writestring("0"); + } + + override void visit(AST.IntegerExp e) + { + visitInteger(e.toInteger, e.type); + } + + private void visitInteger(dinteger_t v, AST.Type t) + { + switch (t.ty) { - switch (t.ty) - { case AST.Tenum: auto te = cast(AST.TypeEnum)t; buf.writestring("("); @@ -1055,24 +1377,27 @@ void genCppFiles(OutBuffer* buf, Modules *ms) buf.printf("%lluLLU", v); break; default: - t.print(); + //t.print(); assert(0); - } } - - override void visit(AST.StructLiteralExp sle) + } + + override void visit(AST.StructLiteralExp sle) + { + buf.writestring(sle.sd.ident.toChars()); + buf.writeByte('('); + foreach(i, e; *sle.elements) { - buf.writestring(sle.sd.ident.toChars()); - buf.writeByte('('); - foreach(i, e; *sle.elements) - { - if (i) - buf.writestring(", "); - e.accept(this); - } - buf.writeByte(')'); + if (i) + buf.writestring(", "); + e.accept(this); } + buf.writeByte(')'); } +} +void genCppFiles(OutBuffer* buf, Modules *ms) +{ + import dmd.tokens; buf.writeByte('\n'); buf.printf("// Automatically generated by dtoh\n"); @@ -1109,148 +1434,48 @@ void genCppFiles(OutBuffer* buf, Modules *ms) buf.writestring("\n"); buf.writestring("#define _d_null NULL\n"); buf.writestring("\n"); - buf.writestring("struct AA;\n"); + version(BUILD_COMPILER) + buf.writestring("struct AA;\n"); buf.writestring("\n"); - + OutBuffer check; check.writestring(` -#if OFFSETS - -template -size_t getSlotNumber(int dummy, ...) -{ - T c; - va_list ap; - va_start(ap, dummy); - void *f = va_arg(ap, void*); - for (size_t i = 0; ; i++) + #if OFFSETS + + template + size_t getSlotNumber(int dummy, ...) { - if ( (*(void***)&c)[i] == f) + T c; + va_list ap; + va_start(ap, dummy); + void *f = va_arg(ap, void*); + for (size_t i = 0; ; i++) + { + if ( (*(void***)&c)[i] == f) return i; + } + va_end(ap); } - va_end(ap); -} - -void testOffsets() -{ - `); - - OutBuffer done; - OutBuffer decl; - scope v = new ToCppBuffer!ASTCodegen(&check, buf, &done, &decl); - foreach (m; *ms) + + void testOffsets() { - buf.printf("// Parsing module %s\n", m.toPrettyChars()); - m.accept(v); + `); + + OutBuffer done; + OutBuffer decl; + scope v = new ToCppBuffer!ASTCodegen(&check, buf, &done, &decl); + foreach (m; *ms) + { + buf.printf("// Parsing module %s\n", m.toPrettyChars()); + m.accept(v); + } + buf.write(&done); + buf.write(&decl); + + check.writestring(` } - buf.write(&done); - buf.write(&decl); - - check.writestring(` -} -#endif + #endif `); - + debug buf.write(&check); } - -void main() -{ - import std.stdio; - import std.algorithm.sorting : sort; - import std.array : array; - import std.file : readText; - import std.path : baseName, buildPath, dirName; - import std.string : toStringz; - - import dmd.id; - import dmd.parse; - import dmd.dsymbolsem; - import dmd.semantic2; - import dmd.semantic3; - import dmd.builtin : builtin_init; - import dmd.dmodule : Module; - import dmd.cond : VersionCondition; - import dmd.expression : Expression; - import dmd.objc : Objc; - import dmd.target : Target; - - import core.memory; - - GC.disable(); - - global._init(); - global.params.isLinux = true; - global.params.is64bit = (size_t.sizeof == 8); - global.params.isLP64 = global.params.is64bit; - - global.path = new Strings(); - global.path.push(__FILE_FULL_PATH__.dirName.buildPath("../../../druntime/src/").toStringz()); - - global.filePath = new Strings(); - global.params.fileImppath = global.filePath; - global.filePath.push(__FILE_FULL_PATH__.dirName.buildPath("../../").toStringz()); - global.filePath.push(__FILE_FULL_PATH__.dirName.buildPath("../../res/").toStringz()); - - ASTCodegen.Type._init(); - Id.initialize(); - Module._init(); - Target._init(); - Expression._init(); - Objc._init(); - builtin_init(); - - VersionCondition.addPredefinedGlobalIdent("all"); - VersionCondition.addPredefinedGlobalIdent("DigitalMars"); - VersionCondition.addPredefinedGlobalIdent("Posix"); - VersionCondition.addPredefinedGlobalIdent("linux"); - VersionCondition.addPredefinedGlobalIdent("CRuntime_Glibc"); - VersionCondition.addPredefinedGlobalIdent("NoBackend"); - VersionCondition.addPredefinedGlobalIdent("NoMain"); - if (global.params.is64bit) - VersionCondition.addPredefinedGlobalIdent("X86_64"); - else - VersionCondition.addPredefinedGlobalIdent("X86"); - if (global.params.isLP64) - VersionCondition.addPredefinedGlobalIdent("D_LP64"); - - Modules modules; - - string path = __FILE_FULL_PATH__.dirName.buildPath("../dmd/"); - - foreach (f; frontendSources) - { - string fn = buildPath(path, f); - - auto id = Identifier.idPool(baseName(fn, ".d")); - auto m = new Module(fn.toStringz(), id, false, false); - auto input = readText(fn); - - if (!Module.rootModule) - Module.rootModule = m; - - m.importedFrom = m; - m.srcfile.setbuffer(cast(void*)input.ptr, input.length); - m.srcfile._ref = 1; - m.parse(); - modules.push(m); - } - - foreach (m; modules) - m.importAll(null); - foreach (m; modules) - m.dsymbolSemantic(null); - Module.dprogress = 1; - Module.runDeferredSemantic(); - foreach (m; modules) - m.semantic2(null); - Module.runDeferredSemantic2(); - foreach (m; modules) - m.semantic3(null); - Module.runDeferredSemantic3(); - - OutBuffer buf; - genCppFiles(&buf, &modules); - - writeln(buf.peekSlice()); -} diff --git a/src/posix.mak b/src/posix.mak index d11232b842c8..f35417a08909 100644 --- a/src/posix.mak +++ b/src/posix.mak @@ -624,7 +624,7 @@ dscanner: $(DSCANNER_DIR)/dsc ###################################################### $G/dtoh: $D/dtoh.d $(FRONT_SRCS) $D/gluelayer.d $(ROOT_SRCS) $G/newdelete.o $G/lexer.a $(STRING_IMPORT_FILES) $(HOST_DMD_PATH) - CC="$(HOST_CXX)" $(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J../res -L-lstdc++ $(DFLAGS) -version=NoBackend -version=NoMain $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH),$^) + CC="$(HOST_CXX)" $(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J../res -L-lstdc++ $(DFLAGS) -version=NoBackend -version=BUILD_COMPILER -version=NoMain $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH),$^) $D/frontend.h: $G/dtoh $G/dtoh > $D/frontend.h From 3e41ecf72486e71a24b29a9b2da5a535ea562761 Mon Sep 17 00:00:00 2001 From: Nicholas Lindsay Wilson Date: Sun, 18 Nov 2018 15:58:21 +0800 Subject: [PATCH 6/7] Fix stuff --- src/dmd/dtoh.d | 67 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/dmd/dtoh.d b/src/dmd/dtoh.d index a9cafc0fb8e5..f3000dc121e8 100644 --- a/src/dmd/dtoh.d +++ b/src/dmd/dtoh.d @@ -148,7 +148,7 @@ int main(string[] args) version(Windows) // delete LIB entry in [Environment] (necessary for optlink) to allow inheriting environment for MS-COFF if (is64bit || strcmp(arch, "32mscoff") == 0) - environment.update("LIB", 3).ptrvalue = null; + environment.update("LIB", 3).ptrvalue = null; // read from DFLAGS in [Environment{arch}] section char[80] envsection = void; @@ -167,13 +167,13 @@ int main(string[] args) } - version(BUILD_COMPILER) + /*version(BUILD_COMPILER) { global.path.push(druntimeFullPath.toStringz()); //TODO: fixme for LDC global.filePath.push(__FILE_FULL_PATH__.dirName.buildPath("../../").toStringz()); global.filePath.push(__FILE_FULL_PATH__.dirName.buildPath("../../res/").toStringz()); - } + }*/ DMDType._init(); version(BUILD_COMPILER) @@ -242,17 +242,32 @@ void setVersions() } } +string dirName(string path) +{ + version (Windows) + enum char separator = '\\'; + else + enum char separator = '/'; + + for (size_t i = path.length - 1; i > 0; i--) + { + if (path[i] == separator) + return path[0..i]; + } + return path; +} + struct DMDType { - static Identifier c_long; - static Identifier c_ulong; - static Identifier c_longlong; - static Identifier c_ulonglong; - static Identifier c_long_double; + __gshared static Identifier c_long; + __gshared static Identifier c_ulong; + __gshared static Identifier c_longlong; + __gshared static Identifier c_ulonglong; + __gshared static Identifier c_long_double; version(BUILD_COMPILER) { - static Identifier AssocArray; - static Identifier Array; + __gshared static Identifier AssocArray; + __gshared static Identifier Array; } static void _init() { @@ -273,14 +288,14 @@ version(BUILD_COMPILER) { struct DMDModule { - static Identifier identifier; - static Identifier root; - static Identifier visitor; - static Identifier parsetimevisitor; - static Identifier permissivevisitor; - static Identifier strictvisitor; - static Identifier transitivevisitor; - static Identifier dmd; + __gshared static Identifier identifier; + __gshared static Identifier root; + __gshared static Identifier visitor; + __gshared static Identifier parsetimevisitor; + __gshared static Identifier permissivevisitor; + __gshared static Identifier strictvisitor; + __gshared static Identifier transitivevisitor; + __gshared static Identifier dmd; static void _init() { identifier = Identifier.idPool("identifier"); @@ -295,10 +310,10 @@ version(BUILD_COMPILER) } struct DMDClass { - static Identifier ID; ////Identifier - static Identifier Visitor; - static Identifier ParseTimeVisitor; - static void _init() + __gshared static Identifier ID; ////Identifier + __gshared static Identifier Visitor; + __gshared static Identifier ParseTimeVisitor; + __gshared static void _init() { ID = Identifier.idPool("Identifier"); Visitor = Identifier.idPool("Visitor"); @@ -320,8 +335,8 @@ version(BUILD_COMPILER) { for (auto cdb = cd; cdb; cdb = cdb.baseClass) { - if (cdb.ident == DMClass.Visitor || - cdb.ident == DMClass.ParseTimeVisitor) + if (cdb.ident == DMDClass.Visitor || + cdb.ident == DMDClass.ParseTimeVisitor) return true; } return false; @@ -356,7 +371,7 @@ version(BUILD_COMPILER) (m.parent.parent.ident == DMDModule.dmd && !m.parent.parent.parent)); } - string druntimeFullPath() + /*string druntimeFullPath() { version (IN_LLVM) string path = "../runtime/druntime/src"; @@ -364,7 +379,7 @@ version(BUILD_COMPILER) string path = "../../../druntime/src/"; return __FILE_FULL_PATH__.dirName.buildPath(path); - } + }*/ } /**************************************************** From a4e436be3c522e33470a33b00939efb8cce29552 Mon Sep 17 00:00:00 2001 From: Nicholas Lindsay Wilson Date: Sun, 18 Nov 2018 16:37:57 +0800 Subject: [PATCH 7/7] include frontend.d in dtoh --- src/posix.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/posix.mak b/src/posix.mak index f35417a08909..a0917ca3f18b 100644 --- a/src/posix.mak +++ b/src/posix.mak @@ -623,7 +623,7 @@ dscanner: $(DSCANNER_DIR)/dsc ###################################################### -$G/dtoh: $D/dtoh.d $(FRONT_SRCS) $D/gluelayer.d $(ROOT_SRCS) $G/newdelete.o $G/lexer.a $(STRING_IMPORT_FILES) $(HOST_DMD_PATH) +$G/dtoh: $D/dtoh.d $D/frontend.d $(FRONT_SRCS) $D/gluelayer.d $(filter-out $(LEXER_ROOT), $(ROOT_SRCS)) $G/newdelete.o $G/lexer.a $(STRING_IMPORT_FILES) $(HOST_DMD_PATH) CC="$(HOST_CXX)" $(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J../res -L-lstdc++ $(DFLAGS) -version=NoBackend -version=BUILD_COMPILER -version=NoMain $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH),$^) $D/frontend.h: $G/dtoh