def __getitem__(self, key): """Return the value associated with key. If the dictionary does not currently contain a value for key, one will be drawn from self's iterable. key may be a Z3 literal. """ hkey = z3util.HashableAst(key) if hkey not in self.__map: if isinstance(key, simsym.Symbolic) and \ not _is_literal(simsym.unwrap(key)): # There's nothing wrong with supporting arbitrary ASTs, # but in every place we use DynamicDict, this indicates # an easy-to-miss bug. raise ValueError("Key is not a literal: %r" % key) if self.__fn is None: raise ValueError( "DynamicDict has been read; cannot be extended") try: self.__map[hkey] = self.__fn(key) except StopIteration: raise ValueError("Ran out of values for %r" % key) return self.__map[hkey]
def __getitem__(self, key): """Return the value associated with key. If the dictionary does not currently contain a value for key, one will be drawn from self's iterable. key may be a Z3 literal. """ hkey = z3util.HashableAst(key) if hkey not in self.__map: if isinstance(key, simsym.Symbolic) and \ not _is_literal(simsym.unwrap(key)): # There's nothing wrong with supporting arbitrary ASTs, # but in every place we use DynamicDict, this indicates # an easy-to-miss bug. raise ValueError("Key is not a literal: %r" % key) if self.__fn is None: raise ValueError("DynamicDict has been read; cannot be extended") try: self.__map[hkey] = self.__fn(key) except StopIteration: raise ValueError("Ran out of values for %r" % key) return self.__map[hkey]
def __init__(self): self.fn_to_ino = symtypes.anyDictOfIntToInt('Fs.dir') self.ino_to_data = symtypes.anyDictOfIntToInt('Fs.idata') self.numifree = simsym.SInt.any('Fs.numifree') simsym.assume(self.numifree >= 0) fn = simsym.unwrap(simsym.SInt.any('fn')) simsym.assume(z3.ForAll(fn, z3.Implies(self.fn_to_ino._valid[fn], self.ino_to_data._valid[self.fn_to_ino._map[fn]])))
def __getitem__(self, key): if not isinstance(key, self.__key_type): raise TypeError("key must be %r instance, not %r" % (self.__key_type.__name__, simsym.strtype(key))) if _is_literal(simsym.unwrap(key)): raise ValueError("key must be non-literal, not %r" % key) lit = key.eval(self.__realm) hlit = z3util.HashableAst(lit) if hlit not in self.__map: if self.__fn is None: raise ValueError("Interpreter has been read; cannot be extended") try: self.__map[hlit] = (key, self.__fn(lit)) except StopIteration: raise ValueError("Ran out of values for %r" % key) return self.__map[hlit][1]
def __getitem__(self, key): if not isinstance(key, self.__key_type): raise TypeError("key must be %r instance, not %r" % (self.__key_type.__name__, simsym.strtype(key))) if _is_literal(simsym.unwrap(key)): raise ValueError("key must be non-literal, not %r" % key) lit = key.eval(self.__realm) hlit = z3util.HashableAst(lit) if hlit not in self.__map: if self.__fn is None: raise ValueError( "Interpreter has been read; cannot be extended") try: self.__map[hlit] = (key, self.__fn(lit)) except StopIteration: raise ValueError("Ran out of values for %r" % key) return self.__map[hlit][1]
def expr_vars(e): """Return an AstSet of uninterpreted constants in e. Uninterpreted constants are what people normally think of as "variables". This is in contrast with interpreted constants such as the number 2. Note that this will also return values that belong to universes of uninterpreted sorts, since there is no distinguishable difference between these and other uninterpreted constants. """ res = z3util.AstSet() def rec(e): if not z3.is_ast(e): return if z3.is_const(e) and e.decl().kind() == z3.Z3_OP_UNINTERPRETED: res.add(e) return for child in e.children(): rec(child) rec(simsym.unwrap(e)) return res
def iused(self, ino): fn = simsym.unwrap(simsym.SInt.any('fn')) return simsym.wrap(z3.Exists(fn, z3.And(self.fn_to_ino._valid[fn], self.fn_to_ino._map[fn] == simsym.unwrap(ino))))