]> Cypherpunks repositories - gostls13.git/commitdiff
embedded types
authorKen Thompson <ken@golang.org>
Thu, 23 Oct 2008 01:18:08 +0000 (18:18 -0700)
committerKen Thompson <ken@golang.org>
Thu, 23 Oct 2008 01:18:08 +0000 (18:18 -0700)
auto & on methods

R=r
OCL=17682
CL=17682

src/cmd/gc/go.h
src/cmd/gc/subr.c
src/cmd/gc/walk.c

index 973b6f2c63b5824308769af59b024ed5890e2b4a..25e92bc9c3d218c09c76ec7c35f52d76a01e65b8 100644 (file)
@@ -584,6 +584,8 @@ int isinter(Type*);
 int    isnilinter(Type*);
 Sym*   globalsig(Type*);
 Type*  ismethod(Type*);
+Type*  methtype(Type*);
+int    needaddr(Type*);
 Sym*   signame(Type*, int);
 int    bytearraysz(Type*);
 int    eqtype(Type*, Type*, int);
index d81c47c9f4cc2a7c884f9a7cb8ef7050d5d3942a..4e1a9ea3a36b8edb4aa369de1cc9ad6d19194194 100644 (file)
@@ -1518,6 +1518,51 @@ out:
        return t;
 }
 
+/*
+ * this is ismethod() without side effects
+ */
+Type*
+methtype(Type *t)
+{
+       Sym *s;
+
+       if(t == T)
+               return T;
+       if(t->etype == TINTER || (t->etype == tptr && t->type->etype == TINTER))
+               return T;
+       s = t->sym;
+       if(s != S)
+               return t;
+       if(!isptr[t->etype])
+               return T;
+       t = t->type;
+       if(t == T)
+               return T;
+       s = t->sym;
+       if(s != S)
+               return t;
+       return T;
+}
+
+/*
+ * this is another ismethod()
+ * returns 1 if t=T and method wants *T
+ */
+int
+needaddr(Type *t)
+{
+       Sym *s;
+
+       if(t == T)
+               return 0;
+       if(t->etype == TINTER || (t->etype == tptr && t->type->etype == TINTER))
+               return 0;
+       s = t->sym;
+       if(s != S && t->methptr == 2)
+               return 1;
+       return 0;
+}
+
 int
 iscomposite(Type *t)
 {
index f8eb2e8a8ac0a06f00019bcf6170c32bc812dd46..1b7c1d31b58f28a106560b24c5db98d76d3802ec 100644 (file)
@@ -1422,30 +1422,6 @@ walkselect(Node *sel)
        lineno = lno;
 }
 
-Type*
-methtype(Type *t)
-{
-       Sym *s;
-
-       // this is ismethod() without diagnostics
-       if(t == T)
-               return T;
-       if(t->etype == TINTER || (t->etype == tptr && t->type->etype == TINTER))
-               return T;
-       s = t->sym;
-       if(s != S && s->name[0] != '_')
-               return t;
-       if(!isptr[t->etype])
-               return T;
-       t = t->type;
-       if(t == T)
-               return T;
-       s = t->sym;
-       if(s != S && s->name[0] != '_')
-               return t;
-       return T;
-}
-
 Type*
 lookdot1(Node *n, Type *f)
 {
@@ -1495,6 +1471,10 @@ lookdot(Node *n, Type *t)
        }
 
        if(f2 != T) {
+               if(needaddr(n->left->type)) {
+                       n->left = nod(OADDR, n->left, N);
+                       n->left->type = ptrto(n->left->left->type);
+               }
                n->right = methodname(n->right, ismethod(n->left->type));
                n->xoffset = f2->width;
                n->type = f2->type;