Permalink
Browse files

Minimize differences between original dmd source and ldc1.

Mainly affects formatting but I also found some code differences.
  • Loading branch information...
redstar committed Apr 10, 2012
1 parent 473a5ec commit f1998a61108a7e112fffdd7775a803a4c6e2a030
Showing with 696 additions and 353 deletions.
  1. +1 −1 dmd/aggregate.h
  2. +188 −0 dmd/argtypes.c
  3. +38 −38 dmd/arrayop.c
  4. +9 −5 dmd/attrib.c
  5. +1 −1 dmd/attrib.h
  6. +7 −7 dmd/cast.c
  7. +1 −1 dmd/class.c
  8. +3 −3 dmd/constfold.c
  9. +12 −4 dmd/declaration.c
  10. +5 −3 dmd/declaration.h
  11. +11 −11 dmd/doc.c
  12. +7 −7 dmd/dsymbol.c
  13. +1 −0 dmd/enum.c
  14. +42 −29 dmd/expression.c
  15. +15 −10 dmd/expression.h
  16. +41 −39 dmd/func.c
  17. +42 −3 dmd/html.c
  18. +2 −3 dmd/html.h
  19. +2 −0 dmd/idgen.c
  20. +2 −0 dmd/imphint.c
  21. +2 −1 dmd/init.c
  22. +0 −1 dmd/inline.c
  23. +107 −108 dmd/interpret.c
  24. +4 −3 dmd/lexer.c
  25. +1 −0 dmd/lexer.h
  26. +3 −3 dmd/module.h
  27. +34 −16 dmd/mtype.c
  28. +25 −5 dmd/mtype.h
  29. +10 −9 dmd/parse.c
  30. +1 −1 dmd/scope.c
  31. +12 −11 dmd/statement.c
  32. +4 −1 dmd/statement.h
  33. +38 −3 dmd/struct.c
  34. +24 −24 dmd/template.c
  35. +0 −1 dmd/template.h
  36. +1 −1 dmd/utf.c
