From syamajala at gmail.com Sat Mar 26 04:13:01 2016 From: syamajala at gmail.com (seshu yamajala) Date: Sat, 26 Mar 2016 04:13:01 -0400 Subject: [CastXML] Parsing class with nested struct definition. Message-ID: <56F6448D.7010904@gmail.com> I'm trying to use pygccxml to auto-generate some C++. The problem I'm having is if I have a class like: class MyClass { struct SomeStruct { int structmem; }; SomeStruct classmem; }; When I look at the variables of the MyClass declaration, its listing both structmem and classmem as members. Is there a way to tell that structmem is a member of SomeStruct and that SomeStruct was defined inside of MyClass? From michkapopoff at gmail.com Sat Mar 26 06:27:26 2016 From: michkapopoff at gmail.com (Michka Popoff) Date: Sat, 26 Mar 2016 11:27:26 +0100 Subject: [CastXML] Parsing class with nested struct definition. In-Reply-To: <56F6448D.7010904@gmail.com> References: <56F6448D.7010904@gmail.com> Message-ID: <280773B2-E8A1-4060-AB23-D9805FCB7A05@gmail.com> Hi as you discovered, the variables() method will return all the variables found under a specific node in the declarations tree. I wrote a small example showing how to access the parent declaration of a variable. The loops at the end show how you could filter out the variables from the different classes/structs. The last one shows how to use the recursive=False option to get variables from the first level only. I hope this helps. Michka from pygccxml import utils from pygccxml import parser from pygccxml import declarations generator_path, generator_name = utils.find_xml_generator() xml_generator_config = parser.xml_generator_configuration_t( xml_generator_path=generator_path, xml_generator=generator_name) code = """class MyClass { struct SomeStruct { int structmem; }; SomeStruct classmem; }; """ decls = parser.parse_string(code, xml_generator_config) ns = declarations.get_global_namespace(decls) myclass = ns.classes()[0] somestruct = ns.classes()[0].classes()[0] # MyClass [class] print(myclass) # MyClass::SomeStruct [struct] print(somestruct) # MyClass::SomeStruct::structmem [variable] print(myclass.classes()[0].variables()[0]) # MyClass::SomeStruct::structmem [variable] # MyClass::classmem [variable] for var in myclass.variables(): if isinstance(var, declarations.variable_t): print(var) # MyClass::SomeStruct [struct] print(myclass.classes()[0].variables()[0].parent) # Found: MyClass::SomeStruct::structmem [variable] for var in myclass.variables(): if isinstance(var, declarations.variable_t): if var.parent == somestruct: print("Found: " + str(var)) # Found: MyClass::classmem [variable] for var in myclass.variables(): if isinstance(var, declarations.variable_t): if var.parent == myclass: print("Found: " + str(var)) # Found: MyClass::classmem [variable] for var in myclass.variables(recursive=False): if isinstance(var, declarations.variable_t): print("Found: " + str(var)) > On 26 Mar 2016, at 09:13, seshu yamajala wrote: > > I'm trying to use pygccxml to auto-generate some C++. The problem I'm having is if I have a class like: > > class MyClass { > struct SomeStruct { > int structmem; > }; > > SomeStruct classmem; > }; > > When I look at the variables of the MyClass declaration, its listing both structmem and classmem as members. Is there a way to tell that structmem is a member of SomeStruct and that SomeStruct was defined inside of MyClass? > > _______________________________________________ > CastXML mailing list > CastXML at public.kitware.com > http://public.kitware.com/mailman/listinfo/castxml From michkapopoff at gmail.com Sat Mar 26 06:59:19 2016 From: michkapopoff at gmail.com (Michka Popoff) Date: Sat, 26 Mar 2016 11:59:19 +0100 Subject: [CastXML] Parsing class with nested struct definition. In-Reply-To: <280773B2-E8A1-4060-AB23-D9805FCB7A05@gmail.com> References: <56F6448D.7010904@gmail.com> <280773B2-E8A1-4060-AB23-D9805FCB7A05@gmail.com> Message-ID: Just a small comment on my code, the "if isinstance(var, declarations.variable_t)? checks are not needed. I was on an experimental branch, were some stuff was broken. The variables() method only returns variables; this check is superfluous. Michka > On 26 Mar 2016, at 11:27, Michka Popoff wrote: > > Hi > > as you discovered, the variables() method will return all the variables found > under a specific node in the declarations tree. > > I wrote a small example showing how to access the parent declaration of a variable. > The loops at the end show how you could filter out the variables from the different > classes/structs. The last one shows how to use the recursive=False option to get > variables from the first level only. > > I hope this helps. > > Michka > > > > > from pygccxml import utils > from pygccxml import parser > from pygccxml import declarations > > generator_path, generator_name = utils.find_xml_generator() > xml_generator_config = parser.xml_generator_configuration_t( > xml_generator_path=generator_path, > xml_generator=generator_name) > > code = """class MyClass { > struct SomeStruct { > int structmem; > }; > > SomeStruct classmem; > }; > """ > > decls = parser.parse_string(code, xml_generator_config) > ns = declarations.get_global_namespace(decls) > myclass = ns.classes()[0] > somestruct = ns.classes()[0].classes()[0] > > # MyClass [class] > print(myclass) > > # MyClass::SomeStruct [struct] > print(somestruct) > > # MyClass::SomeStruct::structmem [variable] > print(myclass.classes()[0].variables()[0]) > > # MyClass::SomeStruct::structmem [variable] > # MyClass::classmem [variable] > for var in myclass.variables(): > if isinstance(var, declarations.variable_t): > print(var) > > # MyClass::SomeStruct [struct] > print(myclass.classes()[0].variables()[0].parent) > > # Found: MyClass::SomeStruct::structmem [variable] > for var in myclass.variables(): > if isinstance(var, declarations.variable_t): > if var.parent == somestruct: > print("Found: " + str(var)) > > # Found: MyClass::classmem [variable] > for var in myclass.variables(): > if isinstance(var, declarations.variable_t): > if var.parent == myclass: > print("Found: " + str(var)) > > # Found: MyClass::classmem [variable] > for var in myclass.variables(recursive=False): > if isinstance(var, declarations.variable_t): > print("Found: " + str(var)) > >> On 26 Mar 2016, at 09:13, seshu yamajala wrote: >> >> I'm trying to use pygccxml to auto-generate some C++. The problem I'm having is if I have a class like: >> >> class MyClass { >> struct SomeStruct { >> int structmem; >> }; >> >> SomeStruct classmem; >> }; >> >> When I look at the variables of the MyClass declaration, its listing both structmem and classmem as members. Is there a way to tell that structmem is a member of SomeStruct and that SomeStruct was defined inside of MyClass? >> >> _______________________________________________ >> CastXML mailing list >> CastXML at public.kitware.com >> http://public.kitware.com/mailman/listinfo/castxml > From michkapopoff at gmail.com Thu Mar 31 18:17:24 2016 From: michkapopoff at gmail.com (Michka Popoff) Date: Fri, 1 Apr 2016 00:17:24 +0200 Subject: [CastXML] [ANNOUNCE] pygccxml v1.7.3 released References: <91E8DBA9-84C4-4231-B305-14209288BFB4@gmail.com> Message-ID: Hi I am really pleased to announce that pygccxml v1.7.3 has been released. pygccxml is a specialized XML reader that reads the output from CastXML or GCC-XML. It provides a simple framework to navigate C++ declarations, using Python classes. https://github.com/gccxml/pygccxml This version brings many bug fixes, especially for people working with py++. The release notes can be found here: http://pygccxml.readthedocs.org/en/develop/history.html#version-1-7- 3 A special thanks to all the contributors which made this release possible ! Michka -------------- next part -------------- An HTML attachment was scrubbed... URL: