Skip to content

Commit

Permalink
fixed wrong use of (ex) leaftype_order in full form dumping and renamed
Browse files Browse the repository at this point in the history
(r)leaftype_order to the more descriptive cheap2flop resp. flop2cheap.
See comment in types.h for documentation.


git-svn-id: https://pet.opendfki.de/repos/pet/main@621 4200e16c-5112-0410-ac55-d7fb557a720a
  • Loading branch information
beki01 committed Aug 28, 2009
1 parent f5c5078 commit 23df96b
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 46 deletions.
3 changes: 2 additions & 1 deletion cheap/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ struct tHypothesis
};


// #define CFGAPPROX_LEXGEN 1

/** Represent an item in a chart. Conceptually there are input items,
* lexical items and phrasal items.
*/
Expand Down Expand Up @@ -216,7 +218,6 @@ class tItem {
else if((R->trait() == SYNTAX_TRAIT) ||
((R->trait() == LEX_TRAIT) && (inflrs_complete_p())))
return false;
}
#endif
else if(R->trait() == SYNTAX_TRAIT) {
if(! inflrs_complete_p())
Expand Down
7 changes: 2 additions & 5 deletions common/dag-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ void dag_mark_dump_nodes(struct dag_node *dag)
}
}

#ifdef FLOP
extern int *rleaftype_order;
#endif

int dump_index = 0;

void dag_dump_rec(dumper *f, struct dag_node *dag)
Expand Down Expand Up @@ -208,7 +204,8 @@ void dag_dump_rec(dumper *f, struct dag_node *dag)
type = dag->type;

#ifdef FLOP
type = rleaftype_order[type];
// always dump with cheap type codes
type = flop2cheap[type];
#endif

dump_n.type = type;
Expand Down
10 changes: 5 additions & 5 deletions common/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,16 @@ void dump_hierarchy(dumper *f)
// bitcodesize in bits
f->dump_int(codesize);

// bitcodes for all proper types
// bitcodes for all proper types (in cheap order)
for(i = 0; i < first_leaftype; i++) {
assert(leaftypeparent[leaftype_order[i]] == -1);
typecode[leaftype_order[i]]->dump(f);
assert(leaftypeparent[cheap2flop[i]] == -1);
typecode[cheap2flop[i]]->dump(f);
}

// parents for all leaf types
for(i = first_leaftype; i < nstatictypes; i++) {
assert(leaftypeparent[leaftype_order[i]] != -1);
f->dump_int(rleaftype_order[leaftypeparent[leaftype_order[i]]]);
assert(leaftypeparent[cheap2flop[i]] != -1);
f->dump_int(flop2cheap[leaftypeparent[cheap2flop[i]]]);
}
}

Expand Down
8 changes: 8 additions & 0 deletions common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ type_t lookup_code(const class bitcode &b);

/** Immediate supertypes for each non-leaftype. */
extern std::vector< std::list<int> > immediateSupertype;

#else // FLOP
/*@{*/
/** Tables containing a reordering function for types, from the new (cheap)
* type id to the old (flop) one and the inverse.
*/
extern int *cheap2flop, *flop2cheap;
/*@}*/
#endif

/** Dump the hierarchy to \a f in binary format (bitcodes and leaftypeparents).
Expand Down
34 changes: 17 additions & 17 deletions flop/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ dump_symbol_tables(dumper *f)
// type names and status
for(int i = 0; i < nstatictypes; i++)
{
f->dump_string(type_name(leaftype_order[i]));
f->dump_int(typestatus[leaftype_order[i]]);
f->dump_string(type_name(cheap2flop[i]));
f->dump_int(typestatus[cheap2flop[i]]);
}

// attribute names
Expand All @@ -97,7 +97,7 @@ dump_tables(dumper *f)
// _fix_doc_ Why only for non-leaftypes ??
for(int i = 0; i < first_leaftype; i++)
{
f->dump_int(featset[leaftype_order[i]]);
f->dump_int(featset[cheap2flop[i]]);
}

f->dump_int(nfeatsets);
Expand All @@ -111,21 +111,21 @@ dump_tables(dumper *f)
}

for(int i = 0; i < nattrs; i++)
f->dump_int(rleaftype_order[apptype[i]]);
f->dump_int(flop2cheap[apptype[i]]);
}


/** write (immediate) supertypes for each type */
void
dump_supertypes(dumper *f)
{
for(int i = 0; i < first_leaftype; i++)
for(int i = 0; i < first_leaftype; i++) // i is a cheap type code
{
list<int> supertypes = immediate_supertypes(leaftype_order[i]);
list<int> supertypes = immediate_supertypes(cheap2flop[i]);
f->dump_short(supertypes.size());
for(list<int>::iterator it = supertypes.begin(); it != supertypes.end();
++it)
f->dump_int(rleaftype_order[*it]);
f->dump_int(flop2cheap[*it]);
}
}

