Cid-compiler is a user-friendly tool for building object-oriented C code with ease.
With this tool, functions are defined and prefixed with the class name, while a new first argument (a pointer to the newly defined struct) is added. Constructors, considered functions with no return value, do not receive a new first argument but are automatically given a return value of a pointer to the struct.
The area between @class "name" and @attributes allows for the inclusion of statements, which will be compiled into the header file. An additional way to make class renaming easier is to use the define CLASS, which serves as a pointer to the new struct type.
For instance, the following interface example:
@class cstring
#include
#include
@attributes
char *c;
@methods
new(char *n)
{
CLASS i = NEWCLASS;
i->c = strdup(n);
return i;
}
int length()
{
return strlen(this->c);
}
@end
Will produce two files, namely cstring.h and cstring.c. The former will look like:
#ifndef _CSTRING_H_
#define _CSTRING_H_
#include
#include
typedef struct cstring *cstring;
cstring cstring_new(char *n);
int cstring_length(cstring this);
#endif
While the latter will look like:
#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);
}
One issue with the current compiler version (v0.1) is that it tends to reject valid C code. Additionally, the error messages it returns are not always helpful.
Version 0.1: N/A