Re: Generating C++ code

Discussion in 'Python' started by Jean-Michel Pichavant, Oct 10, 2012.

  1. ----- Original Message -----
    > On Tue, 09 Oct 2012 20:55:48 +0100
    > Andrea Crotti <> wrote:
    >
    > > On 10/09/2012 05:00 PM, Jean-Michel Pichavant wrote:
    > > > Greetings,
    > > >
    > > > I'm trying to generate C++ code from an XML file. I'd like to use
    > > > a template engine, which imo produce something readable and
    > > > maintainable.
    > > > My google search about this subject has been quite unsuccessful,
    > > > I've been redirected to template engine specific to html mostly.
    > > >
    > > > Does anybody knows a python template engine for generating C++
    > > > code ?
    > > >
    > > > Here's my flow:
    > > >
    > > > XML file -> nice python app -> C++ code
    > > >
    > > > From what I know I could use Cheetah, a generic template engine.
    > > > I never used it though, I'm not sure this is what I need.
    > > > I'm familiar with jinja2 but I'm not sure I could use it to
    > > > generate C++ code, did anybody try ? (maybe that's a silly
    > > > question)
    > > >
    > > > Any advice would be appreciated.
    > > >
    > > > JM

    > >
    > > I think you can use anything to generate C++ code, but is it a good
    > > idea?
    > > Are you going to produce this code only one time and then maintain
    > > it
    > > manually?
    > >
    > > And are you sure that the design that you would get from the XML
    > > file
    > > actually makes sense when
    > > translated in C++?
    > > --
    > > http://mail.python.org/mailman/listinfo/python-list

    >
    > You can build nice python app with Cython/Pyrex too if you got
    > sufficient knowledge in C/C++ programming
    > to extend the app in C. :)
    >
    > Otherwise that seem like a little counter-productive to produce a
    > python template only for generating C stubs when python
    > is good for many things without requiring advanced C++ skills like
    > memory management, etc.
    >
    > HTH,
    > E
    > --
    > Etienne Robillard
    > Green Tea Hackers Club
    > Fine Software Carpentry For The Rest Of Us!
    > http://gthc.org/
    >


    Well, the C++ code will end up running on a MIPS on a SOC, unfortunately, python is not an option here.
    The xml to C++ makes a lot of sense, because only a small part of the code is generated that way (everything related to log & fatal events). Everything else is written directly in C++.

    To answer Andrea's question, the files are regenerated for every compilation (well, unless the xml didn't change, but the xml is highly subject to changes, that's actually its purpose)

    Currently we already have a python script that translate this xml file to C++, but it's done in a way that is difficult to maintain. Basically, when parsing the xml file, it writes the generated C++ code. Something like:
    if 'blabla' in xml:
    h_file.write("#define blabla 55", append="top")
    c_file.write("someglobal = blabla", append="bottom")

    This is working, but the python code is quite difficult to maintain, there's a lot of escaping going on, it's almost impossible to see the structure of the c files unless generating one and hopping it's successful. It's also quite difficult to insert code exactly where you want, because you do not know the order in which the xml trees are defined then parsed.

    I was just wondering if a template engine would help. Maybe not.

    JM
     
    Jean-Michel Pichavant, Oct 10, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    4
    Views:
    755
    Nevyn Twyll
    Mar 6, 2004
  2. =?Utf-8?B?Y25pY2ts?=

    Generating HTML code

    =?Utf-8?B?Y25pY2ts?=, Mar 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    437
    Kevin Spencer
    Mar 22, 2005
  3. Naveen K Kohli

    td tag generating faulty code

    Naveen K Kohli, May 13, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    467
    David Lloyd
    May 13, 2005
  4. Generating HTML code in the code-behind

    , Aug 25, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    162
    jjrdk
    Sep 25, 2005
  5. Generating HTML code in the code-behind

    , Aug 25, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    169
    jjrdk
    Sep 25, 2005
Loading...

Share This Page