[cfe-dev] Problems finding the modifiers to a function
ken.j.hill at gmail.com
Tue May 15 00:13:51 PDT 2012
Fred Stakem wrote
> I am fairly new to clang and was using the python bindings and was having
> a problem figuring out how to find more information on a function.
> Specifically I found the functions in a C file but I can't find a way to
> find if a function is static or not. How do you do this? I don't have to
> use to python bindings but they seemed the easiest way to get things up
> and running.
I don't have a solution for you, but I'll share my hack. You problably
have done something similar by now.
def emit_pre_function_modifiers(cursor, source_text):
Find function modifiers that are specified at the beginning of a
cursor -- is the clang AST Cursor object representing a function-like
source_text -- String containing the source code being examined.
Unfortunately the clang AST doesn't track function modifiers, so we have
resort to looking at the source code. This technique can be fooled with
preprocessor definitions and compiler-specific directives!
so = cursor.extent.start.offset
eo = cursor.extent.end.offset
defn = source_text[so:eo].split(' ')
for word in defn:
if '(' in word: break
if word in ['static', 'virtual', 'inline']: sys.stdout.write(word+'
View this message in context: http://clang-developers.42468.n3.nabble.com/Problems-finding-the-modifiers-to-a-function-tp3870648p3987570.html
Sent from the Clang Developers mailing list archive at Nabble.com.
More information about the cfe-dev