def index_xpredicate(self, p, subst={}): def gett(t): return self.dictionary.s_term_to_exp_index(t, subst=subst) if p.is_not_null(): args = [gett(p.get_term())] tags = ['nn'] def f(index, key): return PO.CPONotNull(self, index, tags, args) return self.po_predicate_table.add(IT.get_key(tags, args), f) if p.is_relational_expr(): expsubst = {} for name in subst: expix = self.dictionary.varinfo_to_exp_index(subst[name]) expsubst[name] = self.dictionary.get_exp(expix) expix = self.dictionary.s_term_bool_expr_to_exp_index( p.get_op(), p.get_term1(), p.get_term2(), expsubst) args = [expix] tags = ['vc'] def f(index, key): return PO.CPOValueConstraint(self, index, tags, args) return self.po_predicate_table.add(IT.get_key(tags, args), f) print('Index xpredicate missing: ' + str(p)) exit(1)
def parse_mathml_offset(self, tnode): if tnode is None: tags = ['no'] def f(index, key): return ST.STArgNoOffset(self, index, tags, []) return self.s_offset_table.add(IT.get_key(tags, []), f) elif tnode.tag == 'field': offsetnode = tnode[0] if len(tnode) > 0 else None tags = ['fo', tnode.get('name')] args = [self.parse_mathml_offset(offsetnode)] def f(index, key): return ST.STArgFieldOffset(self, index, tags, args) return self.s_offset_table.add(IT.get_key(tags, args), f) elif tnode.tag == 'index': offsetnode = tnode[0] if len(tnode) > 0 else None tags = ['io', tnode.get('i')] args = [self.parse_mathml_offset(offsetnode)] def f(index, key): return ST.STArgIndexOffset(self, index, tags, args) return self.s_offset_table.add(IT.get_key(tags, args), f) else: print('Encountered index offset') exit(1)
def index_init(self, init, fid=-1): try: if init.is_single(): tags = ['single'] args = [self.dictionary.index_exp(init.get_exp())] def f(index, key): return CI.CSingleInitInfo(self, index, tags, args) return self.initinfo_table.add(IT.get_key(tags, args), f) if init.is_compound(): tags = ['compound'] gtype = self.dictionary.index_typ(init.get_typ()) oinits = [ self.index_offset_init(x) for x in init.get_offset_initializers() ] args = [gtype] + oinits def f(index, key): return CI.CCompoundInitInfo(self, index, tags, args) return self.initinfo_table.add(IT.get_key(tags, args), f) raise InvalidArgumentError('indexinit: ' + str(init)) except IndexedTableError as e: print('Error in indexing ' + str(init) + ': ' + str(e))
def index_constant(self, c): # TBF if c.is_int(): def f(index, key): return CC.CConstInt(self, index, c.tags, c.args) return self.constant_table.add(IT.get_key(c.tags, c.args), f) if c.is_str(): args = [self.index_string(c.get_string())] def f(index, key): return CC.CConstStr(self, index, c.tags, args) return self.constant_table.add(IT.get_key(c.tags, args), f) if c.is_chr(): def f(index, key): return CC.CConstChr(self, index, c.tags, c.args) return self.constant_table.add(IT.get_key(c.tags, c.args), f) if c.is_real(): def f(index, key): return CC.CConstReal(self, index, c.tags, c.args) return self.constant_table.add(IT.get_key(c.tags, c.args), f) else: print('This constant not yet handled ' + str(c))
def index_offset(self, o, fid=-1): if not o.has_offset(): def f(index, key): return CO.CNoOffset(self, index, o.tags, o.args) return self.offset_table.add(IT.get_key(o.tags, o.args), f) if o.is_field(): ckey = self.convert_ckey(o.get_ckey(), o.cd.cfile.index) args = [ckey, self.index_offset(o.get_offset(), fid)] def f(index, key): return CO.CFieldOffset(self, index, o.tags, args) return self.offset_table.add(IT.get_key(o.tags, args), f) if o.is_index(): args = [ self.index_exp(o.get_index_exp()), self.index_offset(o.get_offset(), fid) ] def f(index, key): return CO.CIndexOffset(self, index, o.tags, args) return self.offset_table.add(IT.get_key(o.tags, args), f)
def __init__(self, cfun): self.cfun = cfun self.pd = self.cfun.cfile.predicatedictionary self.assumption_type_table = IT.IndexedTable('assumption-table') self.ppo_type_table = IT.IndexedTable('ppo-type-table') self.spo_type_table = IT.IndexedTable('spo-type-table') self.tables = [(self.assumption_type_table, self._read_xml_assumption_type_table), (self.ppo_type_table, self._read_xml_ppo_type_table), (self.spo_type_table, self._read_xml_spo_type_table)] self.initialize()
def __init__(self, cfile): self.cfile = cfile self.declarations = self.cfile.declarations self.dictionary = self.declarations.dictionary self.assignment_table = IT.IndexedTable('assignment-table') self.function_name_table = IT.IndexedTable('function-name-table') self.tables = [ (self.function_name_table, self._read_xml_function_name_table), (self.assignment_table, self._read_xml_assignment_table) ] self.initialize()
def __init__(self, cfile): self.cfile = cfile self.nodetable = IT.IndexedTable('nodes') self.cfgtable = IT.IndexedTable('cfg-contexts') self.exptable = IT.IndexedTable('exp-contexts') self.contexttable = IT.IndexedTable('contexts') self.tables = [(self.nodetable, self._read_xml_node_table), (self.cfgtable, self._read_xml_cfg_table), (self.exptable, self._read_xml_exp_table), (self.contexttable, self._read_xml_context_table)] self.initialize()
def __init__(self, vard): self.vard = vard self.cfun = self.vard.cfun self.xd = self.vard.xd self.non_relational_value_table = IT.IndexedTable( 'non-relational-value-table') self.invariant_fact_table = IT.IndexedTable('invariant-fact-table') self.invariant_list_table = IT.IndexedTable('invariant-list-table') self.tables = [(self.non_relational_value_table, self._read_xml_non_relational_value_table), (self.invariant_fact_table, self._read_xml_invariant_fact_table)] self.initialize()
def index_api_parameter(self, p): if p.is_formal(): def f(index, key): return AP.APFormal(self, index, p.tags, p.args) return self.api_parameter_table.add(IT.get_key(p.tags, p.args), f) if c.is_global(): def f(index, key): return AP.APGlobal(self, index, p.tags, p.args) return self.api_parameter_table.add(IT.get_key(p.tags, p.args), f)
def __init__(self,fdecls): self.fdecls = fdecls self.cfun = self.fdecls.cfun self.cfile = self.cfun.cfile self.xd = CFunXprDictionary(self) self.memory_base_table = IT.IndexedTable('memory-base-table') self.memory_reference_data_table = IT.IndexedTable('memory-reference-data-table') self.constant_value_variable_table = IT.IndexedTable('constant-value-variable-table') self.c_variable_denotation_table = IT.IndexedTable('c-variable-denotation-table') self.tables = [ (self.memory_base_table,self._read_xml_memory_base_table), (self.memory_reference_data_table,self._read_xml_memory_reference_data_table), (self.constant_value_variable_table,self._read_xml_constant_value_variable_table), (self.c_variable_denotation_table,self._read_xml_c_variable_denotation_table) ]
def index_lhost(self, h, subst={}, fid=-1): if h.is_var(): args = [self.index_varinfo_vid(h.get_vid(), fid)] def f(index, key): return CH.CLHostVar(self, index, h.tags, args) return self.lhost_table.add(IT.get_key(h.tags, args), f) if h.is_mem(): args = [self.index_exp(h.get_exp(), subst=subst, fid=fid)] def f(index, key): return CH.CLHostMem(self, index, h.tags, args) return self.lhost_table.add(IT.get_key(h.tags, args), f)
def __init__(self, cfile): self.cfile = cfile self.dictionary = self.cfile.declarations.dictionary self.po_predicate_table = IT.IndexedTable('po-predicate-table') self.tables = [(self.po_predicate_table, self._read_xml_po_predicate_table)] self.initialize()
def index_cfg_context(self, cfgcontext): args = [self.index_node(x) for x in cfgcontext.get_nodes()] def f(index, key): return CCfgContext(self, index, [], args) return self.cfgtable.add(IT.get_key([], args), f)
def index_attributes(self, aa): args = [self.index_attribute(a) for a in aa.get_attributes()] def f(index, key): return CA.CAttributes(self, index, aa.tags, args) return self.attributes_table.add(IT.get_key(aa.tags, args), f)
def index_exp_context(self, expcontext): args = [self.index_node(x) for x in expcontext.get_nodes()] def f(index, key): return CExpContext(self, index, [], args) return self.exptable.add(IT.get_key([], args), f)
def index_attribute(self, a): args = [self.index_attrparam(p) for p in a.get_params()] def f(index, key): return CA.CAttribute(self, index, a.tags, args) return self.attribute_table.add(IT.get_key(a.tags, args), f)
def make_opaque_global_varinfo(self, gvid, gname, gtypeix): tags = [gname, 'o_' + str(gvid)] args = [-1, gtypeix, -1, 1, 0, -1, 1, 0] def f(index, key): return CVarInfo(self, index, tags, args) return self.varinfo_table.add(IT.get_key(tags, args), f)
def index_funarg(self, funarg): tags = [funarg.get_name()] args = [self.index_typ(funarg.get_type())] def f(index, key): return CT.CFunArg(self, index, tags, args) return self.funarg_table.add(IT.get_key(tags, args), f)
def __init__(self, cfun, xnode): self.cfun = cfun self.varinfos = {} # vid -> CVarInfo self.dictionary = cfun.cfile.declarations.dictionary self.local_varinfo_table = IT.IndexedTable('local-varinfo-table') self.tables = [(self.local_varinfo_table, self._read_xml_local_varinfo_table)] self.initialize(xnode)
def index_funargs_opt(self, opt_funargs): if opt_funargs is None: return None tags = [] args = [self.index_funarg(f) for f in opt_funargs.get_args()] def f(index, key): return CT.CFunArgs(self, index, tags, args) return self.funargs_table.add(IT.get_key(tags, args), f)
def index_lval(self, lval, subst={}, fid=-1): args = [ self.index_lhost(lval.get_lhost(), subst=subst, fid=fid), self.index_offset(lval.get_offset()) ] def f(index, key): return CV.CLval(self, index, [], args) return self.lval_table.add(IT.get_key([], args), f)
def index_offset_init(self, oinit, fid=-1): args = [ self.dictionary.index_offset(oinit.get_offset()), self.index_init(oinit.get_initializer()) ] def f(index, key): return CI.COffsetInitInfo(self, index, [], args) return self.offset_init_table.add(IT.get_key([], args), f)
def index_cfg_projection(self, context): args = [ self.index_cfg_context(context.get_cfg_context()), self.index_empty_exp_context() ] def f(index, key): return CProgramContext(self, index, [], args) return self.contexttable.add(IT.get_key([], args), f)
def index_opaque_struct(self): tags = ['?'] args = [-1, 1, -1] def f(index, key): if not index in self.compinfo_names: self.compinfo_names[index] = set([]) self.compinfo_names[index].add('opaque-struct') return CCompInfo(self, index, tags, args) return self.compinfo_table.add(IT.get_key(tags, args), f)
def index_s_offset(self, t): if t.is_nooffset(): def f(index, key): return ST.STArgNoOffset(self, index, t.tags, t.args) return self.s_offset_table.add(IT.get_key(t.tags, t.args), f) if t.is_field_offset(): args = [self.index_s_offset(t.get_offset())] def f(index, key): return ST.STArgFieldOffset(self, index, t.tags, args) return self.s_offset_table.add(IT.get_key(t.tags, args), f) if t.is_index_offset(): def f(index, key): return ST.STArgIndexOffset(self, index, t.tags, t.args) return self.s_offset_table.add(IT.get_key(t.tags, t.args), f)
def index_attrparam(self, a): if a.is_int(): def f(index, key): return CA.CAttrInt(self, index, a.tags, a.args) return self.attrparam_table.add(IT.get_key(a.tags, a.args), f) if a.is_str(): def f(index, key): return CA.CAttrStr(self, index, a.tags, a.args) return self.attrparam_table.add(IT.get_key(a.tags, a.args), f) if a.is_cons(): args = [self.index_attrparam(p) for p in a.get_params()] def f(index, key): return CA.CAttrCons(self, index, a.tags, args) return self.attrparam_table.add(IT.get_key(a.tags, a.args), f) print('No case yet for attrparam ' + str(a))
def index_location(self, loc): if (loc.get_line() == -1) and (loc.get_byte() == -1): return -1 args = [ self.index_filename(loc.get_file()), loc.get_byte(), loc.get_line() ] def f(index, key): return CFilename(self, index, [], args) return self.location_table.add(IT.get_key([], args), f)
def __init__(self, capp): self.capp = capp # Basic types dictionary self.dictionary = CGlobalDictionary(self) # Global definitions and declarations dictionary self.fieldinfo_table = IT.IndexedTable('fieldinfo-table') self.compinfo_table = IT.IndexedTable('compinfo-table') self.varinfo_table = IT.IndexedTable('varinfo-table') self.initinfo_table = IT.IndexedTable('initinfo-table') self.offset_init_table = IT.IndexedTable('offset-init-table') self.tables = [(self.fieldinfo_table, self._read_xml_fieldinfo_table), (self.compinfo_table, self._read_xml_compinfo_table), (self.initinfo_table, self._read_xml_initinfo_table), (self.varinfo_table, self._read_xml_varinfo_table), (self.offset_init_table, self._read_xml_offset_init_table)] # Collect names for compinfo equivalence classes self.compinfo_names = {} # gckey -> string set # Collect storage classes for varinfo equivalence classes self.varinfo_storage_classes = {} # gvid -> string # Support data structures for linker self.ckey2gckey = {} # fid -> ckey -> gckey self.vid2gvid = {} # fid -> vid -> gvid self.fieldstrings = {} # string of joined fields -> gckey list self.pending = [] self.conjectured = {} # ckey -> gckey self.reserved = {} # ckey -> gckey self.incompatibles = {} # ckey -> gckey set self.default_function_prototypes = [] # (fid,varinfo) list self.globalcontract = self.capp.globalcontract self._initialize() if self.compinfo_table.size() == 0: self.index_opaque_struct()
def parse_mathml_api_parameter(self, name, pars, gvars=[]): if (not name in pars) and (not name in gvars): print('Error in reading user data: ' + name + ' in file ' + self.cfile.name) if name in pars: tags = ['pf'] args = [pars[name]] def f(index, key): return AP.APFormal(self, index, tags, args) return self.api_parameter_table.add(IT.get_key(tags, args), f) if name in gvars: tags = ['pg', name] args = [] def f(index, key): return AP.APGlobal(self, index, tags, args) return self.api_parameter_table.add(IT.get_key(tags, args), f) print('Api parameter name ' + name + ' not found in parameters or global variables') exit(1)