Back to index

plt-scheme  4.2.1
Defines | Functions
generateh.c File Reference
#include <config.h>
#include <stdio.h>
#include <libit/unistd.h>
#include <libit/string.h>
#include <libit/ctype.h>
#include <wbuild.h>
#include <wsym.h>
#include <libintl.h>
#include <libit/malloc.h>

Go to the source code of this file.

Defines

#define fputS(s, f)   fputs(get(s), f)
#define _(String)   gettext(String)

Functions

static void public_include (FILE *f, Class c, char *prefix, char *private)
static void declare_export_type (FILE *f, Section s)
static void define_macro (FILE *f, Class c, Decl d)
static void declare_export_var (FILE *f, Section s)
static void define_resource_symbols (FILE *f, Class c)
static void define_constraint_resource_symbols (FILE *f, Class c)
static void typedef_class_instance (FILE *f, Class c)
static void declare_exports (FILE *f, Class c)
void public_header (FILE *f, Class c, char *prefix, char *guard)
static void generate_macro_loop (FILE *f, Class c, Section s)
static void generate_macro (FILE *f, Class c)
static void generate_typedefs (FILE *f, Class c)
static void generate_inherit_defines (FILE *f, Class c)
static void generate_constraint_part_record (FILE *f, Class c)
static void declare_super_constraint_parts (FILE *f, Class c)
static void generate_constraint_rec (FILE *f, Class c)
static void generate_class_part_rec (FILE *f, Class c)
static void declare_superclassparts (FILE *f, Class c)
static void generate_class_rec (FILE *f, Class c)
static void generate_instance_part_rec (FILE *f, Class c)
static void declare_superparts (FILE *f, Class c)
static void generate_complete_instance_part_rec (FILE *f, Class c)
static void generate_extern_decl_class_rec (FILE *f, Class c)
void generate_private_header (FILE *f, Class c, char *prefix, char *guard)

Define Documentation

#define _ (   String)    gettext(String)

Definition at line 37 of file generateh.c.

#define fputS (   s,
 
)    fputs(get(s), f)

Definition at line 25 of file generateh.c.


Function Documentation

static void declare_export_type ( FILE *  f,
Section  s 
) [inline, static]

Definition at line 125 of file generateh.c.

{
       fputs("typedef ", f);
       fputS(s->decl->type, f);
       putc(' ', f);
       fputS(s->decl->name, f);
       fputs(";\n\n", f);
}

Here is the caller graph for this function:

static void declare_export_var ( FILE *  f,
Section  s 
) [inline, static]

Definition at line 155 of file generateh.c.

{
       fputS(s->decl->type, f);
       putc(' ', f);
       fputS(s->decl->name, f);
       if (s->decl->suffix)
              fputS(s->decl->suffix, f);
       fputs(";\n\n", f);
}

Here is the caller graph for this function:

static void declare_exports ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 274 of file generateh.c.

