Skip to content

Commit 8ca0f14

Browse files
author
roman_yakovenko
committed
adding get_named_parent algorithm
1 parent 16a495a commit 8ca0f14

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

pygccxml/declarations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
from algorithm import make_flatten
8282
from algorithm import apply_visitor
8383
from algorithm import declaration_path
84+
from algorithm import get_named_parent
8485
from algorithm import find_declaration
8586
from algorithm import match_declaration_t
8687
from algorithm import find_all_declarations

pygccxml/declarations/algorithm.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,27 @@ def partial_declaration_path( decl ):
7070
else:
7171
return decl.cache.partial_declaration_path
7272

73+
def get_named_parent( decl ):
74+
"""
75+
returns a reference to a named parent declaration
76+
77+
@param decl: the child declaration
78+
@type decl: L{declaration_t}
79+
80+
@return: reference to L{declaration_t} or None if not found
81+
"""
82+
if not decl:
83+
return None
84+
85+
parent = decl.parent
86+
while parent and ( not parent.name or parent.name == '::' ):
87+
parent = parent.parent
88+
return parent
89+
90+
7391
def full_name_from_declaration_path( dpath ):
7492
##Here I have lack of knowledge:
75-
##TODO: "What is the full name of declaration declared in unnamed namespace?"
93+
##TODO: "What is the full name of declaration declared in unnamed namespace?"
7694
result = filter( None, dpath )
7795
result = result[0] + '::'.join( result[1:] )
7896
return result
@@ -98,7 +116,7 @@ def full_name( decl, with_defaults=True ):
98116
decl.cache.full_partial_name \
99117
= full_name_from_declaration_path( partial_declaration_path( decl ) )
100118
return decl.cache.full_partial_name
101-
119+
102120
def make_flatten( decl_or_decls ):
103121
"""
104122
converts tree representation of declarations to flatten one.

0 commit comments

Comments
 (0)