David Hakim
2003-05-03 17:04:51 UTC
So I had a chance to go and play around some with the operator
overloading code today. Very nice work Stefano! To try things out
(building off of your work with IntSets) I added some new functions /
methods / and overloaded operators to Stringset (which reminds me I
really should bite the bullet and rename that class from "Stringset" to
"StringSet" ... ugh) .
Anyhow, I added support for the * and *= operators in your structure
just so I could get a hang of how the whole process worked. Very nice
overall! I had to alter mxc.l a little bit because the times operator
was matching the C dereference operator so I added an extra lexical
state for tokens that should only be matched in C prototypes vs moto
prototypes. We should probably add the rest of the operators in now
though just to make sure we aren't going to run into any other lexing /
parsing bugs.
Here are the new methods I added, tests for them are in
util_stringset.moto
-Dave
/** Add the contents of Stringset <i>s</i> to this Stringset. If a
matching String
was already present it is replaces with <i>s</i> **/
void Stringset::addSet(Stringset s) =>
void sset_addSet(Stringset *this, Stringset *p);
/** Clones the contents of this Stringset **/
tracked Stringset Stringset::clone() =>
Stringset* sset_clone(Stringset *this);
/** Returns true if this Stringset contains the same elements as
<i>S</i> **/
boolean Stringset::equals(Stringset s) =>
int sset_equals(Stringset *this, Stringset* S);
/** Removes the contents of Stringset s that are contained in this
Stringset **/
void Stringset::removeSet(Stringset s) =>
void sset_removeSet(Stringset *this, Stringset *p);
/** Returns the union of two Stringsets **/
tracked Stringset Stringset::+=(Stringset i) =>
Stringset * sset_union(Stringset *this, Stringset *i);
/** Returns the intersection of Stringset i1 and Stringset i2 **/
tracked Stringset Stringset::*=(Stringset i) =>
Stringset * sset_intersection(Stringset *this, Stringset *i);
/** Returns the difference Stringset i1 and Stringset i2 **/
tracked Stringset Stringset::-=(Stringset i) =>
Stringset * sset_difference(Stringset *this, Stringset *i);
/** Returns the union of two Stringsets - {x:x is in s1 or x is in s2 }
**/
tracked Stringset +(Stringset s1, Stringset s2) =>
Stringset * sset_union(Stringset * s1, Stringset * s2);
/** Returns the intersection of two Stringsets - {x:x is in s1 and x is
in s2 } **/
tracked Stringset *(Stringset s1, Stringset s2) =>
Stringset * sset_intersection(Stringset * s1, Stringset * s2);
/** Returns the difference Stringset i1 and Stringset i2 - {x:x is in
s1, x is not in s2} **/
tracked Stringset -(Stringset s1, Stringset s2) =>
Stringset * sset_difference(Stringset * s1, Stringset * s2);
/** Returns the union of two Stringsets - {x:x is in s1 or x is in s2 }
**/
tracked Stringset union(Stringset s1, Stringset s2) =>
Stringset * sset_union(Stringset * s1, Stringset * s2);
/** Returns the intersection of two Stringsets - {x:x is in s1 and x is
in s2 } **/
tracked Stringset intersection(Stringset s1, Stringset s2) =>
Stringset * sset_intersection(Stringset * s1, Stringset * s2);
/** Returns the difference Stringset i1 and Stringset i2 - {x:x is in
s1, x is not in s2} **/
Stringset difference(Stringset s1, Stringset s2) =>
Stringset * sset_difference(Stringset * s1, Stringset * s2);
overloading code today. Very nice work Stefano! To try things out
(building off of your work with IntSets) I added some new functions /
methods / and overloaded operators to Stringset (which reminds me I
really should bite the bullet and rename that class from "Stringset" to
"StringSet" ... ugh) .
Anyhow, I added support for the * and *= operators in your structure
just so I could get a hang of how the whole process worked. Very nice
overall! I had to alter mxc.l a little bit because the times operator
was matching the C dereference operator so I added an extra lexical
state for tokens that should only be matched in C prototypes vs moto
prototypes. We should probably add the rest of the operators in now
though just to make sure we aren't going to run into any other lexing /
parsing bugs.
Here are the new methods I added, tests for them are in
util_stringset.moto
-Dave
/** Add the contents of Stringset <i>s</i> to this Stringset. If a
matching String
was already present it is replaces with <i>s</i> **/
void Stringset::addSet(Stringset s) =>
void sset_addSet(Stringset *this, Stringset *p);
/** Clones the contents of this Stringset **/
tracked Stringset Stringset::clone() =>
Stringset* sset_clone(Stringset *this);
/** Returns true if this Stringset contains the same elements as
<i>S</i> **/
boolean Stringset::equals(Stringset s) =>
int sset_equals(Stringset *this, Stringset* S);
/** Removes the contents of Stringset s that are contained in this
Stringset **/
void Stringset::removeSet(Stringset s) =>
void sset_removeSet(Stringset *this, Stringset *p);
/** Returns the union of two Stringsets **/
tracked Stringset Stringset::+=(Stringset i) =>
Stringset * sset_union(Stringset *this, Stringset *i);
/** Returns the intersection of Stringset i1 and Stringset i2 **/
tracked Stringset Stringset::*=(Stringset i) =>
Stringset * sset_intersection(Stringset *this, Stringset *i);
/** Returns the difference Stringset i1 and Stringset i2 **/
tracked Stringset Stringset::-=(Stringset i) =>
Stringset * sset_difference(Stringset *this, Stringset *i);
/** Returns the union of two Stringsets - {x:x is in s1 or x is in s2 }
**/
tracked Stringset +(Stringset s1, Stringset s2) =>
Stringset * sset_union(Stringset * s1, Stringset * s2);
/** Returns the intersection of two Stringsets - {x:x is in s1 and x is
in s2 } **/
tracked Stringset *(Stringset s1, Stringset s2) =>
Stringset * sset_intersection(Stringset * s1, Stringset * s2);
/** Returns the difference Stringset i1 and Stringset i2 - {x:x is in
s1, x is not in s2} **/
tracked Stringset -(Stringset s1, Stringset s2) =>
Stringset * sset_difference(Stringset * s1, Stringset * s2);
/** Returns the union of two Stringsets - {x:x is in s1 or x is in s2 }
**/
tracked Stringset union(Stringset s1, Stringset s2) =>
Stringset * sset_union(Stringset * s1, Stringset * s2);
/** Returns the intersection of two Stringsets - {x:x is in s1 and x is
in s2 } **/
tracked Stringset intersection(Stringset s1, Stringset s2) =>
Stringset * sset_intersection(Stringset * s1, Stringset * s2);
/** Returns the difference Stringset i1 and Stringset i2 - {x:x is in
s1, x is not in s2} **/
Stringset difference(Stringset s1, Stringset s2) =>
Stringset * sset_difference(Stringset * s1, Stringset * s2);