static nc_type inferattributetype1(Datasrc* src) { nc_type result = NC_NAT; /* Recurse down any enclosing compound markers to find first non-fill "primitive"*/ while(result == NC_NAT && srcmore(src)) { if(issublist(src)) { srcpush(src); result = inferattributetype1(src); srcpop(src); } else { Constant* con = srcnext(src); if(isprimplus(con->nctype)) result = con->nctype; /* else keep looking*/ } } return result; }
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); }