View
@@ -257,7 +257,7 @@ struct ClassDeclaration : AggregateDeclaration
ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration
int com; // !=0 if this is a COM class (meaning
// it derives from IUnknown)
- int isscope; // !=0 if this is a scope class
+ int isscope; // !=0 if this is an auto class
int isabstract; // !=0 if abstract class
#if DMDV1
int isnested; // !=0 if is nested
View
@@ -0,0 +1,188 @@
+
+// Compiler implementation of the D programming language
+// Copyright (c) 2010-2011 by Digital Mars
+// All Rights Reserved
+// written by Walter Bright
+// http://www.digitalmars.com
+// http://www.dsource.org/projects/dmd/browser/branches/dmd-1.x/src/argtypes.c
+// License for redistribution is by either the Artistic License
+// in artistic.txt, or the GNU General Public License in gnu.txt.
+// See the included readme.txt for details.
+
+#include <stdio.h>
+#include <assert.h>
+
+#include "mars.h"
+#include "dsymbol.h"
+#include "mtype.h"
+#include "scope.h"
+#include "init.h"
+#include "expression.h"
+#include "attrib.h"
+#include "declaration.h"
+#include "template.h"
+#include "id.h"
+#include "enum.h"
+#include "import.h"
+#include "aggregate.h"
+#include "hdrgen.h"
+
+/****************************************************
+ * This breaks a type down into 'simpler' types that can be passed to a function
+ * in registers, and returned in registers.
+ * It's highly platform dependent.
+ * Returning a tuple of zero length means the type cannot be passed/returned in registers.
+ */
+
+
+TypeTuple *Type::toArgTypes()
+{
+ return NULL; // not valid for a parameter
+}
+
+
+TypeTuple *TypeBasic::toArgTypes()
+{ Type *t1 = NULL;
+ Type *t2 = NULL;
+ switch (ty)
+ {
+ case Tvoid:
+ return NULL;
+
+ case Tbool:
+ case Tint8:
+ case Tuns8:
+ case Tint16:
+ case Tuns16:
+ case Tint32:
+ case Tuns32:
+ case Tfloat32:
+ case Tint64:
+ case Tuns64:
+ case Tfloat64:
+ case Tfloat80:
+ t1 = this;
+ break;
+
+ case Timaginary32:
+ t1 = Type::tfloat32;
+ break;
+
+ case Timaginary64:
+ t1 = Type::tfloat64;
+ break;
+
+ case Timaginary80:
+ t1 = Type::tfloat80;
+ break;
+
+ case Tcomplex32:
+ if (global.params.is64bit)
+ t1 = Type::tfloat64; // weird, eh?
+ else
+ {
+ t1 = Type::tfloat64;
+ t2 = Type::tfloat64;
+ }
+ break;
+
+ case Tcomplex64:
+ //t1 = Type::tfloat64;
+ //t2 = Type::tfloat64;
+ break;
+
+ case Tcomplex80:
+ t1 = Type::tfloat80;
+ t2 = Type::tfloat80;
+ break;
+
+ case Tascii:
+ t1 = Type::tuns8;
+ break;
+
+ case Twchar:
+ t1 = Type::tuns16;
+ break;
+
+ case Tdchar:
+ t1 = Type::tuns32;
+ break;
+
+ default: assert(0);
+ }
+
+ TypeTuple *t;
+ if (t1)
+ {
+ if (t2)
+ t = new TypeTuple(t1, t2);
+ else
+ t = new TypeTuple(t1);
+ }
+ else
+ t = new TypeTuple();
+ return t;
+}
+
+TypeTuple *TypeSArray::toArgTypes()
+{
+#if DMDV2
+ return new TypeTuple(); // pass on the stack for efficiency
+#else
+ return new TypeTuple(Type::tvoidptr);
+#endif
+}
+
+TypeTuple *TypeDArray::toArgTypes()
+{
+ return new TypeTuple(); // pass on the stack for efficiency
+}
+
+TypeTuple *TypeAArray::toArgTypes()
+{
+ return new TypeTuple(Type::tvoidptr);
+}
+
+TypeTuple *TypePointer::toArgTypes()
+{
+ return new TypeTuple(this);
+}
+
+TypeTuple *TypeDelegate::toArgTypes()
+{
+ return new TypeTuple(); // pass on the stack for efficiency
+}
+
+TypeTuple *TypeStruct::toArgTypes()
+{
+ d_uns64 sz = size(0);
+ assert(sz < 0xFFFFFFFF);
+ switch ((unsigned)sz)
+ {
+ case 1:
+ return new TypeTuple(Type::tint8);
+ case 2:
+ return new TypeTuple(Type::tint16);
+ case 4:
+ return new TypeTuple(Type::tint32);
+ case 8:
+ return new TypeTuple(Type::tint64);
+ }
+ return new TypeTuple(); // pass on the stack
+}
+
+TypeTuple *TypeEnum::toArgTypes()
+{
+ return toBasetype()->toArgTypes();
+}
+
+TypeTuple *TypeTypedef::toArgTypes()
+{
+ return sym->basetype->toArgTypes();
+}
+
+TypeTuple *TypeClass::toArgTypes()
+{
+ return new TypeTuple(Type::tvoidptr);
+}
+
View
@@ -314,57 +314,57 @@ Expression *BinExp::arrayOp(Scope *sc)
}
#endif
#endif
- /* Not in library, so generate it.
- * Construct the function body:
- * foreach (i; 0 .. p.length) for (size_t i = 0; i < p.length; i++)
- * loopbody;
- * return p;
- */
-
- Parameters *fparams = new Parameters();
- Expression *loopbody = buildArrayLoop(fparams);
+ /* Not in library, so generate it.
+ * Construct the function body:
+ * foreach (i; 0 .. p.length) for (size_t i = 0; i < p.length; i++)
+ * loopbody;
+ * return p;
+ */
+
+ Parameters *fparams = new Parameters();
+ Expression *loopbody = buildArrayLoop(fparams);
Parameter *p = (*fparams)[0 /*fparams->dim - 1*/];
#if DMDV1
- // for (size_t i = 0; i < p.length; i++)
- Initializer *init = new ExpInitializer(0, new IntegerExp(0, 0, Type::tsize_t));
- Dsymbol *d = new VarDeclaration(0, Type::tsize_t, Id::p, init);
- Statement *s1 = new ForStatement(0,
+ // for (size_t i = 0; i < p.length; i++)
+ Initializer *init = new ExpInitializer(0, new IntegerExp(0, 0, Type::tsize_t));
+ Dsymbol *d = new VarDeclaration(0, Type::tsize_t, Id::p, init);
+ Statement *s1 = new ForStatement(0,
new ExpStatement(0, d),
- new CmpExp(TOKlt, 0, new IdentifierExp(0, Id::p), new ArrayLengthExp(0, new IdentifierExp(0, p->ident))),
- new PostExp(TOKplusplus, 0, new IdentifierExp(0, Id::p)),
- new ExpStatement(0, loopbody));
+ new CmpExp(TOKlt, 0, new IdentifierExp(0, Id::p), new ArrayLengthExp(0, new IdentifierExp(0, p->ident))),
+ new PostExp(TOKplusplus, 0, new IdentifierExp(0, Id::p)),
+ new ExpStatement(0, loopbody));
#else
- // foreach (i; 0 .. p.length)
- Statement *s1 = new ForeachRangeStatement(0, TOKforeach,
- new Parameter(0, NULL, Id::p, NULL),
- new IntegerExp(0, 0, Type::tint32),
- new ArrayLengthExp(0, new IdentifierExp(0, p->ident)),
- new ExpStatement(0, loopbody));
+ // foreach (i; 0 .. p.length)
+ Statement *s1 = new ForeachRangeStatement(0, TOKforeach,
+ new Parameter(0, NULL, Id::p, NULL),
+ new IntegerExp(0, 0, Type::tint32),
+ new ArrayLengthExp(0, new IdentifierExp(0, p->ident)),
+ new ExpStatement(0, loopbody));
#endif
- Statement *s2 = new ReturnStatement(0, new IdentifierExp(0, p->ident));
- //printf("s2: %s\n", s2->toChars());
- Statement *fbody = new CompoundStatement(0, s1, s2);
-
- /* Construct the function
- */
- TypeFunction *ftype = new TypeFunction(fparams, type, 0, LINKc);
- //printf("ftype: %s\n", ftype->toChars());
+ Statement *s2 = new ReturnStatement(0, new IdentifierExp(0, p->ident));
+ //printf("s2: %s\n", s2->toChars());
+ Statement *fbody = new CompoundStatement(0, s1, s2);
+
+ /* Construct the function
+ */
+ TypeFunction *ftype = new TypeFunction(fparams, type, 0, LINKc);
+ //printf("ftype: %s\n", ftype->toChars());
fd = new FuncDeclaration(loc, 0, ident, STCundefined, ftype);
- fd->fbody = fbody;
- fd->protection = PROTpublic;
+ fd->fbody = fbody;
+ fd->protection = PROTpublic;
fd->linkage = LINKc;
fd->isArrayOp = 1;
- sc->module->importedFrom->members->push(fd);
+ sc->module->importedFrom->members->push(fd);
- sc = sc->push();
- sc->parent = sc->module->importedFrom;
- sc->stc = 0;
+ sc = sc->push();
+ sc->parent = sc->module->importedFrom;
+ sc->stc = 0;
sc->linkage = LINKc;
- fd->semantic(sc);
+ fd->semantic(sc);
fd->semantic2(sc);
fd->semantic3(sc);
- sc->pop();
+ sc->pop();
#if IN_DMD
}
else
View
@@ -585,8 +585,8 @@ void LinkDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
case LINKwindows: p = "Windows"; break;
case LINKpascal: p = "Pascal"; break;
- // LDC
- case LINKintrinsic: p = "Intrinsic"; break;
+ // LDC
+ case LINKintrinsic: p = "Intrinsic"; break;
default:
assert(0);
@@ -714,12 +714,15 @@ void AlignDeclaration::setScope(Scope *sc)
void AlignDeclaration::semantic(Scope *sc)
{
-// LDC
-// we only support packed structs, as from the spec: align(1) struct Packed { ... }
-// other alignments are simply ignored. my tests show this is what llvm-gcc does too ...
+ // LDC
+ // we only support packed structs, as from the spec: align(1) struct Packed { ... }
+ // other alignments are simply ignored. my tests show this is what llvm-gcc does too ...
+ if (decl)
{
semanticNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign);
}
+ else
+ assert(0 && "what kind of align use triggers this?");
}
@@ -1130,6 +1133,7 @@ void PragmaDeclaration::semantic(Scope *sc)
}
printf("\n");
}
+ goto Lnodecl;
}
else
error("unrecognized pragma(%s)", ident->toChars());
View
@@ -57,7 +57,7 @@ struct AttribDeclaration : Dsymbol
AttribDeclaration *isAttribDeclaration() { return this; }
#if IN_DMD
- virtual void toObjFile(int multiobj); // compile to .obj file
+ void toObjFile(int multiobj); // compile to .obj file
int cvMember(unsigned char *p);
#endif
View
@@ -404,12 +404,11 @@ MATCH StringExp::implicitConvTo(Type *t)
printf("StringExp::implicitConvTo(this=%s, committed=%d, type=%s, t=%s)\n",
toChars(), committed, type->toChars(), t->toChars());
#endif
- if (!committed)
- {
if (!committed && t->ty == Tpointer && t->next->ty == Tvoid)
{
return MATCHnomatch;
}
+ if (!committed)
if (type->ty == Tsarray || type->ty == Tarray || type->ty == Tpointer)
{
if (type->next->ty == Tchar)
@@ -428,15 +427,16 @@ MATCH StringExp::implicitConvTo(Type *t)
L1:
if (t->next->ty == Tchar)
return MATCHexact;
- else if (t->next->ty == Twchar)
- return MATCHexact;
- else if (t->next->ty == Tdchar)
- return MATCHexact;
+ else if (!committed)
+ { if (t->next->ty == Twchar)
+ return MATCHexact;
+ else if (t->next->ty == Tdchar)
+ return MATCHexact;
+ }
break;
}
}
}
- }
return Expression::implicitConvTo(t);
#if 0
m = (MATCH)type->implicitConvTo(t);
View
@@ -824,7 +824,7 @@ int ClassDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
{
cd->semantic(NULL);
if (!cd->baseClass)
- cd->error("base class is forward referenced by %s", toChars());
+ cd->error("base class is forward referenced by %s", toChars());
}
if (this == cd->baseClass)
Oops, something went wrong.

0 comments on commit f1998a6

Please sign in to comment.