-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpattern_GenSymbols.py
53 lines (45 loc) · 1.72 KB
/
pattern_GenSymbols.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#///////////////// Use this pattern to generate and manage symbolic representations for pointers to classes
import progSpec
import codeDogParser
classesTracked = {} # track to make sure we do not track a class twice.
def apply(classes, tags, classesToTrack):
S=""
if isinstance(classesToTrack,str):
classesToTrack =[classesToTrack]
for className in classesToTrack:
if className in classesTracked: continue
else: classesTracked[className] = True
C= '''
struct <CLASSNAME> {
we uint: symbolCount <- 0
we Map<me uint, me uint>: ptrToUint
we string: classTag <- "<CLASSNAME>"
we Mutex: chkMySymbol
me string: mySymbol() <- { // find or generate symbol
their <CLASSNAME>: obj <- self
if(obj==NULL){return("NULL")}
protect(chkMySymbol){
me uint: objID <- uniqueObjectID(obj)
if(! ptrToUint.containsKey(objID)){
symbolCount <+- 1
ptrToUint[objID] <- symbolCount
return(classTag + toString(symbolCount))
} else {
me uint: item <- ptrToUint.at(objID)
me uint: symbol <- item
return(classTag + toString(symbol))
}
}
}
// their <CLASSNAME>: classPtrFromSymbol(me string: symbol) <- {} // what about our, my, me, ...?
void: clearSymbol(their <CLASSNAME>: obj) <- {
protect(chkMySymbol){
me uint: objID <- uniqueObjectID(obj)
ptrToUint.erase(objID)
}
}
'''.replace("<CLASSNAME>", className)
C += "}\n"
S += C + "\n"
#print(S)
codeDogParser.AddToObjectFromText(classes[0], classes[1], S, 'Pattern: generate symbols' )