Code generation with Xtend

55 views
Skip to first unread message

Hemal Bavishi

unread,
Jan 19, 2017, 2:36:14 AM1/19/17
to Xtend Programming Language
Hello,

I've developed Xtend based code generator which generates "C" code. I've come across one requirement wherein user wants to edit generated "C" source code between "User Start Code" and "User End Code" and later synchronize with code generator such that code generator shouldn't overwrite the manually edited code. I am just wondering what would be the easiest way to handle such requirement using Xtend?  

Example 

1. Generated output using Code Generator:

void Runnable(void) 
{

int x;
int y;

/* User Start Code: */

/* User End Code: */

test_data (x, y);

/* User Start Code: */

/* User End Code: */
}


2.  User edited generated output

void Runnable(void) 
{

int x;
int y;

/* User Start Code: */
x= 20;
y = 20;
/* User End Code: */

test_data (&x, &y);

/* User Start Code: */
if(x!=y) test_data(&x, &y);
/* User End Code: */
}

3. Expected output when Code Generation tool executes the program again with updated xml file which also invoke calculate_data(x,y) in the Runnable. 

void Runnable(void) 
{

int x;
int y;

/* User Start Code: */
x= 20;
y = 20;
/* User End Code: */

test_data (&x, &y);

calculate_data(x, y);

/* User Start Code: */
if(x!=y) test_data(&x, &y);
/* User End Code: */
}

Jan Köhnlein

unread,
Jan 19, 2017, 2:41:38 AM1/19/17
to xtend...@googlegroups.com
What you are heading for is called protected regions.
It's is a strongly discouraged anti-pattern, as maintaining mixed generated/manually sooner or later results in big problems.
There have been third party attempts to implement that for Xtend, namely by Daniel Dietrich (https://github.com/danieldietrich/xtext-protected-regions). I don't know about the state of this.

Isn't there a way to use includes or extract the manually written parts in functions that can be maintained in a separate source folder?

Best regards
Jan

--
Dr. Jan Köhnlein
jan.ko...@typefox.io

TypeFox GmbH
Am Germaniahafen 1
24143 Kiel

Phone: +49 151 17396687
Skype: jankoehnlein
Twitter: jankoehnlein

Sitz: Kiel, Registergericht: Amtsgericht Kiel, HRB 17385
Geschäftsführer: Sven Efftinge, Moritz Eysholdt, Dr. Jan Köhnlein
> --
> You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages