# # The "class vector" is a list of static (read-only) class information. # Each class vector begins with a copy of its super-class class vector (if # any; e.g., class "object" has no super-class vector). The next two entries # identify the subclass by id and name, in case this class gets subclassed. # (If not, these just contain the current class id and name.) Finally, there # is one entry per method DEFINEd by this class. # # We keep track of a separate class value vector for each class. Initially, # it is the same as its superclass class value vector, with the addition of # a subclass id and name. For each method DEFINEd by the class, a new value # is added to the class value vector to point to the method implementation. # For each method IMPLEMENTed by the class, the value of the superclass # method is replaced in the class value vector. # # classes[i] name of ith class # do_class_c[i] was do_c in effect for ith class? # nclasses number of classes so far # super_names[i] name of super class of ith class (0 if none) # # class_vector[class i] ith class value for given class # method_name[class i] method name of ith class value for given class # method_number[class method] position of given method of given class # first[class] first class value that corresponds to class # nvalues[class] number of class values for given class # BEGIN { nclasses = 0 alpha = "abcdefghijklmnopqrstuvwxyz" ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" do_h = 0 do_c = 0 printf("/*\n") printf(" * Automatically generated - DO NOT EDIT!\n") printf(" */\n") printf("\n") nop = "_dxfno_" # prefix for unimplemented method names class_overhead = 2 # extra info per class vector structure root_overhead = 3 # additional extra info for root class # change this to non-zero to enable sizes # this is the number of entries in struct _root } /^#do_h$/ { do_h = 1 next } /^#do_c$/ { do_c = 1 next } /^INCLUDE/ { next } /^CLASS/ || /^SUBCLASS.* OF / { # # Which class we're defining # class = $2 do_class_c[nclasses] = do_c classes[nclasses] = class nclasses++ if (NF==4) super = $4; else super = 0 super_names[class] = super # # Compute upper and lower case versions of name # n = length(class); uc = lc = "" for (i=1; i<=n; i++) { c = substr(class, i, 1) uu = index(ALPHA, c) ll = index(alpha, c) if (ll) uc = uc substr(ALPHA, ll, 1); else uc = uc c if (uu) lc = lc substr(alpha, uu, 1); else lc = lc c } uc_names[class] = uc lc_names[class] = lc if (super) { # # copy superclass class vector, # f = first[class] = nvalues[super] for (i=0; isize)\n") printf("#define CLASS_CLASS(x) (((struct _root *)(x))->class)\n") printf("#define CLASS_NAME(x) (((struct _root *)(x))->name)\n") printf("\n"); } } # override size (part of root_overhead) if (root_overhead>0) { class_vector[class 0] = "sizeof(struct "lc")" class_vector[class 1] = "CLASS_"uc class_vector[class 2] = "\""lc"\"" } if (do_h) printf("\nextern struct %s_class _dxd%s_class;\n", lc, lc); next } /^IMPLEMENTS/ { for (i=2; i<=NF; i++) { # # Our class implements method given by $i itself # method = $i n = method_number[class method] class_vector[class n] = "_dxf" class "_" method if (do_h) { # # Declare our implementation # printf("%s _dxf%s_%s(", returns[method], class, method) na = nargs[method] # note we change type of first arg if (na>0) printf("%s", class) for (k=1; k0) printf("%s", argtype[method 0]) for (k=1; k0) printf("%s", argtype[method 0]) for (k=1; k0) printf(" struct _root root;\n") printf(" Class class;\n") printf(" char *name;\n") for (j=f; j0) printf("%s %s", argtype[method 0], substr(alpha,1,1)) for (k=1; kname;\n", lc_names[class]) printf(" DXSetError(ERROR_BAD_PARAMETER, \"#12130\", \"DX%s\", name);\n", method); printf(" return ERROR;\n") printf("}\n") printf("\n") } # # Create and initialize the class vector itself # printf("struct %s_class _dxd%s_class = {\n", lc, lc) for (j=0; j0) printf("%s %s", argtype[method 0], substr(alpha,1,1)) for (k=1; k%s(", lc, method) # note we change type of first arg if (na>0) printf("(%s)%s", class, substr(alpha,1,1)) for (k=1; kclass: CLASS_MIN;\n",\ lc) printf("}\n") printf("\n") } } }