i have pushed the patch on "mob" Coo: initial last member of union Please change my name of patch: U-YUAN\Administrator -> yuanbin
2010/6/11 grischka <gris...@gmx.de>: > Too all: > > Please push patches on our "mob" branch: > http://repo.or.cz/w/tinycc.git > > People who don't like/know git: at least base patches on latest > mob or master branch. > > Also please give a short description of what the patch really > does. Otherwise it will be too hard for us other people. > > Thanks, > > --- grischka > > yuanbin wrote: >> >> Coo - C, Object Oriented >> http://sourceforge.net/projects/coo/ >> >> ---------coo.h-------------- >> #ifndef __COO_H__ >> #define __COO_H__ >> >> typedef struct VTable /*root of virtual table class*/ >> { >> long offset; /*servers for FREE*/ >> } VTable; >> >> #define EXTENDS(s) \ >> union \ >> { \ >> s s; \ >> s; \ >> }; >> #define VT(v) const v* vt; >> #define EXTENDS2(s,v) \ >> union \ >> { \ >> VT(v) \ >> s s; \ >> s; \ >> }; >> #ifndef offsetof >> #define offsetof(s,m) ((long)&((s*)0)->m) >> #endif >> #define SUPER(s,m,p) ((s*)((char*)(p)-offsetof(s,m))) >> #define FREE(p,vt) free((char*)(p)-(vt)->offset) >> >> #endif >> >> ---------------------------------- >> initialization of the enum: >> enum { >> int i; >> float f; >> } t={1.5}; //t.f >> because of EXTENDS2 in coo.h, compiler needs >> to initialze last member of enum. >> >> --------------tccgen.c-------------- >> static void decl_initializer(CType *type, Section *sec, unsigned long c, >> int first, int size_only) >> { >> int index, array_length, n, no_oblock, nb, parlevel, i; >> int size1, align1, expr_type; >> Sym *s, *f; >> CType *t1; >> >> if (type->t & VT_ARRAY) { >> s = type->ref; >> n = s->c; >> array_length = 0; >> t1 = pointed_type(type); >> size1 = type_size(t1, &align1); >> >> no_oblock = 1; >> if ((first && tok != TOK_LSTR && tok != TOK_STR) || >> tok == '{') { >> skip('{'); >> no_oblock = 0; >> } >> >> /* only parse strings here if correct type (otherwise: handle >> them as ((w)char *) expressions */ >> if ((tok == TOK_LSTR && >> #ifdef TCC_TARGET_PE >> (t1->t & VT_BTYPE) == VT_SHORT && (t1->t & VT_UNSIGNED) >> #else >> (t1->t & VT_BTYPE) == VT_INT >> #endif >> ) || (tok == TOK_STR && (t1->t & VT_BTYPE) == VT_BYTE)) { >> while (tok == TOK_STR || tok == TOK_LSTR) { >> int cstr_len, ch; >> CString *cstr; >> >> cstr = tokc.cstr; >> /* compute maximum number of chars wanted */ >> if (tok == TOK_STR) >> cstr_len = cstr->size; >> else >> cstr_len = cstr->size / sizeof(nwchar_t); >> cstr_len--; >> nb = cstr_len; >> if (n >= 0 && nb > (n - array_length)) >> nb = n - array_length; >> if (!size_only) { >> if (cstr_len > nb) >> warning("initializer-string for array is too >> long"); >> /* in order to go faster for common case (char >> string in global variable, we handle it >> specifically */ >> if (sec && tok == TOK_STR && size1 == 1) { >> memcpy(sec->data + c + array_length, cstr->data, >> nb); >> } else { >> for(i=0;i<nb;i++) { >> if (tok == TOK_STR) >> ch = ((unsigned char *)cstr->data)[i]; >> else >> ch = ((nwchar_t *)cstr->data)[i]; >> init_putv(t1, sec, c + (array_length + i) * >> size1, >> ch, EXPR_VAL); >> } >> } >> } >> array_length += nb; >> next(); >> } >> /* only add trailing zero if enough storage (no >> warning in this case since it is standard) */ >> if (n < 0 || array_length < n) { >> if (!size_only) { >> init_putv(t1, sec, c + (array_length * size1), 0, >> EXPR_VAL); >> } >> array_length++; >> } >> } else { >> index = 0; >> while (tok != '}') { >> decl_designator(type, sec, c, &index, NULL, size_only); >> if (n >= 0 && index >= n) >> error("index too large"); >> /* must put zero in holes (note that doing it that way >> ensures that it even works with designators) */ >> if (!size_only && array_length < index) { >> init_putz(t1, sec, c + array_length * size1, >> (index - array_length) * size1); >> } >> index++; >> if (index > array_length) >> array_length = index; >> /* special test for multi dimensional arrays (may not >> be strictly correct if designators are used at the >> same time) */ >> if (index >= n && no_oblock) >> break; >> if (tok == '}') >> break; >> skip(','); >> } >> } >> if (!no_oblock) >> skip('}'); >> /* put zeros at the end */ >> if (!size_only && n >= 0 && array_length < n) { >> init_putz(t1, sec, c + array_length * size1, >> (n - array_length) * size1); >> } >> /* patch type size if needed */ >> if (n < 0) >> s->c = array_length; >> //[yuanbin >> //} else if ((type->t & VT_BTYPE) == VT_STRUCT && >> } else if ((type->t & VT_BTYPE) == VT_STRUCT && type->ref->c && >> //] >> (sec || !first || tok == '{')) { >> int par_count; >> >> /* NOTE: the previous test is a specific case for automatic >> struct/union init */ >> /* XXX: union needs only one init */ >> >> /* XXX: this test is incorrect for local initializers >> beginning with ( without {. It would be much more difficult >> to do it correctly (ideally, the expression parser should >> be used in all cases) */ >> par_count = 0; >> if (tok == '(') { >> AttributeDef ad1; >> CType type1; >> next(); >> while (tok == '(') { >> par_count++; >> next(); >> } >> if (!parse_btype(&type1, &ad1)) >> expect("cast"); >> type_decl(&type1, &ad1, &n, TYPE_ABSTRACT); >> #if 0 >> if (!is_assignable_types(type, &type1)) >> error("invalid type for cast"); >> #endif >> skip(')'); >> } >> no_oblock = 1; >> if (first || tok == '{') { >> skip('{'); >> no_oblock = 0; >> } >> s = type->ref; >> f = s->next; >> //[yuanbin >> while (f->next && f->next->c==f->c) >> f = f->next; >> //] >> array_length = 0; >> index = 0; >> n = s->c; >> while (tok != '}') { >> decl_designator(type, sec, c, NULL, &f, size_only); >> index = f->c; >> if (!size_only && array_length < index) { >> init_putz(type, sec, c + array_length, >> index - array_length); >> } >> index = index + type_size(&f->type, &align1); >> if (index > array_length) >> array_length = index; >> //[yuanbin >> //f = f->next; >> do >> f = f->next; >> while (f && f->next && f->next->c==f->c); >> //] >> if (no_oblock && f == NULL) >> break; >> if (tok == '}') >> break; >> skip(','); >> } >> /* put zeros at the end */ >> if (!size_only && array_length < n) { >> init_putz(type, sec, c + array_length, >> n - array_length); >> } >> if (!no_oblock) >> skip('}'); >> while (par_count) { >> skip(')'); >> par_count--; >> } >> } else if (tok == '{') { >> next(); >> decl_initializer(type, sec, c, first, size_only); >> skip('}'); >> } else if (size_only) { >> /* just skip expression */ >> parlevel = 0; >> while ((parlevel > 0 || (tok != '}' && tok != ',')) && >> tok != -1) { >> if (tok == '(') >> parlevel++; >> else if (tok == ')') >> parlevel--; >> next(); >> } >> } else { >> /* currently, we always use constant expression for globals >> (may change for scripting case) */ >> expr_type = EXPR_CONST; >> if (!sec) >> expr_type = EXPR_ANY; >> init_putv(type, sec, c, 0, expr_type); >> } >> } >> >> _______________________________________________ >> Tinycc-devel mailing list >> tinycc-de...@nongnu.org >> http://lists.nongnu.org/mailman/listinfo/tinycc-devel >> > > > _______________________________________________ > Tinycc-devel mailing list > tinycc-de...@nongnu.org > http://lists.nongnu.org/mailman/listinfo/tinycc-devel >