def get_is_pagefault(self, decl_ast = None): if decl_ast is None: decl_ast = self.decl_ast modifiers = [] #print 'get_is_pagefault(): decl.ast = ', self.decl_ast for deco_node in decl_ast['decorator']: for modifier_ast in deco_node['annotation']: if modifier_ast.leaf == 'kernelmsg': if evaluate(modifier_ast.the('expression')) =='idl4::pagefault': return True return False
def get_annotations(self): decorators = {} for decorator in self.decorators_list: for arg in decorator.children: args = [] #for exp in arg.children: #args.append(arg.the('expression').leaf) if len(arg['expression']) != 0: #print 'get_annotations: ', arg['expression'] for exp in arg['expression']: args.append(evaluate(exp)) decorators[arg.leaf] = args return decorators
def get_modifiers(self): modifiers = [] for deco_node in self.decl_ast['decorator']: for modifier_ast in deco_node['annotation']: arg_ast = [] for exp_node in modifier_ast['expression']: arg_ast.append(evaluate(exp_node)) if arg_ast == []: modifiers.append( (modifier_ast.leaf, ()) ) elif len(arg_ast) == 1: modifiers.append( (modifier_ast.leaf, arg_ast[0]) ) else: modifiers.append( (modifier_ast.leaf, arg_ast) ) return modifiers
def get_uuid(self): uuid = self._get_uuid_ast() if uuid is not None: return evaluate(uuid.the('expression')) return None
def init_declarator(self, parentast, pt): """ Return an init_declarator node. We used to return: name expression result indirection This now becomes a Node with name "name", child "expression", attribute "indirection", a result, and possibly other children """ decl = Node(None, 'declarator') if pt.name == 'member_declarator_bitfield': decl.leaf = pt.leaf decl.add_child(pt.get_child('expression')) try: decl.result = evaluate(pt.get_child('expression'), parentast) except Exception: decl.result = pt.get_child('expression').result elif pt.name == 'attribute': attribute_pt = pt.children[0] # FIXME: Attribute support decl.set_name('attribute') decl.set_leaf(attribute_pt.name) elif pt.name in ("init_declarator", "member_declarator"): indirection = '' # Now we want this: # declarator * # direct_declarator ID # # ... or any of these : # direct_declarator ID <- function declaration # parameter_list # type_qualifier # exception_specification # direct_declarator ID <- class instantation / array declaration # expression # direct_declarator ID <- ? # declarator <- function ptr # declarator_suffixes decl_pt = pt.get_child('declarator') direct_decl_pt = pt.get_child('direct_declarator') decl_suffixes_pt = None # We want to get to a direct_declarator if it exists. This is a convoluted # process -- probably best to refer to the relevant grammar section. while decl_pt is not None: if decl_pt.leaf == '*': indirection += '*' direct_decl_pt = decl_pt.get_child('direct_declarator') if direct_decl_pt: break else: decl_pt = decl_pt.get_child('declarator') assert decl_pt decl.add_attribute('indirection', indirection) # Now we are down to direct_declarator. if direct_decl_pt.has_child('declarator'): # This is a function pointer - we don't support these too well. decl_pt = direct_decl_pt.get_child('declarator') direct_decl_pt = decl_pt.get_child('direct_declarator') decl.leaf = direct_decl_pt.leaf expr = pt.get_child('expression') if not expr and pt.has_child('initializer'): expr = pt.get_child('initializer').get_child('expression') ast_expr = None if expr: ast_expr = get_expression(parentast, expr, self) if ast_expr: decl.add_child(ast_expr) return decl