Back to index

plt-scheme  4.2.1
wbuild.h
Go to the documentation of this file.
00001 /*   wbuild
00002      Copyright (C) 1996  Joel N. Weber II <nemo@koa.iolani.honolulu.hi.us>
00003      
00004      This program is free software; you can redistribute it and/or
00005      modify it under the terms of the GNU General Public License
00006      as published by the Free Software Foundation; either version 2
00007      of the License, or (at your option) any later version.
00008      
00009      This program is distributed in the hope that it will be useful,
00010      but WITHOUT ANY WARRANTY; without even the implied warranty of
00011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012      GNU General Public License for more details.
00013      
00014      You should have received a copy of the GNU General Public License
00015      along with this program; if not, write to the Free Software
00016      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 /* time_t is needed below, so include the appropriate headers here */
00020 
00021 #if TIME_WITH_SYS_TIME
00022 # include <sys/time.h>
00023 # include <time.h>
00024 #else
00025 # if HAVE_SYS_TIME_H
00026 #  include <sys/time.h>
00027 # else
00028 #  include <time.h>
00029 # endif
00030 #endif
00031 
00032 /* Types and constants. A number of types are defined here that are
00033  * also used by the parser to store the `parse tree' in. |Class| is a
00034  * structure that holds all the available information about a single
00035  * class. Classes are linked into a list. A |Section| is a structure that
00036  * holds information about a `section' of a class, i.e., tex plus macros
00037  * plus a piece of C code.  A |Decl| holds information about a single
00038  * variable declaration, typedef, function, etc.
00039  *
00040  * A |STRING| is an opaque type, implemented in `util' as a pointer in a
00041  * string buffer (see the module `util').
00042  */
00043 
00044 typedef struct _STRING {
00045        char *s;
00046        int linkcount;
00047        struct _STRING *next;
00048 } *STRING;
00049 
00050 
00051 /* The |Decl| type contains a variable declaration, a typedef, a
00052  * procedure, etc. The fields are used in different ways for different
00053  * types of declarations. |tp| is always used, and so is |lineno|.
00054  *
00055  * In the section for the public instance variables, |tp| is always
00056  * |Var|, |type| holds the type of the variable, |name| holds the name
00057  * and |value| holds the default value. These fields should not be empty.
00058  * The |suffix| optionally holds a suffix like |[4]|.  The |typesym|
00059  * field --- if not empty --- holds an identifier that will be used for
00060  * the symbolic name of the type. The generator will capitalize it and
00061  * prefix |XtR|. Similarly, |namesym| --- if not empty --- is used for
00062  * the symbolic name of the varaible, when used as a resource. |XtN| and
00063  * |XtC| will be prefixed to it. |valuesym| must be used if the initial
00064  * value (in |value|) needs to be converted. It contains the symbolic
00065  * name of the type of |value|, if that type is different from |type|.
00066  * The fields |params| and |body| are not used.
00067  *
00068  * E.g., the input
00069  * %
00070  * $$|@@var Pixel shadow_color = XtDefaultBackground|$$
00071  * %
00072  * will result in a resource wih symbolic names |XtNshadow_color| (|=
00073  * "shadow_color"|) and |XtCShadow_color| (|= "Shadow_color"|) and type
00074  * |XtRPixel| (|= "Pixel"|), but
00075  * %
00076  * $$|@@var <shadowColor> Pixel shadow_color <shadowColor>
00077  * = <String> "black"|$$
00078  * %
00079  * creates a resource with symbolic names |XtNshadowColor| and
00080  * |XtCShadowColor|. The default value will be converted from |XtRString|
00081  * to |XtRShadowColor|.
00082  *
00083  * The field |force_new| is set to |TRUE| if the name of the variable is
00084  * prefixed wit a `\$'. This means that the name should be declared in
00085  * this class, regardless of the existence of variables of the same name
00086  * in superclasses. If the \$ is omitted, the variable is only declared
00087  * if the name is not already in use.
00088  *
00089  * For class variables, the fields |type|, |name| |force_new| and |value|
00090  * should be non-empty and |tp| should be |Var|. |suffix| may hold an
00091  * array part. The other fields are not used.
00092  *
00093  * Methods use |type| (the function's return type), |name|, |force_new|,
00094  * |body| and |params|, but |params| may be left empty. If |type| is
00095  * empty, the generator will provide a return type of |void|. |tp| should
00096  * be |Proc|.
00097  *
00098  * Private variables have |tp = Var| and use |type|, |force_new| and
00099  * |name|. |suffix| is again optional.
00100  *
00101  * Exports may be variables (|tp = Var|), procedures (|tp = Proc|), type
00102  * definitions (|tp = Type|) and macro definitions (|tp = Def|).
00103  * Variables use |type|, |name| and optionally |suffix|; procedures use
00104  * |type| (may be empty), |name|, |params| (may be empty), and |body|;
00105  * type definitions use |name| and |type|; macros use |name|, |body| and
00106  * optionally |params|.
00107  *
00108  * Imports may be include files, variables or procedures. Include files
00109  * have |tp = Incl| and use only the |name| field.
00110  *
00111  * Utilities can be procedures, types, macros, or variables.
00112  *
00113  * The |next| field is only used when the |Decl| is used as a parameter
00114  * list in the field |params| of another |Decl|.
00115  */
00116 
00117 typedef enum {Undefined, Proc, Var, Type, Def, Incl, Trans} DeclTp;
00118 typedef struct _Decl {
00119        DeclTp tp;
00120        int lineno;
00121        STRING class_id;
00122        STRING typesym, type;
00123        STRING namesym, name;
00124        STRING suffix;
00125        STRING valuesym, value;
00126        struct _Decl *params;
00127        STRING body;
00128        struct _Decl *next;
00129 } *Decl;
00130 
00131 /* A |Section| contains a ``section'' of the spec file, i.e., from one
00132  * `@@' to the next, including a piece of text, some macros and a piece
00133  * of C code.
00134  */
00135 
00136 typedef struct _Section {
00137        STRING text;
00138        Decl decl;
00139        struct _Section *next;
00140 } *Section;
00141 
00142 /* A |Class| contains the complete information about a single class.
00143  * The |superclass| may be empty, but only for the X Toolkit's intrinsic
00144  * classes. The |options| contain directions for the generator, if the
00145  * class has special conventions, e.g., it doesn't produce any C files.
00146  */
00147 
00148 typedef struct _Class {
00149        int lineno; /* starting line of the class */
00150        STRING name, superclass, filename, filenamepart;
00151        STRING text; /* purpose of the class */
00152        Section classvars, publicvars, privatevars, methods, actions,
00153        translations, imports, exports, utilities,
00154        constraints, privconstr;
00155        int nodoc, nocode;
00156        struct _Class *daughters, *sister, *super; /* hierarchy */
00157        struct _Class *next; /* in spec file */
00158        time_t filetime;
00159 } *Class;
00160 
00161 
00162 typedef enum {
00163        t_start, t_class, t_name, t_name2, t_filename, t_superclass,
00164        t_publicvars,
00165        t_privatevars, t_actions, t_translations, t_exports, t_methods,
00166        t_imports, t_utilities, t_classvars, t_section, t_macro,
00167        t_publicvar, t_action, t_code,
00168        t_table, t_tablehead, t_row, t_resname, t_resclass, t_restype,
00169        t_resdefault, t_inline, t_underline, t_backslash, t_tilde,
00170        t_hashmark, t_dollar, t_less, t_greater,
00171        t_percent, t_caret, t_ampersand, t_lbrace, t_rbrace, t_bar, t_at,
00172        t_type, t_incl, t_constraints, t_constraint, t_privconstraints,
00173        t_privconstraint
00174 } tagtype;
00175 
00176 typedef char *tagpair[2];
00177 typedef char *taglist[t_privconstraint + 1][2];
00178 
00179 typedef struct _Doctype {
00180        int shortdoc;
00181        taglist tag;
00182        struct _Doctype *next;
00183 } *Doctype;
00184 
00185 /* Function prototypes
00186  */
00187 
00188 STRING hash(char *s);
00189 char *get(STRING s);
00190 STRING get_headerPname(char *dir, Class c);
00191 STRING get_classname(STRING s);
00192 STRING get_word(char *s);
00193 STRING get_instname(STRING s);
00194 Class find_instvar_class(Class c, STRING name);
00195 Section find_pubvar(Class c, STRING m);
00196 Section find_pubvar_back(Class c, STRING m);
00197 Class find_constr_class(Class c, STRING name);
00198 Section find_constraint(Class c, STRING m);
00199 Section find_method(Class c, STRING m);
00200 Class find_superclass(Class c, STRING name);
00201 Class find_method_class(Class c, STRING name);
00202 Class find_classvar_class(Class c, STRING name);
00203 int strneq(char *a, char *b, int n);
00204 size_t Strlen(STRING s);
00205 void delete(STRING s);
00206 int has_method(Class c, STRING m);
00207 STRING find_classvar_value(Class c, STRING name);
00208 STRING hdup(STRING s);
00209 void declare_function(int export, STRING name, Decl d, FILE *f);
00210 void wbuild_comment(FILE *f);
00211 void print_body(FILE *f, STRING body, Class class, STRING procname,
00212        int lineno, int ismacro);
00213 int set_hierarchy(void);
00214 void public_header(FILE *f, Class c, char *prefix, char *guard);
00215 void generate_private_header(FILE *f, Class c, char *prefix, char *guard);
00216 void symbol_init(void);
00217 void generatec(FILE *f, Class c, char *prefix, int lines);
00218 void generate_doc(FILE *f, tagpair *tag, Class c, int shortdoc);
00219 void add_class(Class c);
00220 void add_doctype(Doctype d);
00221 void copy_taglist(taglist *dest, taglist *src);
00222 void zero_taglist(taglist *dest);
00223 void set_doctag(taglist tag, char *name, char *open, char *close);
00224 
00225 
00226 #if HAVE_STDARG_H
00227 #ifdef __STDC__
00228 STRING catstr(int n,...);
00229 #else /* not __STDC__ */
00230 STRING catstr(n);
00231 #endif /* not __STDC__ */
00232 #else /* not HAVE_STDARG_H */
00233 STRING catstr(va_alist);
00234 #endif /* not HAVE_STDARG_H */
00235 
00236 
00237 
00238 #define lined(lineno, file)                                             \
00239        if (lines) fprintf(f, "#line %d \"%s\"\n", lineno, get(file))
00240 
00241 #define warn_if_params(params, filename, lineno, procname)            \
00242        if (params != NULL)                                     \
00243               nerrors++,                                       \
00244               fprintf(stderr,                                         \
00245                      _("%s:%d: Parameter list of `%s' ignored\n"),    \
00246                      get(filename), lineno, get(procname))
00247 
00248 
00249 extern int nerrors;
00250 extern Doctype doctypes;
00251 extern Class classes;
00252 extern int classnodoc, classnocode, doctypeshort;
00253 extern STRING classfilename, doctypeext, doctypedir;