Expand All @@ -136,14 +136,14 @@ dump_supertypes(dumper *f)
void
dump_print_names(dumper *f)
{
// print names
for(int i = 0; i < nstatictypes; i++)
{
if(get_printname(leaftype_order[i]) != get_typename(leaftype_order[i]))
f->dump_string(print_name(leaftype_order[i]));
else
f->dump_string(0);
}
// print names (in cheap order, i is a cheap type code)
for(int i = 0; i < nstatictypes; i++) {
int flop_type = cheap2flop[i];
if(get_printname(flop_type) != get_typename(flop_type))
f->dump_string(print_name(flop_type));
else
f->dump_string(0);
}
}

/** Dump the full form table. Here, dumping is delegated to the full form
Expand Down Expand Up @@ -187,7 +187,7 @@ dump_inflrs(dumper *f)
if(types[i]->inflr != 0)
{
ninflr++;
dump_inflr(f, rleaftype_order[i], types[i]->inflr);
dump_inflr(f, flop2cheap[i], types[i]->inflr);
}
}

Expand Down Expand Up @@ -282,7 +282,7 @@ dump_grammar(dumper *f, const char *desc)
toc.start_section(SEC_CONSTRAINTS);

for(int i = 0; i < types.number(); i++)
dag_dump(f, types[leaftype_order[i]]->thedag);
dag_dump(f, types[cheap2flop[i]]->thedag);
logkb(", types", f);

toc.dump();
Expand Down
2 changes: 1 addition & 1 deletion flop/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ void merge_top_down(int t, int p, tPartition &P) {
}

void merge_partitions(int t, int p, tPartition &P, int s) {
if(nfeat[t] == 0 || prefixl.find(t) != prefixl.end() && prefixl[t] >= 0)
if(nfeat[t] == 0 || (prefixl.find(t) != prefixl.end() && prefixl[t] >= 0))
return;

P.union_sets(t, p);
Expand Down
23 changes: 14 additions & 9 deletions flop/flop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,13 @@ void process_multi_instances()
}
}

int *leaftype_order = 0;
int *rleaftype_order = 0;
/** The reorder_leaftypes functions fills the following arrays such that:
* - given a cheap type code i, cheap2flop[i] is the corresponding flop type
* code
* - given a flop type code j, flop2cheap[j] is the corresponding cheap type
*/
int *cheap2flop = 0;
int *flop2cheap = 0;

/**
* Returns true iff type t is a proper type.
Expand All @@ -181,15 +186,15 @@ is_proper(int t) {
*/
void reorder_leaftypes()
{
leaftype_order = (int *) malloc(nstatictypes * sizeof(int));
cheap2flop = (int *) malloc(nstatictypes * sizeof(int));
for(int i = 0; i < nstatictypes; i++)
leaftype_order[i] = i;
cheap2flop[i] = i;

stable_partition(leaftype_order, leaftype_order + nstatictypes, is_proper);
stable_partition(cheap2flop, cheap2flop + nstatictypes, is_proper);

rleaftype_order = (int *) malloc(nstatictypes * sizeof(int));
flop2cheap = (int *) malloc(nstatictypes * sizeof(int));
for(int i = 0; i < nstatictypes; i++)
rleaftype_order[leaftype_order[i]] = i;
flop2cheap[cheap2flop[i]] = i;
}

void assign_printnames()
Expand Down Expand Up @@ -311,8 +316,8 @@ void print_infls() {
if(types[i]->inflr != NULL) {
//if(flop_settings->statusmember("infl-rule-status-values",
// typestatus[i])) {
fprintf(f, "%s:%d\n", type_name(rleaftype_order[i])
, typestatus[rleaftype_order[i]]);
fprintf(f, "%s:%d\n", type_name(flop2cheap[i])
, typestatus[flop2cheap[i]]);
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions flop/flop.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ extern char *global_inflrs;
*/
extern int allow_redefinitions;

/*@{*/
/** Tables containing a reordering function for types, from the old type id to
* the new one and the inverse .
*/
extern int *leaftype_order, *rleaftype_order;
/*@}*/
/** A table containing the parent of a leaf type, if greater than zero.
* \code leaftypeparent[type] < 0 \endcode is a predicate for testing
* if type is not a leaf type (after expansion).
Expand Down
4 changes: 2 additions & 2 deletions flop/full-form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ void ff_entry::dump(dumper *f)
LOG(logSemantic, WARN, "unknown preterminal `" << _preterminal << "'");
}

preterminal = leaftype_order[preterminal];
preterminal = flop2cheap[preterminal];

affix = types.id(_affix);
if(affix != -1)
affix = leaftype_order[affix];
affix = flop2cheap[affix];

if(!_affix.empty() && affix == -1)
{
Expand Down

0 comments on commit 23df96b

Please sign in to comment.