{
       Section s;

       for (s = c->exports; s; s = s->next) {
              if (s->decl) {
                     switch (s->decl->tp) {
                            case Var: declare_export_var(f, s); break;
                            case Def: define_macro(f, c, s->decl); break;
                            case Proc: declare_function(1, s->decl->name,
                                   s->decl, f); break;
                            case Type: declare_export_type(f, s); break;
                            case Incl:
                                   fprintf(f, "#include %s\n",
                                          get(s->decl->name));
                                   break;
                            case Undefined: break;
                            case Trans: break;
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void declare_super_constraint_parts ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 536 of file generateh.c.

{
       if (c != NULL) {
              if (c->super && c->superclass != CONSTRAINT)
                     declare_super_constraint_parts(f, c->super);
              fprintf(f, "%sConstraintPart %s;\n",
                     get(c->name), get(get_instname(c->name)));
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void declare_superclassparts ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 629 of file generateh.c.

{
       if (!c)
              return;
       if (c->name == OBJECT || c->name == RECTOBJ) {
              fprintf(f, "%sClassPart object_class;\n", get(c->name));
       } else {
              declare_superclassparts(f, c->super);
              fprintf(f, "%sClassPart %s_class;\n", get(c->name),
              get(get_instname(c->name)));
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void declare_superparts ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 723 of file generateh.c.

{
       if (!c)
              return;
       if (c->super)
              declare_superparts(f, c->super);
       fprintf(f, "%sPart %s;\n",
       get(c->name), get(get_instname(c->name)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void define_constraint_resource_symbols ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 221 of file generateh.c.

{
       STRING hi, hc, ht;
       Section s;

       for (s = c->constraints; s; s = s->next) {
              if (s->decl == NULL || s->decl->tp != Var)
                     continue;
              if (find_constr_class(c, s->decl->name) != c)
                     continue;
              if (s->decl->typesym)
                     ht = hdup(s->decl->typesym);
              else if (!s->decl->type) {
                     fprintf(stderr, _("%s:%d: Missing type for `%s'\n"),
                            get(c->filename), s->decl->lineno,
                            get(s->decl->name));
                     nerrors++;
                     continue;      
              } else {
                     ht = get_word(get(get_classname(s->decl->type)));
              }
              if (s->decl->namesym) {
                     hi = get_instname(s->decl->namesym);
                     hc = get_classname(s->decl->namesym);
              } else {
                     hi = get_instname(s->decl->name);
                     hc = get_classname(s->decl->name);
              }
              fprintf(f, "#ifndef XtN%s\n", get(hi));
              fprintf(f, "#define XtN%s \"%s\"\n", get(hi), get(hi));
              fprintf(f, "#endif\n");
              fprintf(f, "#ifndef XtC%s\n", get(hc));
              fprintf(f, "#define XtC%s \"%s\"\n", get(hc), get(hc));
              fprintf(f, "#endif\n");
              fprintf(f, "#ifndef XtR%s\n", get(ht));
              fprintf(f, "#define XtR%s \"%s\"\n", get(ht), get(ht));
              fprintf(f, "#endif\n\n");
              delete(hi);
              delete(hc);
              delete(ht);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void define_macro ( FILE *  f,
Class  c,
Decl  d 
) [static]

Definition at line 135 of file generateh.c.

{
       Decl d1;

       fputs("#define ", f);
       fputS(d->name, f);
       if (d->params) {
              putc('(', f);
              for (d1 = d->params; d1; d1 = d1->next) {
                     fputS(d1->name, f);
                     if (d1->next)
                            fputs(", ", f);
              }
              putc(')', f);
       }
       putc(' ', f);
       print_body(f, d->body, c, d->name, d->lineno, 1);
       fputs("\n\n", f);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void define_resource_symbols ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 171 of file generateh.c.

{
       STRING hi, hc, ht;
       Section s;

       for (s = c->publicvars; s; s = s->next) {
              if (s->decl == NULL || s->decl->tp != Var)
                     continue;
              if (find_instvar_class(c, s->decl->name) != c)
                     continue;
              if (s->decl->typesym) {
                     ht = hdup(s->decl->typesym);
              } else if (!s->decl->type) {
                     fprintf(stderr, _("%s:%d: Missing type for `%s'\n"),
                            get(c->filename), s->decl->lineno,
                            get(s->decl->name));
                     nerrors++;
                     continue;      
              } else {
                     ht = get_word(get(get_classname(s->decl->type)));
              }
              if (s->decl->namesym) {
                     hi = get_instname(s->decl->namesym);
                     hc = get_classname(s->decl->namesym);
              } else {
                     hi = get_instname(s->decl->name);
                     hc = get_classname(s->decl->name);
              }
              fprintf(f, "#ifndef XtN%s\n", get(hi));
              fprintf(f, "#define XtN%s \"%s\"\n", get(hi), get(hi));
              fprintf(f, "#endif\n");
              fprintf(f, "#ifndef XtC%s\n", get(hc));
              fprintf(f, "#define XtC%s \"%s\"\n", get(hc), get(hc));
              fprintf(f, "#endif\n");
              fprintf(f, "#ifndef XtR%s\n", get(ht));
              fprintf(f, "#define XtR%s \"%s\"\n", get(ht), get(ht));
              fprintf(f, "#endif\n\n");
              delete(hi);
              delete(hc);
              delete(ht);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_class_part_rec ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 568 of file generateh.c.

{
       int n;
       Section s;

       n = 0;
       fprintf(f, "\ntypedef struct {\n/* methods */\n");
       for (s = c->methods; s; s = s->next) {
              if (s->decl && (s->decl->tp == Proc)) {
                     if (s->decl->class_id
                            && s->decl->class_id != DOLLAR)
                            /* Inherited */
                            continue;
                     if (!s->decl->class_id
                            && find_method_class(c, s->decl->name) != c)
                            /* Inherited */
                            continue;
                     fprintf(f, "%s_Proc %s;\n",
                            get(s->decl->name), get(s->decl->name));
                     n++;
              }
       }
       fprintf(f, "/* class variables */\n");
       for (s = c->classvars; s; s = s->next) {
              if (s->decl && (s->decl->tp)) {
                     if (s->decl->class_id
                            && s->decl->class_id != DOLLAR)
                            /* Inherited */
                            continue;
                     if (!s->decl->class_id
                            && find_classvar_class(c,s->decl->name)!=c)
                            /* Inherited */
                            continue;
                     fprintf(f, "%s %s", get(s->decl->type),
                            get(s->decl->name));
                     if (s->decl->suffix)
                            fputS(s->decl->suffix, f);
                     fputs(";\n", f);
                     n++;
              }
       }
       if (n == 0)
              fprintf(f, "int dummy;\n");
       fprintf(f, "} %sClassPart;\n", get(c->name));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_class_rec ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 642 of file generateh.c.

{
       fprintf(f, "\ntypedef struct _%sClassRec {\n", get(c->name));
       declare_superclassparts(f, c);
       fprintf(f, "} %sClassRec;\n\n", get(c->name));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_complete_instance_part_rec ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 733 of file generateh.c.

{
       fprintf(f, "typedef struct _%sRec {\n", get(c->name));
       declare_superparts(f, c);
       fprintf(f, "} %sRec;\n\n", get(c->name));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_constraint_part_record ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 486 of file generateh.c.

{
       int n;
       Section s;

       fprintf(f, "typedef struct {\n");
       n = 0;
       fprintf(f, "/* Constraint resources */\n");
       for (s = c->constraints; s; s = s->next) {
              if (s->decl && s->decl->tp == Var) {
                     if (s->decl->class_id
                            && s->decl->class_id != DOLLAR)
                            /* Inherited */
                            continue;
                     if (!s->decl->class_id
                            && find_constr_class(c,s->decl->name) != c)
                            /* Inherited */
                            continue;
                     fprintf(f, "%s %s", get(s->decl->type),
                            get(s->decl->name));
                     if (s->decl->suffix)
                            fputS(s->decl->suffix, f);
                     fputs(";\n", f);
                     n++;
              }
       }
       fprintf(f, "/* Private constraint variables */\n");
       for (s = c->privconstr; s; s = s->next) {
              if (s->decl == NULL)
                     continue;
              if (s->decl->tp == Var) {
                     if (s->decl->class_id && (s->decl->class_id != DOLLAR))
                            /* Inherited */
                            continue;
                     if (!s->decl->class_id
                            && find_constr_class(c,s->decl->name) != c)
                            /* Inherited */
                            continue;
                     fprintf(f, "%s %s", get(s->decl->type), get(s->decl->name));
                     if (s->decl->suffix)
                            fputS(s->decl->suffix, f);
                     fputs(";\n", f);
                     n++;
              }
       }
       if (n == 0)
              fprintf(f, "int dummy;\n");
       fprintf(f, "} %sConstraintPart;\n\n", get(c->name));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_constraint_rec ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 546 of file generateh.c.

{
       fprintf(f, "typedef struct _%sConstraintRec {\n", get(c->name));
       declare_super_constraint_parts(f, c);
       fprintf(f, "} %sConstraintRec;\n\n", get(c->name));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_extern_decl_class_rec ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 740 of file generateh.c.

{
       fprintf(f, "externalref %sClassRec %sClassRec;\n\n",
              get(c->name), get(get_instname(c->name)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_inherit_defines ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 425 of file generateh.c.

{
       Section s;
       Decl d1;

       for (s = c->methods; s; s = s->next) {
              if (!s->decl || s->decl->tp != Proc)
                     /* No decl in this section */
                     continue;
              if (s->decl->class_id && s->decl->class_id != DOLLAR) 
                     /* Inherited method */
                     continue;
              if (!s->decl->class_id
                            && find_method_class(c, s->decl->name) != c)
                     /* Inherited method */
                     continue;
              fprintf(f, "typedef %s (*%s_Proc)(\n",
                     s->decl->type ? get(s->decl->type) : "void",
                     get(s->decl->name));
              fprintf(f, "#if NeedFunctionPrototypes\n");
              if (s->decl->params == NULL) {
                     fputs("void", f);
              } else {
                     for (d1 = s->decl->params; d1; d1 = d1->next) {
                            if (d1->name == DOLLAR)
                                   fputs("Widget", f);
                            else
                                   fputS(d1->type, f);
                            if (d1->suffix)
                                   /* An array? */
                                   fprintf(f, " %s%s", get(d1->name),
                                          get(d1->suffix));
                            if (d1->next)
                                   putc(',', f);
                     }
              }
              fprintf(f, "\n#endif\n);\n");
              fprintf(f, "#define XtInherit_%s ((%s_Proc) _XtInherit)\n",
              get(s->decl->name), get(s->decl->name));
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_instance_part_rec ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 665 of file generateh.c.

{
       int n;
       Section s;

       fprintf(f, "typedef struct {\n");
       n = 0;
       fprintf(f, "/* resources */\n");
       for (s = c->publicvars; s; s = s->next) {
              if (s->decl && (s->decl->tp == Var)) {
                     if (s->decl->class_id
                            && s->decl->class_id != DOLLAR)
                            /* Inherited */
                            continue;
                     if (!s->decl->class_id
                            && find_instvar_class(c, s->decl->name) != c)
                            /* Inherited */
                            continue;
                     fprintf(f, "%s %s", get(s->decl->type),
                            get(s->decl->name));
                     if (s->decl->suffix)
                            fputS(s->decl->suffix, f);
                     fputs(";\n", f);
                     n++;
              }
       }
       fprintf(f, "/* private state */\n");
       for (s = c->privatevars; s; s = s->next) {
              if (s->decl && (s->decl->tp == Var)) {
                     if (s->decl->class_id
                            && s->decl->class_id != DOLLAR)
                            /* Inherited */
                            continue;
                     if (!s->decl->class_id
                            && find_instvar_class(c,s->decl->name) != c)
                            /* Inherited */
                            continue;
                     if (!s->decl->type) {
                            nerrors++;
                            fprintf(stderr,
                                   _("%s:%d: Missing type for `%s'\n"),
                                   get(c->filename), s->decl->lineno,
                                   get(s->decl->name));
                            continue;
                     }
                     fprintf(f, "%s %s", get(s->decl->type),
                            get(s->decl->name));
                     if (s->decl->suffix)
                            fputS(s->decl->suffix, f);
                     fputs(";\n", f);
                     n++;
              }
       }
       if (n == 0)
              fprintf(f, "int dummy;\n");
       fprintf(f, "} %sPart;\n\n", get(c->name));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_macro ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 382 of file generateh.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_macro_loop ( FILE *  f,
Class  c,
Section  s 
) [inline, static]

Definition at line 373 of file generateh.c.

{
       while (s) {
              if ((s->decl) && (s->decl->tp == Def))
                     define_macro(f, c, s->decl);
              s = s->next;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void generate_private_header ( FILE *  f,
Class  c,
char *  prefix,
char *  guard 
)

Definition at line 746 of file generateh.c.

{
       wbuild_comment(f);
       fprintf(f, "#ifndef %s\n", guard);
       fprintf(f, "#define %s\n", guard);
       public_include(f, c, prefix, "P");
       fprintf(f, "#include <%s/%s.h>\n", prefix,
              get(c->filenamepart ? c->filenamepart : c->name));
       fputs("_XFUNCPROTOBEGIN\n", f);
       generate_macro(f, c);
       generate_typedefs(f, c);
       generate_inherit_defines(f, c);
       if (find_superclass(c, CONSTRAINT) != NULL) {
              generate_constraint_part_record(f, c);
              generate_constraint_rec(f, c);
       }
       generate_class_part_rec(f, c);
       generate_class_rec(f, c);
       generate_instance_part_rec(f, c);
       generate_complete_instance_part_rec(f, c);
       generate_extern_decl_class_rec(f, c);
       fputs("_XFUNCPROTOEND\n", f);
       fprintf(f, "#endif /* %s */\n", guard);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void generate_typedefs ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 396 of file generateh.c.

{
       Section s;

       for (s = c->classvars; s; s = s->next)
              if ((s->decl) && (s->decl->tp == Type))
                     fprintf(f, "typedef %s %s;\n",
                            get(s->decl->type), get(s->decl->name));
       for (s = c->privatevars; s; s = s->next)
              if ((s->decl) && (s->decl->tp == Type))
                     fprintf(f, "typedef %s %s;\n",
                            get(s->decl->type), get(s->decl->name));
}

Here is the caller graph for this function:

void public_header ( FILE *  f,
Class  c,
char *  prefix,
char *  guard 
)

Definition at line 297 of file generateh.c.

{
       wbuild_comment(f);
       fprintf(f, "#ifndef %s\n", guard);
       fprintf(f, "#define %s\n", guard);
       public_include(f, c, prefix, "");
       fputs("_XFUNCPROTOBEGIN\n", f);
       declare_exports(f, c);
       define_resource_symbols(f, c);
       define_constraint_resource_symbols(f, c);
       typedef_class_instance(f, c);
       fputs("_XFUNCPROTOEND\n", f);
       fprintf(f, "#endif /* %s */\n", guard);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void public_include ( FILE *  f,
Class  c,
char *  prefix,
char *  private 
) [inline, static]

Definition at line 61 of file generateh.c.

{
       char *s, *slash;

       if (c->super && c->super->filenamepart)
              s = get(c->super->filenamepart);
       else
              s = get(c->superclass);

       slash = strchr(s, '/');
       if (slash) {
              fprintf(f, "#include <%s%s.h>\n", s, private);
       } else {
              fprintf(f, "#include <%s/%s%s.h>\n", prefix, s, private);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void typedef_class_instance ( FILE *  f,
Class  c 
) [inline, static]

Definition at line 264 of file generateh.c.

{
       fprintf(f, "typedef struct _%sClassRec *%sWidgetClass;\n",
              get(c->name), get(c->name));
       fprintf(f, "typedef struct _%sRec *%sWidget;\n",
              get(c->name), get(c->name));
       fprintf(f, "externalref WidgetClass %sWidgetClass;\n",
              get(get_instname(c->name)));
}

Here is the call graph for this function:

Here is the caller graph for this function: