comparison dmd2/aliasthis.c @ 1452:638d16625da2

LDC 2 compiles again.
author Robert Clipsham <robert@octarineparrot.com>
date Sat, 30 May 2009 17:23:32 +0100
parents
children
comparison
equal deleted inserted replaced
1423:42bd767ec5a4 1452:638d16625da2
1
2 // Compiler implementation of the D programming language
3 // Copyright (c) 2009-2009 by Digital Mars
4 // All Rights Reserved
5 // written by Walter Bright
6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
10
11 #include <stdio.h>
12 #include <assert.h>
13
14 #include "mars.h"
15 #include "identifier.h"
16 #include "aliasthis.h"
17 #include "scope.h"
18 #include "aggregate.h"
19 #include "dsymbol.h"
20
21 #if DMDV2
22
23
24 AliasThis::AliasThis(Loc loc, Identifier *ident)
25 : Dsymbol(NULL) // it's anonymous (no identifier)
26 {
27 this->loc = loc;
28 this->ident = ident;
29 }
30
31 Dsymbol *AliasThis::syntaxCopy(Dsymbol *s)
32 {
33 assert(!s);
34 /* Since there is no semantic information stored here,
35 * we don't need to copy it.
36 */
37 return this;
38 }
39
40 void AliasThis::semantic(Scope *sc)
41 {
42 Dsymbol *parent = sc->parent;
43 if (parent)
44 parent = parent->pastMixin();
45 AggregateDeclaration *ad = NULL;
46 if (parent)
47 ad = parent->isAggregateDeclaration();
48 if (ad)
49 {
50 if (ad->aliasthis)
51 error("there can be only one alias this");
52 assert(ad->members);
53 Dsymbol *s = ad->search(loc, ident, 0);
54 ad->aliasthis = s;
55 }
56 else
57 error("alias this can only appear in struct or class declaration, not %s", parent ? parent->toChars() : "nowhere");
58 }
59
60 const char *AliasThis::kind()
61 {
62 return "alias this";
63 }
64
65 void AliasThis::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
66 {
67 buf->writestring("alias ");
68 buf->writestring(ident->toChars());
69 buf->writestring(" this;\n");
70 }
71
72 #endif