void genbin_arraydata(Symbol* vsym, Bytebuffer* memory) { Datasrc* src; Datalist* list; int i; int chartype = (vsym->typ.basetype->typ.typecode == NC_CHAR); nciter_t iter; Iterodom iterodom; if(vsym->data == NULL) return; if(chartype) { gen_chararray(vsym,memory); return; } list = vsym->data; ASSERT(list->dimdata != NULL); src = datalist2src(list); /* Create an iterator to generate blocks of data */ nc_get_iter(vsym,databuffersize,&iter); nc_next_iter(&iter,iterodom.start,iterodom.count); iterodom.rank = vsym->typ.dimset.ndims; genbin_arraydatar(vsym,memory,src,iter,&iterodom,/*index=*/0) }
void gen_charattr(Symbol* asym, Bytebuffer* databuf) { Datasrc* src; Constant* con; if(asym->data == NULL) return; src = datalist2src(asym->data); while((con=srcnext(src))) { switch (con->nctype) { /* Following list should be consistent with isstringable */ case NC_CHAR: bbAppend(databuf,con->value.charv); break; case NC_BYTE: bbAppend(databuf,con->value.int8v); break; case NC_UBYTE: bbAppend(databuf,con->value.uint8v); break; case NC_STRING: bbCat(databuf,con->value.stringv.stringv); bbNull(databuf); break; case NC_FILL: bbAppend(databuf,NC_FILL_CHAR); break; default: semerror(srcline(src), "Encountered non-string constant in attribute: %s", asym->name); return; } } }
/* Specialty wrappers for genbin_data */ void genbin_attrdata(Symbol* asym, Bytebuffer* memory) { Datasrc* src; int chartype = (asym->typ.basetype->typ.typecode == NC_CHAR); if(asym->data == NULL) return; if(chartype) {gen_charattr(asym,memory); return;} src = datalist2src(asym->data); while(srcmore(src)) { genbin_data(asym->typ.basetype,src,NULL,memory); } } #if 0 /* Apparently not used */ void genbin_scalardata(Symbol* vsym, Bytebuffer* memory) { Datasrc* src; if(vsym->data == NULL) return; src = datalist2src(vsym->data); genbin_data(vsym->typ.basetype,src, vsym->var.special._Fillvalue,memory); if(srcmore(src)) { semerror(srcline(src),"Extra data at end of datalist"); } }
/* Specialty wrappers for genbin_data */ void genbin_attrdata(Symbol* asym, Bytebuffer* memory) { Datasrc* src; int chartype = (asym->typ.basetype->typ.typecode == NC_CHAR); if(asym->data == NULL) return; if(chartype) {gen_charattr(asym,memory); return;} src = datalist2src(asym->data); while(srcmore(src)) { genbin_data(asym->typ.basetype,src,NULL,memory); } }
int checkfillvalue(Symbol* tvsym, Datalist* filler) { Datasrc* src = datalist2src(filler); int result; ASSERT(tvsym->objectclass == NC_VAR || tvsym->objectclass == NC_TYPE); if(tvsym->objectclass == NC_VAR) { if(tvsym->typ.dimset.ndims > 0) { result = checkarray(tvsym->typ.basetype,&tvsym->typ.dimset,0,src,tvsym,TOPLEVEL); } else result = checkfill(tvsym->typ.basetype,src,tvsym); } else /* NC_TYPE*/ result = checkfill(tvsym,src,tvsym); freedatasrc(src); return result; }
/* Specialty wrappers for f77data_data */ void f77data_attrdata(Symbol* asym, Bytebuffer* databuf) { Datasrc* src; int typecode = asym->typ.basetype->typ.typecode; if(asym->data == NULL) return; if(typecode == NC_CHAR) { gen_charattr(asym,databuf); } else { src = datalist2src(asym->data); while(srcmore(src)) { bbAppend(databuf,' '); f77data_basetype(asym->typ.basetype,src,databuf,NULL); } } }
static void inferattributetype(Symbol* asym) { Datalist* datalist; Datasrc* src; nc_type nctype; ASSERT(asym->data != NULL); datalist = asym->data; if(datalist->length == 0) { /* Default for zero length attributes */ asym->typ.basetype = basetypefor(NC_CHAR); return; } src = datalist2src(datalist); nctype = inferattributetype1(src); freedatasrc(src); /* get the corresponding primitive type built-in symbol*/ /* special case for string*/ if(nctype == NC_STRING) asym->typ.basetype = basetypefor(NC_CHAR); else if(usingclassic) { /* If we are in classic mode, then restrict the inferred type to the classic types */ switch (nctype) { case NC_UBYTE: nctype = NC_SHORT; break; case NC_USHORT: case NC_UINT: case NC_INT64: case NC_UINT64: case NC_OPAQUE: case NC_ENUM: nctype = NC_INT; break; default: /* leave as is */ break; } asym->typ.basetype = basetypefor(nctype); } else asym->typ.basetype = basetypefor(nctype); }
/* This walk of the data lists collects vlen sublists and constructs separate C constants for each of them. The "id" of each list is then recorded in the containing datalist. */ void cdata_vlenconstants(List* vlenconstants, Bytebuffer* codebuf) { int i,nvlen; Datasrc* vlensrc; Bytebuffer* tmp = bbNew(); nvlen = listlength(vlenconstants); for(i=0;i<nvlen;i++) { Constant* cmpd = (Constant*)listget(vlenconstants,i); int chartype; Symbol* tsym = cmpd->value.compoundv->vlen.schema; ASSERT(tsym != NULL); chartype = (tsym->typ.basetype->typ.typecode == NC_CHAR); bbprintf0(tmp,"static const %s vlen_%u[] = ", ctypename(tsym->typ.basetype), cmpd->value.compoundv->vlen.uid); bbCatbuf(codebuf,tmp); vlensrc = datalist2src(cmpd->value.compoundv); bbAppend(codebuf,'{'); if(chartype) { /* Collect the char vlen in a separate buffer */ Bytebuffer* vlenbuf = bbNew(); gen_charvlen(vlensrc,vlenbuf); /* Add to the existing data buf as a single constant */ cquotestring(vlenbuf); bbCatbuf(codebuf,vlenbuf); bbFree(vlenbuf); } else { size_t count = 0; while(srcmore(vlensrc)) { if(count > 0) bbCat(codebuf,", "); cdata_basetype(tsym->typ.basetype,vlensrc,codebuf,NULL); count++; } ASSERT(count == cmpd->value.compoundv->vlen.count); } bbCat(codebuf,"} ;\n"); } bbFree(tmp); }
/* This walk of the data lists collects vlen sublists and constructs separate C constants for each of them. The "id" of each list is then recorded in the containing datalist. */ void genbin_vlenconstants(List* vlenconstants) { int i,nvlen; Datasrc* vlensrc; Bytebuffer* memory = bbNew(); /* Prepare a place to store vlen constants */ nvlen = listlength(vlenconstants); if(nvlen == 0) return; vlendata = (struct Vlendata*)emalloc(sizeof(struct Vlendata)*nvlen+1); memset((void*)vlendata,0,sizeof(struct Vlendata)*nvlen+1); for(i=0;i<nvlen;i++) { Constant* cmpd = (Constant*)listget(vlenconstants,i); int chartype; Symbol* tsym = cmpd->value.compoundv->vlen.schema; unsigned long uid = cmpd->value.compoundv->vlen.uid; unsigned long count; ASSERT(tsym != NULL); chartype = (tsym->typ.basetype->typ.typecode == NC_CHAR); vlensrc = datalist2src(cmpd->value.compoundv); bbClear(memory); count = 0; if(chartype) { /* Collect the char vlen in a separate buffer */ gen_charvlen(vlensrc,memory); count = bbLength(memory); } else { while(srcmore(vlensrc)) { genbin_data(tsym->typ.basetype,vlensrc,NULL,memory); count++; } ASSERT(count == cmpd->value.compoundv->vlen.count); } vlendata[uid].data = bbDup(memory); vlendata[uid].count = count; } bbFree(memory); }
void genbin_datalist(struct Symbol* sym, Datalist* list, Bytebuffer* memory) { Datasrc* src = datalist2src(list); genbin_data(sym,src,NULL,memory); }