cid-compiler 0.1 review

Download
by rbytes.net on

cid-compiler is a language tool to easily create C code with object oriented features

License: BSD License
File size: 98K
Developer: Markus W Weissmann
0 stars award from rbytes.net

cid-compiler is a language tool to easily create C code with object oriented features. It's compiler generates header (.h) files and implementations (.c) from a specification file (.i).

The generated C code consists of a struct, a opaque pointer to it (in the header file) and rewritten functions. The defined functions will get prefixed with the class name, they will also get a new first argument that is a pointer to the newly defined struct.

Functions that do not have a return value are considered constructors and will not get a new 1st argument but will automatically get a return value of pointer to the struct. The place between @class "name" and @attributes is e. g. for include statements and will make it into the header file.

To ease renaming the class, you can use the define CLASS, which will always be a define to a pointer of the new struct type.

Interface example

@class cstring
#include < stdio.h >
#include < string.h >
@attributes
char *c;
@methods
new(char *n) {
CLASS i = NEWCLASS;
i->c = strdup(n);
return i;
}
int length() {
return strlen(this->c);
}
@end

will yield a cstring.h file:
#ifndef _CSTRING_H_
#define _CSTRING_H_
#include < stdio.h >
#include < string.h >
typedef struct cstring *cstring;
cstring cstring_new(char *n);
int cstring_length(cstring this);
#endif

and a cstring.c file:
#include "cstring.h"
#define CLASS cstring
#define NEWCLASS malloc(sizeof(struct cstring));
#define NEWCLASS_M malloc(sizeof(struct cstring));
#define NEWCLASS_C calloc(1,sizeof(struct cstring));
struct cstring {
char *c;
};
cstring cstring_new(char *n) {
CLASS i = NEWCLASS;
i->c = strdup(n);
return i;
}
int cstring_length(cstring this) {
return strlen(this->c);
}

Issues:

The current compiler (v0.1) will reject quite some valid C code. Also the given error is not very helpful;

cid-compiler 0.1 search tags