X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=blobdiff_plain;f=notes%2Fdefinition.cc;h=99d5a9394a0c9cbe4c85a1400770428c185f9a8b;hp=0c5b7965174727e5414f005c0421f33188937e35;hb=fb52175d1e1ebe5f73f6b4b0513b6302d3c03031;hpb=189207ea1c47667cd77bcd5a41b37ff023a48315;ds=sidebyside diff --git a/notes/definition.cc b/notes/definition.cc index 0c5b796..99d5a93 100644 --- a/notes/definition.cc +++ b/notes/definition.cc @@ -12,24 +12,43 @@ using namespace std; -typedef struct MethodCall { +struct MethodCall; + +typedef MethodCall *Method; +typedef set *MethodSet; + +struct MethodCall { string interfaceName; // The interface label name void *value; // The pointer that points to the struct that have the return // value and the arguments void *state; // The pointer that points to the struct that represents // the state - set *prev; // Method calls that are hb right before me - set *next; // Method calls that are hb right after me - set *concurrent; // Method calls that are concurrent with me -} MethodCall; + MethodSet prev; // Method calls that are hb right before me + MethodSet next; // Method calls that are hb right after me + MethodSet concurrent; // Method calls that are concurrent with me + + MethodCall(string name) : MethodCall() { interfaceName = name; } + + MethodCall() : interfaceName(""), prev(new set), + next(new set), concurrent(new set) { } + + void addPrev(Method m) { prev->insert(m); } + + void addNext(Method m) { next->insert(m); } + + void addConcurrent(Method m) { concurrent->insert(m); } + +}; -typedef MethodCall *Method; -typedef set *MethodSet; typedef vector IntVector; typedef list IntList; typedef set IntSet; +typedef vector DoubleVector; +typedef list DoubleList; +typedef set DoubleSet; + /********** More general specification-related types and operations **********/ #define NewMethodSet new set @@ -97,19 +116,19 @@ typedef set IntSet; /** We provide a more general subset operation that takes a plain boolean expression on each item (access by the name "ITEM") of the set, and put it - into a new set if the boolean expression (Guard) on that item holds. This is - used as the second arguments of the Subset operation. An example to extract - a subset of positive elements on an IntSet "s" would be "Subset(s, + into a new set if the boolean expression (Guard) on that item holds. This + is used as the second arguments of the Subset operation. An example to + extract a subset of positive elements on an IntSet "s" would be "Subset(s, GeneralGuard(int, ITEM > 0))" */ #define GeneralGuard(type, expression) std::function ( \ - [](type ITEM) -> bool { return (expression);}) \ + [&](type ITEM) -> bool { return (expression);}) \ /** This is a more specific guard designed for the Method (MethodCall*). It basically wrap around the GeneralGuard with the type Method. An example to - extract the subset of method calls in the PREV set whose state "x" is - equal to "val" would be "Subset(PREV, Guard(STATE(x) == val))" + extract the subset of method calls in the PREV set whose state "x" is equal + to "val" would be "Subset(PREV, Guard(STATE(x) == val))" */ #define Guard(expression) GeneralGuard(Method, expression) @@ -117,9 +136,8 @@ typedef set IntSet; A general subset operation that takes a condition and returns all the item for which the boolean guard holds. */ -template -inline set* Subset(set *original, std::function condition) { - set *res = new set; +inline MethodSet Subset(MethodSet original, std::function condition) { + MethodSet res = new SnapSet; ForEach (_M, original) { if (condition(_M)) res->insert(_M); @@ -127,6 +145,21 @@ inline set* Subset(set *original, std::function condition) { return res; } +/** + A general set operation that takes a condition and returns if there exists + any item for which the boolean guard holds. +*/ +template +inline bool HasItem(set *original, std::function condition) { + ForEach (_M, original) { + if (condition(_M)) + return true; + } + return false; +} + + + /** A general sublist operation that takes a condition and returns all the item for which the boolean guard holds in the same order as in the old list. @@ -312,11 +345,16 @@ int main() { m->value = ld; ms->insert(m); - MakeSet(int, ms, newis, STATE(x)); - cout << "Size=" << Size(newis) << " | val= " << Belong(newis, 2) << endl; - ForEach (i, newis) { - cout << "elem: " << i << endl; - } + //MakeSet(int, ms, newis, STATE(x)); + //cout << "Size=" << Size(newis) << " | val= " << Belong(newis, 2) << endl; + + int x = 2; + int y = 2; + cout << "HasItem=" << HasItem(ms, Guard(STATE(x) == x && y == 0)) << endl; + + //ForEach (i, newis) { + //cout << "elem: " << i << endl; + //} //Subset(ms, sub, NAME == "Store" && VALUE(Store, val) != 0);