parse/type.c
/*
 * Shallowly duplicates a type, so we can frob
 * its internals later
 */
Shallowly duplicates a type, so we can frob
its internals later
Shallowly duplicates a type so we can frob its internals later
Type *tydup(Type *t)
{
    Type *r;
    r = mktype(t->loc, t->type);
    r->resolved = 0; 
    r->fixed = 0; 
    r->traits = bsdup(t->traits);
    r->traitlist = memdup(t->traitlist, t->ntraitlist * sizeof(Node*));
    r->ntraitlist = t->ntraitlist;
    r->arg = memdup(t->arg, t->narg * sizeof(Type*));
    r->narg = t->narg;
    r->inst = memdup(t->arg, t->narg * sizeof(Type*));
    r->ninst = t->ninst;
    r->sub = memdup(t->sub, t->nsub * sizeof(Type*));
    r->nsub = t->nsub;
    r->nmemb = t->nmemb;
    switch (t->type) {
        case Tyname:   	r->name = t->name;              break;
        case Tyunres:   r->name = t->name;              break;
        case Tyarray:   r->asize = t->asize;            break;
        case Typaram:   r->pname = strdup(t->pname);    break;
        case Tystruct:  r->sdecls = memdup(t->sdecls, t->nmemb*sizeof(Node*));   break;
        case Tyunion:   r->udecls = memdup(t->udecls, t->nmemb*sizeof(Node*));   break;
        default:        break;
    }
    return r;
}
Type * tydup ( Type * t ) { Type * r ; r = mktype ( t -> loc , t -> type ) ; r -> resolved = 0 ; r -> fixed = 0 ; r -> traits = bsdup ( t -> traits ) ; r -> traitlist = memdup ( t -> traitlist , t -> ntraitlist * sizeof ( Node * ) ) ; r -> ntraitlist = t -> ntraitlist ; r -> arg = memdup ( t -> arg , t -> narg * sizeof ( Type * ) ) ; r -> narg = t -> narg ; r -> inst = memdup ( t -> arg , t -> narg * sizeof ( Type * ) ) ; r -> ninst = t -> ninst ; r -> sub = memdup ( t -> sub , t -> nsub * sizeof ( Type * ) ) ; r -> nsub = t -> nsub ; r -> nmemb = t -> nmemb ; switch ( t -> type ) { case Tyname : r -> name = t -> name ; break ; case Tyunres : r -> name = t -> name ; break ; case Tyarray : r -> asize = t -> asize ; break ; case Typaram : r -> pname = strdup ( t -> pname ) ; break ; case Tystruct : r -> sdecls = memdup ( t -> sdecls , t -> nmemb * sizeof ( Node * ) ) ; break ; case Tyunion : r -> udecls = memdup ( t -> udecls , t -> nmemb * sizeof ( Node * ) ) ; break ; default : break ; } return r ; }
Shallowly duplicates a type, so we can frob
 its internals later
Shallowly duplicates a type so we can frob its internals later
/* re-resolving doesn't hurt */ /* re-resolving doesn't hurt */