Revision: 1390
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1390&view=rev
Author: roman_yakovenko
Date: 2008-08-09 11:25:14 +0000 (Sat, 09 Aug 2008)
Log Message:
-----------
adding get_named_parent algorithm
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/__init__.py
pygccxml_dev/pygccxml/declarations/algorithm.py
Modified: pygccxml_dev/pygccxml/declarations/__init__.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/__init__.py 2008-08-09 08:44:35 UTC (rev 1389)
+++ pygccxml_dev/pygccxml/declarations/__init__.py 2008-08-09 11:25:14 UTC (rev 1390)
@@ -81,6 +81,7 @@
from algorithm import make_flatten
from algorithm import apply_visitor
from algorithm import declaration_path
+from algorithm import get_named_parent
from algorithm import find_declaration
from algorithm import match_declaration_t
from algorithm import find_all_declarations
Modified: pygccxml_dev/pygccxml/declarations/algorithm.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/algorithm.py 2008-08-09 08:44:35 UTC (rev 1389)
+++ pygccxml_dev/pygccxml/declarations/algorithm.py 2008-08-09 11:25:14 UTC (rev 1390)
@@ -70,9 +70,27 @@
else:
return decl.cache.partial_declaration_path
+def get_named_parent( decl ):
+ """
+ returns a reference to a named parent declaration
+
+ @param decl: the child declaration
+ @type decl: L{declaration_t}
+
+ @return: reference to L{declaration_t} or None if not found
+ """
+ if not decl:
+ return None
+
+ parent = decl.parent
+ while parent and ( not parent.name or parent.name == '::' ):
+ parent = parent.parent
+ return parent
+
+
def full_name_from_declaration_path( dpath ):
##Here I have lack of knowledge:
- ##TODO: "What is the full name of declaration declared in unnamed namespace?"
+ ##TODO: "What is the full name of declaration declared in unnamed namespace?"
result = filter( None, dpath )
result = result[0] + '::'.join( result[1:] )
return result
@@ -98,7 +116,7 @@
decl.cache.full_partial_name \
= full_name_from_declaration_path( partial_declaration_path( decl ) )
return decl.cache.full_partial_name
-
+
def make_flatten( decl_or_decls ):
"""
converts tree representation of declarations to flatten one.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|