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); }
static void inferattributetype(Symbol* asym) { Datalist* datalist; 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; } nctype = inferattributetype1(datalist); if(nctype == NC_NAT) { /* Illegal attribute value list */ semerror(asym->lineno,"Non-simple list of values for untyped attribute: %s",fullname(asym)); return; } /* 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 or cdf5 atypes */ switch (nctype) { 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); }
Symbol* locate(Symbol* refsym) { Symbol* sym = NULL; switch (refsym->objectclass) { case NC_DIM: if(refsym->is_prefixed) { /* locate exact dimension specified*/ sym = lookup(NC_DIM,refsym); } else { /* Search for matching dimension in all parent groups*/ Symbol* parent = lookupgroup(refsym->prefix);/*get group for refsym*/ while(parent != NULL) { /* search this parent for matching name and type*/ sym = lookupingroup(NC_DIM,refsym->name,parent); if(sym != NULL) break; parent = parent->container; } } break; case NC_TYPE: if(refsym->is_prefixed) { /* locate exact type specified*/ sym = lookup(NC_TYPE,refsym); } else { Symbol* parent; int i; /* Search for matching type in all groups (except...)*/ /* Short circuit test for primitive types*/ for(i=NC_NAT;i<=NC_STRING;i++) { Symbol* prim = basetypefor(i); if(prim == NULL) continue; if(strcmp(refsym->name,prim->name)==0) { sym = prim; break; } } if(sym == NULL) { /* Added 5/26/09: look in parent hierarchy first */ parent = lookupgroup(refsym->prefix);/*get group for refsym*/ while(parent != NULL) { /* search this parent for matching name and type*/ sym = lookupingroup(NC_TYPE,refsym->name,parent); if(sym != NULL) break; parent = parent->container; } } if(sym == NULL) { sym = uniquetreelocate(refsym,rootgroup); /* want unique */ } } break; case NC_VAR: if(refsym->is_prefixed) { /* locate exact variable specified*/ sym = lookup(NC_VAR,refsym); } else { Symbol* parent = lookupgroup(refsym->prefix);/*get group for refsym*/ /* search this parent for matching name and type*/ sym = lookupingroup(NC_VAR,refsym->name,parent); } break; case NC_GRP: if(refsym->is_prefixed) { /* locate exact group specified*/ sym = lookup(NC_GRP,refsym); } else { Symbol* parent = lookupgroup(refsym->prefix);/*get group for refsym*/ /* search this parent for matching name and type*/ sym = lookupingroup(NC_GRP,refsym->name,parent); } break; default: PANIC1("locate: bad refsym type: %d",refsym->objectclass); } if(debug > 1) { char* ncname; if(refsym->objectclass == NC_TYPE) ncname = ncclassname(refsym->subclass); else ncname = ncclassname(refsym->objectclass); fdebug("locate: %s: %s -> %s\n", ncname,fullname(refsym),(sym?fullname(sym):"NULL")); } return sym; }