Skip to content

Commit

Permalink
merge with D2 pull 82
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 6, 2011
1 parent 26816f7 commit 92a9682
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 42 deletions.
62 changes: 27 additions & 35 deletions src/doc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -133,6 +133,7 @@ LINK = <a href=\"$0\">$0</a>\n\
LINK2 = <a href=\"$1\">$+</a>\n\
LPAREN= (\n\
RPAREN= )\n\
DOLLAR= $\n\
\n\
RED = <font color=red>$0</font>\n\
BLUE = <font color=blue>$0</font>\n\
Expand Down Expand Up @@ -374,6 +375,12 @@ void escapeDdocString(OutBuffer *buf, unsigned start)
unsigned char c = buf->data[u];
switch(c)
{
case '$':
buf->remove(u, 1);
buf->insert(u, "$(DOLLAR)", 9);
u += 8;
break;

case '(':
buf->remove(u, 1); //remove the (
buf->insert(u, "$(LPAREN)", 9); //insert this instead
Expand Down Expand Up @@ -792,29 +799,35 @@ void prefix(OutBuffer *buf, Dsymbol *s)
}
}

void Declaration::toDocBuffer(OutBuffer *buf)
void declarationToDocBuffer(Declaration *decl, OutBuffer *buf, TemplateDeclaration *td)
{
//printf("Declaration::toDocbuffer() %s, originalType = %p\n", toChars(), originalType);
if (ident)
//printf("declarationToDocBuffer() %s, originalType = %s, td = %s\n", decl->toChars(), decl->originalType ? decl->originalType->toChars() : "--", td ? td->toChars() : "--");
if (decl->ident)
{
prefix(buf, this);
prefix(buf, decl);

if (type)
if (decl->type)
{ HdrGenState hgs;
hgs.ddoc = 1;
if (originalType)
{ //originalType->print();
originalType->toCBuffer(buf, ident, &hgs);
Type *origType = decl->originalType ? decl->originalType : decl->type;
if (origType->ty == Tfunction)
{
TypeFunction *attrType = (TypeFunction*)(decl->ident == Id::ctor ? origType : decl->type);
((TypeFunction*)origType)->toCBufferWithAttributes(buf, decl->ident, &hgs, attrType, td);
}
else
type->toCBuffer(buf, ident, &hgs);
origType->toCBuffer(buf, decl->ident, &hgs);
}
else
buf->writestring(ident->toChars());
buf->writestring(decl->ident->toChars());
buf->writestring(";\n");
}
}

void Declaration::toDocBuffer(OutBuffer *buf)
{
declarationToDocBuffer(this, buf, NULL);
}

void AliasDeclaration::toDocBuffer(OutBuffer *buf)
{
Expand Down Expand Up @@ -859,31 +872,9 @@ void FuncDeclaration::toDocBuffer(OutBuffer *buf)
td->onemember == this)
{ /* It's a function template
*/
HdrGenState hgs;
unsigned o = buf->offset;
TypeFunction *tf = (TypeFunction *)type;

hgs.ddoc = 1;
prefix(buf, td);
if (tf)
{ if (tf->nextOf())
tf->nextOf()->toCBuffer(buf, NULL, &hgs);
else
buf->writestring("auto");
}
buf->writeByte(' ');
buf->writestring(ident->toChars());
buf->writeByte('(');
for (int i = 0; i < td->origParameters->dim; i++)
{
TemplateParameter *tp = (TemplateParameter *)td->origParameters->data[i];
if (i)
buf->writestring(", ");
tp->toCBuffer(buf, &hgs);
}
buf->writeByte(')');
Parameter::argsToCBuffer(buf, &hgs, tf ? tf->parameters : NULL, tf ? tf->varargs : 0);
buf->writestring(";\n");
declarationToDocBuffer(this, buf, td);

highlightCode(NULL, this, buf, o);
}
Expand All @@ -894,6 +885,7 @@ void FuncDeclaration::toDocBuffer(OutBuffer *buf)
}
}

#if DMDV1
void CtorDeclaration::toDocBuffer(OutBuffer *buf)
{
HdrGenState hgs;
Expand All @@ -902,7 +894,7 @@ void CtorDeclaration::toDocBuffer(OutBuffer *buf)
Parameter::argsToCBuffer(buf, &hgs, arguments, varargs);
buf->writestring(";\n");
}

#endif

