Skip to content

Commit

Permalink
Merge branch 'master' of github.com:D-Programming-Language/dmd
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Apr 8, 2013
2 parents 81009a1 + 94e608a commit 44fe0d0
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 60 deletions.
13 changes: 12 additions & 1 deletion src/aliasthis.c
Expand Up @@ -38,9 +38,20 @@ Expression *resolveAliasThis(Scope *sc, Expression *e)
{
bool isstatic = (e->op == TOKtype);
e = new DotIdExp(e->loc, e, ad->aliasthis->ident);
e = e->semantic(sc);
if (isstatic && ad->aliasthis->needThis())
{
/* non-@property function is not called inside typeof(),
* so resolve it ahead.
*/
int save = sc->intypeof;
sc->intypeof = 1; // bypass "need this" error check
e = resolveProperties(sc, e);
sc->intypeof = save;

e = new TypeExp(e->loc, new TypeTypeof(e->loc, e));
e = e->semantic(sc);
e = e->semantic(sc);
}
e = resolveProperties(sc, e);
}
}
Expand Down
95 changes: 47 additions & 48 deletions src/doc.c
Expand Up @@ -475,6 +475,42 @@ void escapeStrayParenthesis(OutBuffer *buf, size_t start, Loc loc)
}
}

static bool emitAnchorName(OutBuffer *buf, Dsymbol *s)
{
if (!s || s->isPackage() || s->isModule())
return false;

TemplateDeclaration *td;
bool dot;

// Add parent names first
dot = emitAnchorName(buf, s->parent);
// Eponymous template members can share the parent anchor name
if (s->parent && (td = s->parent->isTemplateDeclaration()) != NULL &&
td->onemember == s)
return dot;
if (dot)
buf->writeByte('.');
// Use "this" not "__ctor"
if (s->isCtorDeclaration() || ((td = s->isTemplateDeclaration()) != NULL &&
td->onemember && td->onemember->isCtorDeclaration()))
buf->writestring("this");
else
{
/* We just want the identifier, not overloads like TemplateDeclaration::toChars.
* We don't want the template parameter list and constraints. */
buf->writestring(s->Dsymbol::toChars());
}
return true;
}

static void emitAnchor(OutBuffer *buf, Dsymbol *s)
{
buf->writestring("$(DDOC_ANCHOR ");
emitAnchorName(buf, s);
buf->writeByte(')');
}

/******************************* emitComment **********************************/

/** Get leading indentation from 'src' which represents lines of code. */
Expand Down Expand Up @@ -679,8 +715,10 @@ void AggregateDeclaration::emitComment(Scope *sc)
dc->pmacrotable = &sc->module->macrotable;

buf->writestring(ddoc_decl_s);
toDocBuffer(buf, sc);
sc->lastoffset = buf->offset;
size_t o = buf->offset;
toDocBuffer(buf, sc);
highlightCode(sc, this, buf, o);
sc->lastoffset = buf->offset;
buf->writestring(ddoc_decl_e);

buf->writestring(ddoc_decl_dd_s);
Expand Down Expand Up @@ -776,7 +814,9 @@ void EnumDeclaration::emitComment(Scope *sc)
dc->pmacrotable = &sc->module->macrotable;

buf->writestring(ddoc_decl_s);
size_t o = buf->offset;
toDocBuffer(buf, sc);
highlightCode(sc, this, buf, o);
sc->lastoffset = buf->offset;
buf->writestring(ddoc_decl_e);

Expand All @@ -796,7 +836,6 @@ void EnumMember::emitComment(Scope *sc)

OutBuffer *buf = sc->docbuf;
DocComment *dc = DocComment::parse(sc, this, comment);
size_t o;

if (!dc)
{
Expand All @@ -806,7 +845,7 @@ void EnumMember::emitComment(Scope *sc)
dc->pmacrotable = &sc->module->macrotable;

buf->writestring(ddoc_decl_s);
o = buf->offset;
size_t o = buf->offset;
toDocBuffer(buf, sc);
highlightCode(sc, this, buf, o);
sc->lastoffset = buf->offset;
Expand All @@ -817,42 +856,6 @@ void EnumMember::emitComment(Scope *sc)
buf->writestring(ddoc_decl_dd_e);
}

