const char *type_pp_minify(type_t t, minify_fn_t fn) { assert(t != NULL); switch (type_kind(t)) { case T_FUNC: case T_PROC: { char *buf = get_fmt_buf(256); static_printf_begin(buf, 256); const char *fname = (*fn)(istr(type_ident(t))); static_printf(buf, "%s(", fname); const int nparams = type_params(t); for (int i = 0; i < nparams; i++) static_printf(buf, "%s%s", (i == 0 ? "" : ", "), (*fn)(istr(type_ident(type_param(t, i))))); static_printf(buf, ")"); if (type_kind(t) == T_FUNC) static_printf(buf, " return %s", (*fn)(istr(type_ident(type_result(t))))); return buf; } default: return (*fn)(istr(type_ident(t))); } }
/******************************************************************************* Returns true if the ItemType of the given sequence type is a generalized atomic type. ********************************************************************************/ bool XQType::isGenAtomicAny() const { if (type_kind() == XQType::ATOMIC_TYPE_KIND) { return true; } else if (type_kind() == XQType::USER_DEFINED_KIND) { const UserDefinedXQType* udt = static_cast<const UserDefinedXQType*>(this); if (udt->isAtomicAny()) return true; if (udt->isUnion()) { std::vector<xqtref_t>::const_iterator ite = udt->m_unionItemTypes.begin(); std::vector<xqtref_t>::const_iterator end = udt->m_unionItemTypes.end(); for (; ite != end; ++ite) { if ((*ite)->get_quantifier() != SequenceType::QUANT_ONE && (*ite)->get_quantifier() != SequenceType::QUANT_QUESTION) return false; } return true; } } return false; }
/******************************************************************************* Returns true if the ItemType of the given sequence type is an atomic type. ********************************************************************************/ bool XQType::isAtomicAny() const { if (type_kind() == XQType::ATOMIC_TYPE_KIND) { return true; } else if (type_kind() == XQType::USER_DEFINED_KIND) { return static_cast<const UserDefinedXQType*>(this)->theUDTKind == ATOMIC_UDT; } return false; }
/******************************************************************************* Returns true if the quantifier of the given sequence type is QUANT_ONE and its ItemType is an atomic type. ********************************************************************************/ bool XQType::isAtomicOne() const { if (get_quantifier() == SequenceType::QUANT_ONE) { if (type_kind() == XQType::ATOMIC_TYPE_KIND) { return true; } else if (type_kind() == XQType::USER_DEFINED_KIND) { return static_cast<const UserDefinedXQType*>(this)->theUDTKind == ATOMIC_UDT; } } return false; }
store::Item_t XQType::getQName() const { switch (type_kind()) { case ATOMIC_TYPE_KIND: { store::SchemaTypeCode type = static_cast<const AtomicXQType*>(this)->theAtomicCode; return GENV_TYPESYSTEM.m_atomic_typecode_qname_map[type]; } case USER_DEFINED_KIND: { return static_cast<const UserDefinedXQType*>(this)->theQName; } case ANY_TYPE_KIND: { return GENV_TYPESYSTEM.XS_ANY_TYPE_QNAME; } case UNTYPED_KIND: { return GENV_TYPESYSTEM.XS_UNTYPED_QNAME; } case ANY_SIMPLE_TYPE_KIND: { return GENV_TYPESYSTEM.XS_ANY_SIMPLE_TYPE_QNAME; } default: ZORBA_ASSERT(false); } }
bool XQType::isUnion() const { if (type_kind() == XQType::USER_DEFINED_KIND) { return static_cast<const UserDefinedXQType*>(this)->theUDTKind == UNION_UDT; } return false; }
/* returns TRUE if "t", an alias type, `defines a new type' by explicitly specifying a type UID */ static boolean redef_needed (Type t) { if (type_kind(t) != alias_Type) return FALSE; if (type_uid(t) == NIL) return FALSE; else if (type_uid(ur_type(t)) == NIL) return TRUE; else return (strcmp(type_uid(t), type_uid(ur_type(t))) != 0); }
type_t index_type_of(type_t type, int dim) { if (type_is_unconstrained(type)) return type_index_constr(type_base_recur(type), dim); else if (type_kind(type) == T_ENUM) return type; else { tree_t left = type_dim(type, dim).left; // If the left bound has not been assigned a type then there is some // error with it so just return a dummy type here return tree_has_type(left) ? tree_type(left) : type; } }
bool XQType::isAnonymous() const { switch (type_kind()) { case XQType::USER_DEFINED_KIND: { return static_cast<const UserDefinedXQType*>(this)->theIsAnonymous; } default: { return false; } } }
bool XQType::isComplex() const { switch (type_kind()) { case XQType::USER_DEFINED_KIND: { return static_cast<const UserDefinedXQType*>(this)->theUDTKind == COMPLEX_UDT; } case XQType::ANY_TYPE_KIND: case XQType::UNTYPED_KIND: { return true; } default: { return false; } } }
/* * Create a fresh value of type tau: * - return null_value if that fails (i.e., tau is finite and all values * or type tau are already present) */ value_t make_fresh_value(fresh_val_maker_t *maker, type_t tau) { type_table_t *types; value_t v; types = maker->types; switch (type_kind(types, tau)) { case BOOL_TYPE: v = null_value; break; case INT_TYPE: case REAL_TYPE: v = make_fresh_integer(maker); assert(v != null_value); break; case BITVECTOR_TYPE: v = make_fresh_bv(maker, bv_type_size(types, tau)); break; case SCALAR_TYPE: case UNINTERPRETED_TYPE: v = make_fresh_const(maker, tau); break; case TUPLE_TYPE: v = make_fresh_tuple(maker, tau); break; case FUNCTION_TYPE: v = make_fresh_function(maker, tau); break; default: assert(false); v = null_value; break; } return v; }
XQType::content_kind_t XQType::contentKind() const { switch (type_kind()) { case XQType::USER_DEFINED_KIND: { return static_cast<const UserDefinedXQType*>(this)->theContentKind; } case XQType::NONE_KIND: case XQType::EMPTY_KIND: { return EMPTY_CONTENT_KIND; } case XQType::ATOMIC_TYPE_KIND: case XQType::ANY_SIMPLE_TYPE_KIND: { return SIMPLE_CONTENT_KIND; } default: { return MIXED_CONTENT_KIND; } } }
void lxt_restart(void) { if (trace == NULL) return; lt_set_timescale(trace, -15); lt_symbol_bracket_stripping(trace, 0); lt_set_clock_compress(trace); const int ndecls = tree_decls(lxt_top); for (int i = 0; i < ndecls; i++) { tree_t d = tree_decl(lxt_top, i); if (tree_kind(d) != T_SIGNAL_DECL) continue; else if (!wave_should_dump(d)) continue; type_t type = tree_type(d); int rows, msb, lsb; if (type_is_array(type)) { rows = type_dims(type) - 1; if ((rows > 0) || type_is_array(type_elem(type))) { warn_at(tree_loc(d), "cannot emit arrays of greater than one " "dimension or arrays of arrays in LXT yet"); continue; } range_t r = type_dim(type, 0); msb = assume_int(r.left); lsb = assume_int(r.right); } else { rows = 0; msb = lsb = -1; } lxt_data_t *data = xmalloc(sizeof(lxt_data_t)); memset(data, '\0', sizeof(lxt_data_t)); int flags = 0; if (type_is_array(type)) { // Only arrays of CHARACTER, BIT, STD_ULOGIC are supported type_t elem = type_base_recur(type_elem(type)); if ((type_kind(elem) != T_ENUM) || !lxt_can_fmt_enum_chars(elem, data, &flags)) { warn_at(tree_loc(d), "cannot represent arrays of type %s " "in LXT format", type_pp(elem)); free(data); continue; } data->dir = type_dim(type, 0).kind; } else { type_t base = type_base_recur(type); switch (type_kind(base)) { case T_INTEGER: data->fmt = lxt_fmt_int; flags = LT_SYM_F_INTEGER; break; case T_ENUM: if (!lxt_can_fmt_enum_chars(base, data, &flags)) { data->fmt = lxt_fmt_enum; flags = LT_SYM_F_STRING; } break; default: warn_at(tree_loc(d), "cannot represent type %s in LXT format", type_pp(type)); free(data); continue; } } char *name = lxt_fmt_name(d); data->sym = lt_symbol_add(trace, name, rows, msb, lsb, flags); free(name); tree_add_attr_ptr(d, lxt_data_i, data); watch_t *w = rt_set_event_cb(d, lxt_event_cb, data, true); (*data->fmt)(d, w, data); } last_time = (lxttime_t)-1; }
static void vcd_process_signal(tree_t d, int *next_key) { type_t type = tree_type(d); type_t base = type_base_recur(type); vcd_data_t *data = xmalloc(sizeof(vcd_data_t)); memset(data, '\0', sizeof(vcd_data_t)); int msb = 0, lsb = 0; if (type_is_array(type)) { if (type_dims(type) > 1) { warn_at(tree_loc(d), "cannot represent multidimensional arrays " "in VCD format"); free(data); return; } range_t r = type_dim(type, 0); int64_t low, high; range_bounds(r, &low, &high); data->dir = r.kind; data->size = high - low + 1; msb = assume_int(r.left); lsb = assume_int(r.right); type_t elem = type_elem(type); if (!vcd_can_fmt_chars(elem, data)) { warn_at(tree_loc(d), "cannot represent arrays of type %s " "in VCD format", type_pp(elem)); free(data); return; } } else { switch (type_kind(base)) { case T_INTEGER: { int64_t low, high; range_bounds(type_dim(type, 0), &low, &high); data->size = ilog2(high - low + 1); data->fmt = vcd_fmt_int; } break; case T_ENUM: if (vcd_can_fmt_chars(type, data)) { data->size = 1; break; } // Fall-through default: warn_at(tree_loc(d), "cannot represent type %s in VCD format", type_pp(type)); free(data); return; } } const char *name_base = strrchr(istr(tree_ident(d)), ':') + 1; const size_t base_len = strlen(name_base); char name[base_len + 64]; strncpy(name, name_base, base_len + 64); if (type_is_array(type)) snprintf(name + base_len, 64, "[%d:%d]\n", msb, lsb); tree_add_attr_ptr(d, vcd_data_i, data); data->watch = rt_set_event_cb(d, vcd_event_cb, data, true); vcd_key_fmt(*next_key, data->key); fprintf(vcd_file, "$var reg %d %s %s $end\n", (int)data->size, data->key, name); ++(*next_key); }
PUBLIC boolean enm_is_a(Type t) { t = myUrType(t); return (type_kind(t) == enumeration_Type); }
static void fst_process_signal(tree_t d) { type_t type = tree_type(d); type_t base = type_base_recur(type); fst_data_t *data = xmalloc(sizeof(fst_data_t)); memset(data, '\0', sizeof(fst_data_t)); int msb = 0, lsb = 0; enum fstVarType vt; enum fstSupplementalDataType sdt; if (type_is_array(type)) { if (type_dims(type) > 1) { warn_at(tree_loc(d), "cannot represent multidimensional arrays " "in FST format"); free(data); return; } range_t r = type_dim(type, 0); int64_t low, high; range_bounds(r, &low, &high); data->dir = r.kind; data->size = high - low + 1; msb = assume_int(r.left); lsb = assume_int(r.right); type_t elem = type_elem(type); if (!fst_can_fmt_chars(elem, data, &vt, &sdt)) { warn_at(tree_loc(d), "cannot represent arrays of type %s " "in FST format", type_pp(elem)); free(data); return; } else { ident_t ident = type_ident(base); if (ident == unsigned_i) sdt = FST_SDT_VHDL_UNSIGNED; else if (ident == signed_i) sdt = FST_SDT_VHDL_SIGNED; } } else { switch (type_kind(base)) { case T_INTEGER: { ident_t ident = type_ident(type); if (ident == natural_i) sdt = FST_SDT_VHDL_NATURAL; else if (ident == positive_i) sdt = FST_SDT_VHDL_POSITIVE; else sdt = FST_SDT_VHDL_INTEGER; int64_t low, high; range_bounds(type_dim(type, 0), &low, &high); vt = FST_VT_VCD_INTEGER; data->size = ilog2(high - low + 1); data->fmt = fst_fmt_int; } break; case T_ENUM: if (!fst_can_fmt_chars(type, data, &vt, &sdt)) { ident_t ident = type_ident(base); if (ident == std_bool_i) sdt = FST_SDT_VHDL_BOOLEAN; else if (ident == std_char_i) sdt = FST_SDT_VHDL_CHARACTER; else sdt = FST_SDT_NONE; vt = FST_VT_GEN_STRING; data->size = 0; data->fmt = fst_fmt_enum; } else data->size = 1; break; case T_PHYSICAL: { sdt = FST_SDT_NONE; vt = FST_VT_GEN_STRING; data->size = 0; data->type.units = fst_make_unit_map(type); data->fmt = fst_fmt_physical; } break; default: warn_at(tree_loc(d), "cannot represent type %s in FST format", type_pp(type)); free(data); return; } } enum fstVarDir dir = FST_VD_IMPLICIT; switch (tree_attr_int(d, fst_dir_i, -1)) { case PORT_IN: dir = FST_VD_INPUT; break; case PORT_OUT: dir = FST_VD_OUTPUT; break; case PORT_INOUT: dir = FST_VD_INOUT; break; case PORT_BUFFER: dir = FST_VD_BUFFER; break; } const char *name_base = strrchr(istr(tree_ident(d)), ':') + 1; const size_t base_len = strlen(name_base); char name[base_len + 64]; strncpy(name, name_base, base_len + 64); if (type_is_array(type)) snprintf(name + base_len, 64, "[%d:%d]\n", msb, lsb); data->handle = fstWriterCreateVar2( fst_ctx, vt, dir, data->size, name, 0, type_pp(type), FST_SVT_VHDL_SIGNAL, sdt); tree_add_attr_ptr(d, fst_data_i, data); data->watch = rt_set_event_cb(d, fst_event_cb, data, true); }
PUBLIC type tc_expr(tree t, env e) #endif { switch (t->x_kind) { case REF: return ref_type((sym) t->x_tag, t->x_params, e, t); case INGEN: return ref_type((sym) t->x_tag, list2(t->x_param1, t->x_param2), e, t); case PREGEN: return ref_type((sym) t->x_tag, list1(t->x_param), e, t); case NUMBER: return nat_type; case SEXPR: { def d; frame params; if (! open_sref(t->x_ref, e, &d, ¶ms)) return err_type; if ((tok) t->x_ref->x_sref_decor != empty) { tc_error(t->x_loc, "Decoration ignored in schema reference"); tc_e_etc("Expression: %z", t); tc_e_end(); } if (t->x_ref->x_sref_renames != nil) { tc_error(t->x_loc, "Renaming ignored in schema reference"); tc_e_etc("Expression: %z", t); tc_e_end(); } if (! aflag && d->d_abbrev) return mk_power(mk_abbrev(d, params)); else return mk_power(seal(mk_sproduct(d->d_schema), params)); } case POWER: { type tt1, tt2; if (! anal_power(tt1 = tc_expr(t->x_arg, e), &tt2, t->x_arg)) { tc_error(t->x_loc, "Argument of \\power must be a set"); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", tt1); tc_e_end(); } return mk_power(mk_power(tt2)); } case TUPLE : { type a[MAX_ARGS]; int n = 0; tree u; for (u = t->x_elements; u != nil; u = cdr(u)) { if (n >= MAX_ARGS) panic("tc_expr - tuple too big"); a[n++] = tc_expr(car(u), e); } return mk_cproduct(n, a); } case CROSS: { type a[MAX_ARGS]; type tt1, tt2; int n = 0; tree u; for (u = t->x_factors; u != nil; u = cdr(u)) { if (n >= MAX_ARGS) panic("tc_expr - product too big"); tt1 = tc_expr(car(u), e); if (! anal_power(tt1, &tt2, car(u))) { tc_error(t->x_loc, "Argument %d of \\cross must be a set", n+1); tc_e_etc("Expression: %z", t); tc_e_etc("Arg %d type: %t", n+1, tt1); tc_e_end(); } a[n++] = tt2; } return mk_power(mk_cproduct(n, a)); } case EXT: case SEQ: case BAG: { type elem_type; type tt; tree u; if (t->x_elements == nil) elem_type = new_typevar(t); else { elem_type = tc_expr(car(t->x_elements), e); for (u = cdr(t->x_elements); u != nil; u = cdr(u)) { if (unify(elem_type, tt = tc_expr(car(u), e))) elem_type = type_union(elem_type, arid, tt, arid); else { tc_error(t->x_loc, "Type mismatch in %s display", (t->x_kind == EXT ? "set" : t->x_kind == SEQ ? "sequence" : "bag")); tc_e_etc("Expression: %z", car(u)); tc_e_etc("Has type: %t", tt); tc_e_etc("Expected: %t", elem_type); tc_e_end(); } } } switch (t->x_kind) { case EXT: return mk_power(elem_type); case SEQ: return (aflag ? rel_type(num_type, elem_type) : mk_seq(elem_type)); case BAG: return (aflag ? rel_type(elem_type, num_type) : mk_bag(elem_type)); } } case THETA: return theta_type(t, e, (type) NULL, t); case BINDING: { tree u; env e1 = new_env(e); for (u = t->x_elements; u != nil; u = cdr(u)) add_def(VAR, (sym) car(u)->x_lhs, tc_expr(car(u)->x_rhs, e), e1); return mk_sproduct(mk_schema(e1)); } case SELECT: { type a = tc_expr(t->x_arg, e); if (type_kind(a) != SPRODUCT) { tc_error(t->x_loc, "Argument of selection must have schema type"); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", a); tc_e_end(); mark_error(); return err_type; } switch (t->x_field->x_kind) { case IDENT: return (comp_type(a, (sym) t->x_field, t, t->x_loc)); case THETA: return (theta_type(t->x_field, e, a, t)); default: bad_tag("tc_expr.SELECT", t->x_field->x_kind); return (type) NULL; } } case APPLY: return tc_apply(APPLY, t, t->x_arg1, t->x_arg2, e); case INOP: return tc_apply(INOP, t, simply(t->x_op, t->x_loc), pair(t->x_rand1, t->x_rand2), e); case POSTOP: return tc_apply(POSTOP, t, simply(t->x_op, t->x_loc), t->x_rand, e); case LAMBDA: { env e1 = tc_schema(t->x_bvar, e); type dom = tc_expr(char_tuple(t->x_bvar), e1); type ran = tc_expr(t->x_body, e1); return (aflag ? rel_type(dom, ran) : mk_pfun(dom, ran)); } case COMP: case MU: { env e1 = tc_schema(t->x_bvar, e); type a = tc_expr(exists(t->x_body) ? the(t->x_body) : char_tuple(t->x_bvar), e1); return (t->x_kind == COMP ? mk_power(a) : a); } case LETEXPR: return tc_expr(t->x_body, tc_letdefs(t->x_defs, e)); case IF: { type a, b; tc_pred(t->x_if, e); a = tc_expr(t->x_then, e); b = tc_expr(t->x_else, e); if (unify(a, b)) return type_union(a, arid, b, arid); else { tc_error(t->x_loc, "Type mismatch in conditional expression"); tc_e_etc("Expression: %z", t); tc_e_etc("Then type: %t", a); tc_e_etc("Else type: %t", b); tc_e_end(); return err_type; } } default: bad_tag("tc_expr", t->x_kind); /* dummy */ return (type) NULL; } }
PUBLIC boolean ar_is_a(Type t) { TypeKind kind; t = myUrType(t); kind = type_kind(t); return (kind==array_Type); }
tree_t make_default_value(type_t type, const loc_t *loc) { type_t base = type_base_recur(type); switch (type_kind(base)) { case T_UARRAY: assert(type_kind(type) == T_SUBTYPE); // Fall-through case T_CARRAY: { tree_t def = NULL; const int ndims = type_dims(type); for (int i = ndims - 1; i >= 0; i--) { tree_t val = (def ? def : make_default_value(type_elem(base), loc)); def = tree_new(T_AGGREGATE); tree_set_type(def, array_aggregate_type(type, i)); tree_t a = tree_new(T_ASSOC); tree_set_subkind(a, A_OTHERS); tree_set_value(a, val); tree_add_assoc(def, a); } tree_set_type(def, type); tree_set_loc(def, loc); return def; } case T_INTEGER: case T_PHYSICAL: case T_REAL: return type_dim(type, 0).left; case T_ENUM: { int64_t val = 0; const bool folded = folded_int(type_dim(type, 0).left, &val); if (folded) return make_ref(type_enum_literal(base, (unsigned) val)); else return type_dim(type, 0).left; } case T_RECORD: { tree_t def = tree_new(T_AGGREGATE); tree_set_loc(def, loc); const int nfields = type_fields(base); for (int i = 0; i < nfields; i++) { tree_t field = type_field(base, i); tree_t a = tree_new(T_ASSOC); tree_set_subkind(a, A_POS); tree_set_value(a, make_default_value(tree_type(field), tree_loc(field))); tree_add_assoc(def, a); } tree_set_type(def, type); return def; } case T_ACCESS: { tree_t null = tree_new(T_LITERAL); tree_set_loc(null, loc); tree_set_subkind(null, L_NULL); tree_set_type(null, type); return null; } case T_UNRESOLVED: return NULL; default: fatal_trace("cannot handle type %s in %s", type_kind_str(type_kind(base)), __func__); } }
static void add_typeref (Type t, struct buffer_s *data, list referenced) { if ((t->uid != NIL) && t->explicit_uid) { } else if (type_kind(t) == alias_Type) { add_typeref (t->supertype, data, referenced); } else { switch (type_kind(t)) { case byte_Type: print0ToBuffer (data, "byte"); break; case shortcardinal_Type: print0ToBuffer (data, "shortcardinal"); break; case cardinal_Type: print0ToBuffer (data, "cardinal"); break; case longcardinal_Type: print0ToBuffer (data, "longcardinal"); break; case shortinteger_Type: print0ToBuffer (data, "shortinteger"); break; case integer_Type: print0ToBuffer (data, "integer"); break; case longinteger_Type: print0ToBuffer (data, "longinteger"); break; case shortreal_Type: print0ToBuffer (data, "shortreal"); break; case real_Type: print0ToBuffer (data, "real"); break; case longreal_Type: print0ToBuffer (data, "longreal"); break; case shortcharacter_Type: print0ToBuffer (data, "shortcharacter"); break; case character_Type: print0ToBuffer (data, "character"); break; #if 0 case longcharacter_Type: #endif case boolean_Type: print0ToBuffer (data, "boolean"); break; case pickle_Type: print0ToBuffer (data, "pickle"); break; case void_Type: print0ToBuffer (data, "void"); break; case object_Type: case fixedpoint_Type: case string_Type: case union_Type: case sequence_Type: case record_Type: case array_Type: case enumeration_Type: case optional_Type: case reference_Type: printmToBuffer (data, "(ref %s %s)", interface_name(type_interface(t)), type_name(t)); add_entity (InterfaceE, type_interface(t), referenced); add_entity (TypeE, t, referenced); break; default: fprintf (stderr, "Invalid type kind %d for built-in type %s\n", type_basic_type(t), full_type_name(t)); exit(1); } } }
/******************************************************************************* Attempt to output the type as a string closer to the xs: representation ********************************************************************************/ std::string XQType::toSchemaString() const { std::string result; switch (type_kind()) { case NONE_KIND: { result = "none"; break; } case EMPTY_KIND: { result = "empty-sequence()"; break; } case ATOMIC_TYPE_KIND: { result = toString(); break; } case ITEM_KIND: { result = "item()"; result += TypeOps::decode_quantifier(get_quantifier()); break; } case STRUCTURED_ITEM_KIND: { result = "structured-item()"; result += TypeOps::decode_quantifier(get_quantifier()); break; } case JSON_TYPE_KIND: { const JSONXQType* type = static_cast<const JSONXQType*>(this); store::StoreConsts::JSONItemKind kind = type->get_json_kind(); if (kind == store::StoreConsts::jsonItem) { result = "json-item()"; } else if (kind == store::StoreConsts::jsonObject) { result = "object()"; } else if (kind == store::StoreConsts::jsonArray) { result = "array()"; } result += TypeOps::decode_quantifier(get_quantifier()); break; } case NODE_TYPE_KIND: { result = static_cast<const NodeXQType*>(this)->toSchemaStringInternal(); result += TypeOps::decode_quantifier(get_quantifier()); break; } case FUNCTION_TYPE_KIND: { result = toString(); result += TypeOps::decode_quantifier(get_quantifier()); break; } case ANY_FUNCTION_TYPE_KIND: { result = "function(*)"; result += TypeOps::decode_quantifier(get_quantifier()); break; } case ANY_TYPE_KIND: { result = "xs:anyType"; break; } case ANY_SIMPLE_TYPE_KIND: { result = "xs:anySimpleType"; break; } case UNTYPED_KIND: { result = "xs:untyped"; break; } default: { result = toString(); result += TypeOps::decode_quantifier(get_quantifier()); break; } } return result; }
bool parse_value(type_t type, const char *str, int64_t *value) { while (isspace((int)*str)) ++str; switch (type_kind(type_base_recur(type))) { case T_INTEGER: { int64_t sum = 0; while (isdigit((int)*str) || (*str == '_')) { if (*str != '_') { sum *= 10; sum += (*str - '0'); } ++str; } *value = sum; } break; case T_ENUM: { bool upcase = true; char *copy = strdup(str), *p; for (p = copy; (*p != '\0') && !isspace((int)*p); p++, str++) { if (*p == '\'') upcase = false; if (upcase) *p = toupper((int)*p); } *p = '\0'; ident_t id = ident_new(copy); free(copy); *value = -1; const int nlits = type_enum_literals(type); for (int i = 0; (*value == -1) && (i < nlits); i++) { if (tree_ident(type_enum_literal(type, i)) == id) *value = i; } if (*value == -1) return false; } break; default: break; } while (*str != '\0') { if (!isspace((int)*str)) { str++; return false; } else { str++; } } return true; }
std::ostream& XQType::serialize_ostream(std::ostream& os) const { return os << "[XQType " << KIND_STRINGS[type_kind()] << TypeOps::decode_quantifier(get_quantifier()) << "]"; }
char *FigureTypeUID (Type t) { struct buffer_s buffer; unsigned char hash[20]; SHS_CTX ctx; static boolean initialized = FALSE; Type t2; if (! initialized) { verbose = (getenv ("ILU_TYPE_UID_VERBOSE") != NULL); initialized = TRUE; } if (type_uid(t) != NULL) return (type_uid(t)); assert((t->importInterfaceName == NULL) || (type_kind(t) == alias_Type)); if (type_kind(t) == alias_Type || t->importInterfaceName != NULL) return (type_uid(t) = ilu_strdup(FigureTypeUID(under_type(t)))); if (type_kind(t) == object_Type && class_object(t) != NULL && class_object(t)->corba_rep_id != NULL) return (type_uid(t) = class_object(t)->corba_rep_id); if (verbose && !t->builtIn) fprintf(stderr, "figuring 'ilut:' uid for <%s> (addr %p, ifc addr %p) from %s\n", full_type_name(t), t, t->interface, ((t->importInterfaceName != NULL) ? t->importInterfaceName : "(current ifc)")); buffer.data = (unsigned char *) iluparser_Malloc(buffer.size = 1024); buffer.used = 0; form_typedesc (t, &buffer); buffer.data[buffer.used] = '\0'; if (verbose && ! t->builtIn) fprintf (stderr, " buffer is <%*.*s>\n", buffer.used, buffer.used, buffer.data); SHSInit(&ctx); SHSUpdate (&ctx, buffer.data, buffer.used); SHSFinal (hash, &ctx); /* { int i; fprintf (stderr, " hash is "); for (i = 0; i < 20; i += 1) fprintf (stderr, "%u ", hash[i]); fprintf (stderr, "\n"); } */ type_uid(t) = (char *) iluparser_Malloc(40); strcpy (type_uid(t), "ilut:"); /* convert to base 64 */ convbase(hash,20,type_uid(t) + strlen(type_uid(t))); iluparser_Free(buffer.data); if (verbose && !t->builtIn) fprintf (stderr, " uid for %s is %s\n", type_name(t), type_uid(t)); if (iluparser_CString_Type == NULL && t->importInterfaceName == NULL && type_interface(t) != NULL && strcmp(interface_name(type_interface(t)), "ilu") == 0 && strcmp(type_name(t), "CString") == 0) iluparser_CString_Type = t; return (type_uid(t)); }
bool type_eq(type_t a, type_t b) { assert(a != NULL); assert(b != NULL); type_kind_t kind_a = type_kind(a); type_kind_t kind_b = type_kind(b); if ((kind_a == T_UNRESOLVED) || (kind_b == T_UNRESOLVED)) return false; if (a == b) return true; // Subtypes are convertible to the base type while ((kind_a = type_kind(a)) == T_SUBTYPE) a = type_base(a); while ((kind_b = type_kind(b)) == T_SUBTYPE) b = type_base(b); const bool compare_c_u_arrays = (kind_a == T_CARRAY && kind_b == T_UARRAY) || (kind_a == T_UARRAY && kind_b == T_CARRAY); if ((kind_a != kind_b) && !compare_c_u_arrays) return false; // Universal integer type is equal to any other integer type type_t universal_int = type_universal_int(); ident_t uint_i = type_ident(universal_int); if (kind_a == T_INTEGER && (type_ident(a) == uint_i || type_ident(b) == uint_i)) return true; // Universal real type is equal to any other real type type_t universal_real = type_universal_real(); ident_t ureal_i = type_ident(universal_real); if (kind_a == T_REAL && (type_ident(a) == ureal_i || type_ident(b) == ureal_i)) return true; // XXX: this is not quite right as structurally equivalent types // may be declared in different scopes with the same name but // shouldn't compare equal if (type_ident(a) != type_ident(b)) return false; // Access types are equal if the pointed to type is the same if (kind_a == T_ACCESS) return type_eq(type_access(a), type_access(b)); if (compare_c_u_arrays) return type_eq(type_elem(a), type_elem(b)); const imask_t has = has_map[a->kind]; if ((has & I_DIMS) && (type_dims(a) != type_dims(b))) return false; if (type_kind(a) == T_FUNC) { if (!type_eq(type_result(a), type_result(b))) return false; } if (has & I_PARAMS) { if (type_params(a) != type_params(b)) return false; const int nparams = type_params(a); for (int i = 0; i < nparams; i++) { if (!type_eq(type_param(a, i), type_param(b, i))) return false; } } return true; }
bool XQType::isBuiltinAtomicAny() const { return type_kind() == XQType::ATOMIC_TYPE_KIND; }
/******************************************************************************* Returns true if the quantifier of the given sequence type is QUANT_ONE and its ItemType is a builtin atomic type. ********************************************************************************/ bool XQType::isBuiltinAtomicOne() const { return get_quantifier() == SequenceType::QUANT_ONE && type_kind() == XQType::ATOMIC_TYPE_KIND; }
END_TEST START_TEST(test_lib_save) { { tree_t ent = tree_new(T_ENTITY); tree_set_ident(ent, ident_new("name")); tree_add_attr_str(ent, ident_new("attr"), ident_new("test string")); type_t e = type_new(T_ENUM); type_set_ident(e, ident_new("myenum")); tree_t a = tree_new(T_ENUM_LIT); tree_set_ident(a, ident_new("a")); tree_set_type(a, e); tree_set_pos(a, 55); type_enum_add_literal(e, a); tree_t b = tree_new(T_ENUM_LIT); tree_set_ident(b, ident_new("b")); tree_set_type(b, e); type_enum_add_literal(e, b); tree_t p1 = tree_new(T_PORT_DECL); tree_set_ident(p1, ident_new("foo")); tree_set_subkind(p1, PORT_OUT); tree_set_type(p1, type_universal_int()); tree_add_port(ent, p1); tree_t p2 = tree_new(T_PORT_DECL); tree_set_ident(p2, ident_new("bar")); tree_set_subkind(p2, PORT_IN); tree_set_type(p2, e); tree_add_port(ent, p2); tree_t ar = tree_new(T_ARCH); tree_set_ident(ar, ident_new("arch")); tree_set_ident2(ar, ident_new("foo")); tree_t pr = tree_new(T_PROCESS); tree_set_ident(pr, ident_new("proc")); tree_add_stmt(ar, pr); tree_t v1 = tree_new(T_VAR_DECL); tree_set_ident(v1, ident_new("v1")); tree_set_type(v1, e); tree_t r = tree_new(T_REF); tree_set_ident(r, ident_new("v1")); tree_set_ref(r, v1); tree_t s = tree_new(T_VAR_ASSIGN); tree_set_ident(s, ident_new("var_assign")); tree_set_target(s, r); tree_set_value(s, r); tree_add_stmt(pr, s); tree_t c = tree_new(T_LITERAL); tree_set_subkind(c, L_INT); tree_set_ival(c, 53); tree_t s2 = tree_new(T_VAR_ASSIGN); tree_set_ident(s2, ident_new("var_assign")); tree_set_target(s2, r); tree_set_value(s2, c); tree_add_stmt(pr, s2); tree_t s3 = tree_new(T_VAR_ASSIGN); tree_set_ident(s3, ident_new("var_assign")); tree_set_target(s3, r); tree_set_value(s3, str_to_agg("foobar", NULL)); tree_add_stmt(pr, s3); tree_t s4 = tree_new(T_ASSERT); tree_set_ident(s4, ident_new("assert")); tree_set_value(s4, c); tree_set_severity(s4, c); tree_set_message(s4, str_to_agg("message", NULL)); tree_add_stmt(pr, s4); lib_put(work, ar); lib_put(work, ent); } tree_gc(); lib_save(work); lib_free(work); lib_add_search_path("/tmp"); work = lib_find(ident_new("test_lib"), false); fail_if(work == NULL); { tree_t ent = lib_get(work, ident_new("name")); fail_if(ent == NULL); fail_unless(tree_kind(ent) == T_ENTITY); fail_unless(tree_ident(ent) == ident_new("name")); fail_unless(tree_ports(ent) == 2); ident_t attr = tree_attr_str(ent, ident_new("attr")); fail_if(attr == NULL); fail_unless(icmp(attr, "test string")); tree_t p1 = tree_port(ent, 0); fail_unless(tree_kind(p1) == T_PORT_DECL); fail_unless(tree_subkind(p1) == PORT_OUT); fail_unless(type_kind(tree_type(p1)) == T_INTEGER); tree_t p2 = tree_port(ent, 1); fail_unless(tree_kind(p2) == T_PORT_DECL); fail_unless(tree_subkind(p2) == PORT_IN); type_t e = tree_type(p2); fail_unless(type_kind(e) == T_ENUM); fail_unless(type_enum_literals(e) == 2); tree_t a = type_enum_literal(e, 0); fail_unless(tree_kind(a) == T_ENUM_LIT); fail_unless(tree_ident(a) == ident_new("a")); fail_unless(tree_type(a) == e); fail_unless(tree_pos(a) == 55); tree_t b = type_enum_literal(e, 1); fail_unless(tree_kind(b) == T_ENUM_LIT); fail_unless(tree_ident(b) == ident_new("b")); fail_unless(tree_type(b) == e); tree_t ar = lib_get(work, ident_new("arch")); fail_if(ar == NULL); fail_unless(tree_ident(ar) == ident_new("arch")); fail_unless(tree_ident2(ar) == ident_new("foo")); tree_t pr = tree_stmt(ar, 0); fail_unless(tree_kind(pr) == T_PROCESS); fail_unless(tree_ident(pr) == ident_new("proc")); tree_t s = tree_stmt(pr, 0); fail_unless(tree_kind(s) == T_VAR_ASSIGN); tree_t r = tree_target(s); fail_unless(tree_kind(r) == T_REF); fail_unless(tree_value(s) == r); tree_t s2 = tree_stmt(pr, 1); fail_unless(tree_kind(s2) == T_VAR_ASSIGN); fail_unless(tree_target(s2) == r); tree_t s3 = tree_stmt(pr, 2); fail_unless(tree_kind(s3) == T_VAR_ASSIGN); fail_unless(tree_target(s3) == r); fail_unless(tree_kind(tree_value(s3)) == T_AGGREGATE); tree_t s4 = tree_stmt(pr, 3); fail_unless(tree_kind(s4) == T_ASSERT); fail_unless(tree_ident(s4) == ident_new("assert")); tree_t c = tree_value(s2); fail_unless(tree_kind(c) == T_LITERAL); fail_unless(tree_subkind(c) == L_INT); fail_unless(tree_ival(c) == 53); // Type declaration and reference written to different units // so two copies of the type declaration will be read back // hence can't check for pointer equality here fail_unless(type_eq(tree_type(tree_ref(r)), e)); } }
tree_t make_default_value(type_t type, const loc_t *loc) { type_t base = type_base_recur(type); switch (type_kind(base)) { case T_UARRAY: assert(type_kind(type) == T_SUBTYPE); // Fall-through case T_CARRAY: { tree_t def = NULL; const int ndims = type_dims(type); for (int i = ndims - 1; i >= 0; i--) { tree_t val = (def ? def : make_default_value(type_elem(base), loc)); def = tree_new(T_AGGREGATE); tree_set_type(def, array_aggregate_type(type, i)); tree_t a = tree_new(T_ASSOC); tree_set_subkind(a, A_OTHERS); tree_set_value(a, val); tree_add_assoc(def, a); } tree_set_type(def, type); tree_set_loc(def, loc); return def; } case T_INTEGER: case T_PHYSICAL: case T_REAL: return type_dim(type, 0).left; case T_ENUM: return make_ref(type_enum_literal(base, 0)); case T_RECORD: { tree_t def = tree_new(T_AGGREGATE); tree_set_loc(def, loc); const int nfields = type_fields(base); for (int i = 0; i < nfields; i++) { tree_t field = type_field(base, i); tree_t a = tree_new(T_ASSOC); tree_set_subkind(a, A_POS); tree_set_value(a, make_default_value(tree_type(field), tree_loc(field))); tree_add_assoc(def, a); } tree_set_type(def, type); return def; } case T_ACCESS: { tree_t null = tree_new(T_LITERAL); tree_set_loc(null, loc); tree_set_subkind(null, L_NULL); tree_set_type(null, type); return null; } default: assert(false); } }