def open(self): if not self.isOpen: print "Opening Python file", self.filename trace_interpret.trace_file(self.filename) print "Done interpreting file, about to open trace" Artutils.openHatFile("Sombrero", self.tracename) self.isOpen = True
def name(self): #print "finding the name of a program object" # return a string if not hasattr(self, "_data"): if isExp(self.typ): #print "about to call Artutils.traceFromFO on fileoffset", self.fo self._data = Artutils.traceFromFO(self.fo, 0, 5) #print "Artutils.traceFromFO returned", self._data if self.typ == Art.ExpConstUse: self._data.expr = self._data.expr + " (use)" elif self.typ == Art.ExpConstDef: self._data.expr = self._data.expr + " (def)" elif self.typ == Art.ExpValueUse: self._data.expr = self._data.expr + " (use)" elif isAtom(self.typ): self._data = Artutils.readAtomAt(self.fo) if self.typ == Art.AtomVariable: self._data.idname = self._data.idname + " (var)" else: raise Exception("Can't get data for node type " + str(self.typ)) #print "have the data structure that holds the name" if isinstance(self._data, Artutils.Trace): return self._data.expr elif isinstance(self._data, Artutils.Ident): return self._data.idname else: raise Exception("Don't understand data " + str(self._data))
def definition(self): # return a program object or None if not hasattr(self, "_definition"): if self.typ == Art.ExpConstUse or self.typ == Art.ExpValueUse: self._definition = Program(Artutils.peekExpArg(self.fo, 0)) else: self._definition = None return self._definition
def result(self): # return a program object or None if not hasattr(self, "_result"): r = Artutils.peekResult(self.fo) if r == 0 or r == self.fo: self._result = None else: self._result = Program(r) return self._result
def parent(self): # return a program object or None if not hasattr(self, "_parent"): p = Artutils.parentNode(self.fo) if not p == 0: self._parent = Program(p) else: self._parent = None #print "parent of", self, "is", self._parent return self._parent
def subexps(self): # subexps: right now we have a special case to find the subexps # of a basic expression, because the C function won't let us, # and everything else just calls the C. this is not quite # correct, because there are certain things that are not basic # values but still don't have subexpressions, but we don't deal # with those things right now. however, regardless of # correctness, it might make more sense in the future to switch # the type of special-casing: only call peekExpArg if our typ # meets certain conditions which are known to work, and # otherwise don't. #print "about to find subexps of", self.name() if isBasicExp(self.typ): se = [] else: se = [Program(Artutils.peekExpArg(self.fo, n)) for n in range(0, self.arity+1)] #print "the subexps of", self.name(), "are", se return se
def default_program(self): return Program(Artutils.findMainUse(True))
def __init__(self, fileoffset): self.typ = Artutils.getNodeType(fileoffset) self.arity = Artutils.getExpArity(fileoffset)
def close(self): if self.isOpen: Artutils.closeHatFile() self.isOpen = False
def resume(self): if not self.isOpen: Artutils.openHatFile("Sombrero", self.tracename) self.isOpen = True
def open(self): if not self.isOpen: Artutils.openHatFile("Sombrero", self.filename) self.isOpen = True