void AggregateDeclaration::toDocBuffer(OutBuffer *buf)
{
Expand Down
9 changes: 9 additions & 0 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extern "C" char * __cdecl __locale_decpoint;
#include "attrib.h"
#include "hdrgen.h"
#include "parse.h"
#include "doc.h"


Expression *createTypeInfoArray(Scope *sc, Expression *args[], int dim);
Expand Down Expand Up @@ -1447,13 +1448,18 @@ void IntegerExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
break;
}
case Tchar:
{
unsigned o = buf->offset;
if (v == '\'')
buf->writestring("'\\''");
else if (isprint(v) && v != '\\')
buf->printf("'%c'", (int)v);
else
buf->printf("'\\x%02x'", (int)v);
if (hgs->ddoc)
escapeDdocString(buf, o);
break;
}

case Tint8:
buf->writestring("cast(byte)");
Expand Down Expand Up @@ -2756,6 +2762,7 @@ unsigned StringExp::charAt(size_t i)
void StringExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writeByte('"');
unsigned o = buf->offset;
for (size_t i = 0; i < len; i++)
{ unsigned c = charAt(i);

Expand All @@ -2780,6 +2787,8 @@ void StringExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
break;
}
}
if (hgs->ddoc)
escapeDdocString(buf, o);
buf->writeByte('"');
if (postfix)
buf->writeByte(postfix);
Expand Down
22 changes: 16 additions & 6 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include "import.h"
#include "aggregate.h"
#include "hdrgen.h"
#include "doc.h"

FuncDeclaration *hasThis(Scope *sc);

Expand Down Expand Up @@ -2800,6 +2799,11 @@ void TypeFunction::toDecoBuffer(OutBuffer *buf)
}

void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs)
{
toCBufferWithAttributes(buf, ident, hgs, this, NULL);
}

void TypeFunction::toCBufferWithAttributes(OutBuffer *buf, Identifier *ident, HdrGenState* hgs, TypeFunction *attrs, TemplateDeclaration *td)
{
const char *p = NULL;

Expand Down Expand Up @@ -2830,6 +2834,17 @@ void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs
{ buf->writeByte(' ');
buf->writestring(ident->toHChars2());
}
if (td)
{ buf->writeByte('(');
for (int i = 0; i < td->origParameters->dim; i++)
{
TemplateParameter *tp = (TemplateParameter *)td->origParameters->data[i];
if (i)
buf->writestring(", ");
tp->toCBuffer(buf, hgs);
}
buf->writeByte(')');
}
Parameter::argsToCBuffer(buf, hgs, parameters, varargs);
inuse--;
}
Expand Down Expand Up @@ -5541,12 +5556,7 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
if (arg->defaultArg)
{
argbuf.writestring(" = ");
unsigned o = argbuf.offset;
arg->defaultArg->toCBuffer(&argbuf, hgs);
if(hgs->ddoc)
{
escapeDdocString(&argbuf, o);
}
}
buf->write(&argbuf);
}
Expand Down
3 changes: 2 additions & 1 deletion src/mtype.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -475,6 +475,7 @@ struct TypeFunction : Type
Type *semantic(Loc loc, Scope *sc);
void toDecoBuffer(OutBuffer *buf);
void toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs);
void toCBufferWithAttributes(OutBuffer *buf, Identifier *ident, HdrGenState* hgs, TypeFunction *attrs, TemplateDeclaration *td);
void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
TypeInfoDeclaration *getTypeInfoDeclaration();
Expand Down
16 changes: 16 additions & 0 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,20 @@ TemplateDeclaration::TemplateDeclaration(Loc loc, Identifier *id,
this->overroot = NULL;
this->semanticRun = 0;
this->onemember = NULL;

// Compute in advance for Ddoc's use
if (members)
{
Dsymbol *s;
if (Dsymbol::oneMembers(members, &s))
{
if (s && s->ident && s->ident->equals(ident))
{
onemember = s;
s->parent = this;
}
}
}
}

Dsymbol *TemplateDeclaration::syntaxCopy(Dsymbol *)
Expand Down Expand Up @@ -484,6 +498,8 @@ void TemplateDeclaration::semantic(Scope *sc)

paramscope->pop();

// Compute again
onemember = NULL;
if (members)
{
Dsymbol *s;
Expand Down

0 comments on commit 92a9682

Please sign in to comment.