Skip to content

Commit

Permalink
cherry-picked changeset [587] from cm branch:
Browse files Browse the repository at this point in the history
stable type order: proper types and leaf types are ordered as defined in TDL & grammar dump version increased to 17

git-svn-id: https://pet.opendfki.de/repos/pet/main@596 4200e16c-5112-0410-ac55-d7fb557a720a
  • Loading branch information
pead01 committed Jul 28, 2009
1 parent 4adc3f5 commit 9da21b2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 71 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
v0.99.??
- stable type order: proper types and leaf types are ordered as defined in TDL
& grammar dump version increased to 17
- added option -sm
- clear memory and stats before rather than after analysis
- added dag_find_paths(), fs::find_paths()
Expand Down
4 changes: 2 additions & 2 deletions cheap/grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,15 @@ tGrammar::tGrammar(const char * filename)
{
grammar_rule *R = grammar_rule::make_grammar_rule(i);
if (R != NULL) {
_syn_rules.push_front(R);
_syn_rules.push_back(R);
_rule_dict[i] = R;
}
}
else if(lex_rule_status(i))
{
grammar_rule *R = grammar_rule::make_grammar_rule(i);
if (R != NULL) {
_lex_rules.push_front(R);
_lex_rules.push_back(R);
_rule_dict[i] = R;
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/dag-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void dag_mark_dump_nodes(struct dag_node *dag)
}

#ifdef FLOP
extern int *leaftype_order;
extern int *rleaftype_order;
#endif

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

#ifdef FLOP
type = leaftype_order[type];
type = rleaftype_order[type];
#endif

dump_n.type = type;
Expand Down
4 changes: 3 additions & 1 deletion common/grammar-dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
* - 14 -> 15 : remove lexicon and rule section; list of rules and lexicon is
* now constructed in the parser using status values
* - 15 -> 16: add new section containing grammar properties
* - 16 -> 17: stable type order: proper types and leaf types are ordered
* as defined in TDL
*/

#ifndef _GRAMMAR_DUMP_H_
Expand All @@ -61,7 +63,7 @@
/** Magic Number of binary grammar files */
#define DUMP_MAGIC 0x03422711
/** Current binary grammar file version */
#define DUMP_VERSION 16
#define DUMP_VERSION 17

/** @name Header Dump
* Dump/Undump the header of the grammar file.
Expand Down
36 changes: 10 additions & 26 deletions common/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#undef SUBTYPECACHE
#endif

#include <cassert>

using namespace std;
using namespace HASH_SPACE;

Expand Down Expand Up @@ -337,34 +339,16 @@ void dump_hierarchy(dumper *f)
f->dump_int(codesize);

// bitcodes for all proper types
for(i = 0; i < first_leaftype; i++)
if(leaftypeparent[rleaftype_order[i]] == -1)
{
typecode[rleaftype_order[i]]->dump(f);
}
else
{
ostringstream errmsg;
errmsg << "leaf type conception error a: `"
<< type_name(rleaftype_order[i]) << "' (" << i << " -> "
<< rleaftype_order[i] << ")";
throw tError(errmsg.str());
}
for(i = 0; i < first_leaftype; i++) {
assert(leaftypeparent[leaftype_order[i]] == -1);
typecode[leaftype_order[i]]->dump(f);
}

// parents for all leaf types
for(i = first_leaftype; i < nstatictypes; i++)
if(leaftypeparent[rleaftype_order[i]] != -1)
{
f->dump_int(rleaftype_order[leaftypeparent[leaftype_order[i]]]);
}
else
{
ostringstream errmsg;
errmsg << "leaf type conception error b: `"
<< type_name(rleaftype_order[i]) << "' (" << i << " -> "
<< rleaftype_order[i] << ")";
throw tError(errmsg.str());
}
for(i = first_leaftype; i < nstatictypes; i++) {
assert(leaftypeparent[leaftype_order[i]] != -1);
f->dump_int(rleaftype_order[leaftypeparent[leaftype_order[i]]]);
}
}

#endif
Expand Down
16 changes: 8 additions & 8 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(rleaftype_order[i]));
f->dump_int(typestatus[rleaftype_order[i]]);
f->dump_string(type_name(leaftype_order[i]));
f->dump_int(typestatus[leaftype_order[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[rleaftype_order[i]]);
f->dump_int(featset[leaftype_order[i]]);
}

f->dump_int(nfeatsets);
Expand All @@ -121,7 +121,7 @@ dump_supertypes(dumper *f)
{
for(int i = 0; i < first_leaftype; i++)
{
list<int> supertypes = immediate_supertypes(rleaftype_order[i]);
list<int> supertypes = immediate_supertypes(leaftype_order[i]);
f->dump_short(supertypes.size());
for(list<int>::iterator it = supertypes.begin(); it != supertypes.end();
++it)
Expand All @@ -139,8 +139,8 @@ dump_print_names(dumper *f)
// print names
for(int i = 0; i < nstatictypes; i++)
{
if(get_printname(rleaftype_order[i]) != get_typename(rleaftype_order[i]))
f->dump_string(print_name(rleaftype_order[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);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ dump_inflrs(dumper *f)
if(types[i]->inflr != 0)
{
ninflr++;
dump_inflr(f, leaftype_order[i], types[i]->inflr);
dump_inflr(f, rleaftype_order[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[rleaftype_order[i]]->thedag);
dag_dump(f, types[leaftype_order[i]]->thedag);
logkb(", types", f);

toc.dump();
Expand Down
49 changes: 17 additions & 32 deletions flop/flop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <fcntl.h>
#include <errno.h>

#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
Expand Down Expand Up @@ -166,45 +167,29 @@ void process_multi_instances()
int *leaftype_order = 0;
int *rleaftype_order = 0;

/**
* Returns true iff type t is a proper type.
*/
inline bool
is_proper(int t) {
return (leaftypeparent[t] == -1);
}

#include <stdio.h>
/**
* Order all leaftypes in one consecutive range after all nonleaftypes.
*/
void reorder_leaftypes()
// we want all leaftypes in one consecutive range after all nonleaftypes
{
int i;

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

int curr = nstatictypes - 1;

for(i = 0; i < nstatictypes && i < curr; i++)
{
// look for next non-leaftype starting downwards from curr
while(leaftypeparent[curr] != -1 && curr > i) curr--;

if(leaftypeparent[i] != -1)
{
leaftype_order[i] = curr;
leaftype_order[curr] = i;
curr --;
}
}
stable_partition(leaftype_order, leaftype_order + nstatictypes, is_proper);

rleaftype_order = (int *) malloc(nstatictypes * sizeof(int));
for(i = 0; i < nstatictypes; i++) rleaftype_order[i] = -1;

for(i = 0; i < nstatictypes; i++) rleaftype_order[leaftype_order[i]] = i;

for(i = 0; i < nstatictypes; i++)
{
if(rleaftype_order[i] == -1)
{
fprintf(stderr, "conception error in leaftype reordering\n");
exit(1);
}
if(rleaftype_order[i] != leaftype_order[i])
fprintf(stderr, "gotcha: %d: %d <-> %d", i, leaftype_order[i], rleaftype_order[i]);
}
for(int i = 0; i < nstatictypes; i++)
rleaftype_order[leaftype_order[i]] = i;
}

void assign_printnames()
Expand Down

0 comments on commit 9da21b2

Please sign in to comment.