static bool emitAnchorName(OutBuffer *buf, Dsymbol *s)
{
if (!s || s->isPackage() || s->isModule())
return false;

TemplateDeclaration *td;
bool dot;

// Add parent names first
dot = emitAnchorName(buf, s->parent);
// Eponymous template members can share the parent anchor name
if (s->parent && (td = s->parent->isTemplateDeclaration()) != NULL &&
td->onemember == s)
return dot;
if (dot)
buf->writeByte('.');
// Use "this" not "__ctor"
if (s->isCtorDeclaration() || ((td = s->isTemplateDeclaration()) != NULL &&
td->onemember && td->onemember->isCtorDeclaration()))
buf->writestring("this");
else
{
/* We just want the identifier, not overloads like TemplateDeclaration::toChars.
* We don't want the template parameter list and constraints. */
buf->writestring(s->Dsymbol::toChars());
}
return true;
}

static void emitAnchor(OutBuffer *buf, Dsymbol *s)
{
buf->writestring("$(DDOC_ANCHOR ");
emitAnchorName(buf, s);
buf->writeByte(')');
}

/******************************* toDocBuffer **********************************/

void Dsymbol::toDocBuffer(OutBuffer *buf, Scope *sc)
Expand Down Expand Up @@ -1067,11 +1070,10 @@ void AggregateDeclaration::toDocBuffer(OutBuffer *buf, Scope *sc)
{
if (ident)
{
emitAnchor(buf, this);
#if 0
emitProtection(buf, protection);
#endif
buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
buf->printf("%s %s", kind(), toChars());
buf->writestring(";\n");
}
}
Expand All @@ -1095,8 +1097,7 @@ void StructDeclaration::toDocBuffer(OutBuffer *buf, Scope *sc)
}
else
{
emitAnchor(buf, this);
buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
buf->printf("%s %s", kind(), toChars());
}
buf->writestring(";\n");
}
Expand All @@ -1121,10 +1122,9 @@ void ClassDeclaration::toDocBuffer(OutBuffer *buf, Scope *sc)
}
else
{
emitAnchor(buf, this);
if (isAbstract())
buf->writestring("abstract ");
buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
buf->printf("%s %s", kind(), toChars());
}
int any = 0;
for (size_t i = 0; i < baseclasses->dim; i++)
Expand Down Expand Up @@ -1161,8 +1161,7 @@ void EnumDeclaration::toDocBuffer(OutBuffer *buf, Scope *sc)
{
if (ident)
{
emitAnchor(buf, this);
buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars());
buf->printf("%s %s", kind(), toChars());
buf->writestring(";\n");
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/expression.c
Expand Up @@ -5914,6 +5914,8 @@ Expression *IsExp::semantic(Scope *sc)
{ ClassDeclaration *cd = ((TypeClass *)targ)->sym;
Parameters *args = new Parameters;
args->reserve(cd->baseclasses->dim);
if (cd->scope && !cd->symtab)
cd->semantic(cd->scope);
for (size_t i = 0; i < cd->baseclasses->dim; i++)
{ BaseClass *b = (*cd->baseclasses)[i];
args->push(new Parameter(STCin, b->type, NULL, NULL));
Expand Down
4 changes: 2 additions & 2 deletions src/interpret.c
Expand Up @@ -3933,7 +3933,7 @@ Expression *CallExp::interpret(InterState *istate, CtfeGoal goal)
Expression * pe = ((PtrExp*)ecall)->e1;
if (pe->op == TOKvar) {
VarDeclaration *vd = ((VarExp *)((PtrExp*)ecall)->e1)->var->isVarDeclaration();
if (vd && vd->getValue() && vd->getValue()->op == TOKsymoff)
if (vd && vd->hasValue() && vd->getValue()->op == TOKsymoff)
fd = ((SymOffExp *)vd->getValue())->var->isFuncDeclaration();
else
{
Expand Down Expand Up @@ -3974,7 +3974,7 @@ Expression *CallExp::interpret(InterState *istate, CtfeGoal goal)
else if (ecall->op == TOKvar)
{
VarDeclaration *vd = ((VarExp *)ecall)->var->isVarDeclaration();
if (vd && vd->getValue())
if (vd && vd->hasValue())
ecall = vd->getValue();
else // Calling a function
fd = ((VarExp *)e1)->var->isFuncDeclaration();
Expand Down
6 changes: 2 additions & 4 deletions src/mars.c
Expand Up @@ -369,9 +369,7 @@ Usage:\n\
-quiet suppress unnecessary messages\n\
-release compile release version\n\
-run srcfile args... run resulting program, passing args\n"
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
" -shared generate shared library\n"
#endif
" -shared generate shared library (DLL)\n"
" -unittest compile in unit tests\n\
-v verbose\n\
-version=level compile in version code >= level\n\
Expand Down Expand Up @@ -572,14 +570,14 @@ int tryMain(size_t argc, char *argv[])
else if (p[4])
goto Lerror;
}
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
else if (strcmp(p + 1, "shared") == 0
#if TARGET_OSX
// backwards compatibility with old switch
|| strcmp(p + 1, "dylib") == 0
#endif
)
global.params.dll = 1;
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
else if (strcmp(p + 1, "fPIC") == 0)
global.params.pic = 1;
#endif
Expand Down
6 changes: 4 additions & 2 deletions src/msc.c
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2012 by Digital Mars
// Copyright (c) 1999-2013 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -71,7 +71,9 @@ void backend_init()
bool exe;
#if TARGET_WINDOS
exe = false;
if (params->run)
if (params->dll)
;
else if (params->run)
exe = true; // EXE file only optimizations
else if (params->link && !global.params.deffile)
exe = true; // EXE file only optimizations
Expand Down
35 changes: 35 additions & 0 deletions test/compilable/ddoc9903.d
@@ -0,0 +1,35 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Ddtest_results/compilable -o-
// POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9903

/// sss
struct S9903X {}
/// Ditto
struct S9903Y {}

/// ccc
class C9903X {}
/// Ditto
class C9903Y {}

/// uuu
union U9903X {}
/// Ditto
union U9903Y {}

/// iii
interface I9903X {}
/// Ditto
interface I9903Y {}

/// eee
enum E9903X { a }
/// Ditto
enum E9903Y { a }

///
enum {
a9903, /// ea
b9903, /// Ditto
c9903, /// ec
}
48 changes: 48 additions & 0 deletions test/compilable/extra-files/ddoc9903.html
@@ -0,0 +1,48 @@
<html><head>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<title>ddoc9903</title>
</head><body>
<h1>ddoc9903</h1>
<br><br>
<dl><dt><big><a name="S9903X"></a>struct <u>S9903X</u>;
<br><a name="S9903Y"></a>struct <u>S9903Y</u>;
</big></dt>
<dd>sss<br><br>

</dd>
<dt><big><a name="C9903X"></a>class <u>C9903X</u>;
<br><a name="C9903Y"></a>class <u>C9903Y</u>;
</big></dt>
<dd>ccc<br><br>

</dd>
<dt><big><a name="U9903X"></a>union <u>U9903X</u>;
<br><a name="U9903Y"></a>union <u>U9903Y</u>;
</big></dt>
<dd>uuu<br><br>

</dd>
<dt><big><a name="I9903X"></a>interface <u>I9903X</u>;
<br><a name="I9903Y"></a>interface <u>I9903Y</u>;
</big></dt>
<dd>iii<br><br>

</dd>
<dt><big><a name="E9903X"></a>enum <u>E9903X</u>;
<br><a name="E9903Y"></a>enum <u>E9903Y</u>;
</big></dt>
<dd>eee<br><br>

</dd>
<dt><big><a name="a9903"></a><u>a9903</u><br><a name="b9903"></a><u>b9903</u></big></dt>
<dd>ea<br><br>

</dd>
<dt><big><a name="c9903"></a><u>c9903</u></big></dt>
<dd>ec<br><br>

</dd>
</dl>

<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. </small>
</body></html>
12 changes: 12 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -4640,6 +4640,18 @@ void bug7419() {
static assert(x == 3);
}

/**************************************************
9445 ice
**************************************************/

template c9445(T...) { }

void ice9445(void delegate() expr, void function() f2)
{
static assert(!is(typeof(c9445!(f2()))));
static assert(!is(typeof(c9445!(expr()))));
}

/**************************************************
7162 and 4711
**************************************************/
Expand Down
8 changes: 7 additions & 1 deletion test/compilable/test9680.sh
Expand Up @@ -3,7 +3,13 @@
name=`basename $0 .sh`
dir=${RESULTS_DIR}/compilable

for kind in main winmain dllmain
if [ "${OS}" == "win32" -o "${OS}" == "Windows_NT" ]; then
kinds=( main winmain dllmain )
else
kinds=( main )
fi

for kind in "${kinds[@]}"
do
file_name=${name}${kind}
src_file=compilable/extra-files/${file_name}.d
Expand Down
4 changes: 2 additions & 2 deletions test/compilable/test9692.d
Expand Up @@ -3,5 +3,5 @@ module test9692;
import test9692a;
import imports.test9692b;

enum x = __traits(allMembers, imports.test9692b); // ok
enum y = __traits(allMembers, test9692a); // ng: should work
enum x = [__traits(allMembers, imports.test9692b)]; // ok
enum y = [__traits(allMembers, test9692a)]; // ng: should work

0 comments on commit 44fe0d0

Please sign in to comment.