void dlappend(Datalist* dl, NCConstant* constant) { if(dl->length >= dl->alloc) dlextend(dl); if(constant == NULL) constant = &nullconstant; dl->data[dl->length++] = *constant; }
/* Generate type definitions */ static void genbin_deftype(Symbol* tsym) { int i,stat; ASSERT(tsym->objectclass == NC_TYPE); switch (tsym->subclass) { case NC_PRIM: break; /* these are already taken care of*/ case NC_OPAQUE: stat = nc_def_opaque(tsym->container->ncid, tsym->typ.size, tsym->name, &tsym->ncid); check_err(stat,__LINE__,__FILE__); break; case NC_ENUM: { Bytebuffer* datum; Datalist* ecdl; stat = nc_def_enum(tsym->container->ncid, tsym->typ.basetype->typ.typecode, tsym->name, &tsym->ncid); check_err(stat,__LINE__,__FILE__); datum = bbNew(); ecdl = builddatalist(1); dlextend(ecdl); /* make room for one constant*/ ecdl->length = 1; for(i=0;i<listlength(tsym->subnodes);i++) { Symbol* econst = (Symbol*)listget(tsym->subnodes,i); ASSERT(econst->subclass == NC_ECONST); generator_reset(bin_generator,NULL); bbClear(datum); generate_basetype(econst->typ.basetype,&econst->typ.econst,datum,NULL,bin_generator); stat = nc_insert_enum(tsym->container->ncid, tsym->ncid, econst->name, bbContents(datum)); check_err(stat,__LINE__,__FILE__); } bbFree(datum); dlfree(&ecdl); } break; case NC_VLEN: stat = nc_def_vlen(tsym->container->ncid, tsym->name, tsym->typ.basetype->ncid, &tsym->ncid); check_err(stat,__LINE__,__FILE__); break; case NC_COMPOUND: stat = nc_def_compound(tsym->container->ncid, tsym->typ.size, tsym->name, &tsym->ncid); check_err(stat,__LINE__,__FILE__); for(i=0;i<listlength(tsym->subnodes);i++) { Symbol* efield = (Symbol*)listget(tsym->subnodes,i); ASSERT(efield->subclass == NC_FIELD); if(efield->typ.dimset.ndims == 0){ stat = nc_insert_compound( tsym->container->ncid, tsym->ncid, efield->name, efield->typ.offset, efield->typ.basetype->ncid); } else { int j; int dimsizes[NC_MAX_VAR_DIMS]; /* Generate the field dimension constants*/ for(j=0;j<efield->typ.dimset.ndims;j++) { unsigned int size = efield->typ.dimset.dimsyms[j]->dim.declsize; dimsizes[j] = size; } stat = nc_insert_array_compound( tsym->container->ncid, tsym->ncid, efield->name, efield->typ.offset, efield->typ.basetype->ncid, efield->typ.dimset.ndims, dimsizes); } check_err(stat,__LINE__,__FILE__); } break; default: panic("definectype: unexpected type subclass"); } }
void dlappend(Datalist* dl, Constant* constant) { if(dl->length >= dl->alloc) dlextend(dl); dl->data[dl->length++] = *constant; }