More type stuff. Almost working.
This commit is contained in:
parent
1307bbdfcc
commit
bec0cdce84
|
@ -15,6 +15,7 @@ xHFILES = \
|
|||
|
||||
OFILES = \
|
||||
$(baseCFILES:%.c=$(OBJDIR)/%.o) \
|
||||
$(IDLFILES:%.idl=$(OBJDIR)/z%typefuncs.o) \
|
||||
$(baseMFILES:%.m=$(OBJDIR)/%.o)
|
||||
|
||||
xCFLAGS = \
|
||||
|
@ -59,6 +60,11 @@ $(OUTDIR)/%.h: %.idl tools/idl2h.go | $(OUTDIR)/.phony
|
|||
@echo ====== Generated `basename $@`
|
||||
.PRECIOUS: $(OUTDIR)/%.h
|
||||
|
||||
z%typefuncs.c: %.idl tools/idl2typefuncs.go
|
||||
@go run tools/idl2typefuncs.go out/ui.h < $< > $@
|
||||
@echo ====== Generated $@
|
||||
.PRECIOUS: z%typefuncs.c
|
||||
|
||||
clean:
|
||||
rm -rf $(OUTDIR) $(OBJDIR) ui.h
|
||||
rm -rf $(OUTDIR) $(OBJDIR) z*
|
||||
.PHONY: clean
|
||||
|
|
|
@ -28,6 +28,7 @@ baseCFILES = \
|
|||
box.c \
|
||||
ptrarray.c \
|
||||
shouldquit.c \
|
||||
types.c \
|
||||
$(osCFILES)
|
||||
|
||||
baseMFILES = $(osMFILES)
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
// 17 may 2015
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"flag"
|
||||
"github.com/andlabs/pgidl"
|
||||
)
|
||||
|
||||
func geniface(iface *pgidl.Interface, prefix string) {
|
||||
v := fmt.Sprintf("type%s%s", prefix, iface.Name)
|
||||
fmt.Printf("static uintmax_t %s = 0;\n", v)
|
||||
fmt.Printf("uintmax_t %sType%s(void)\n", prefix, iface.Name)
|
||||
fmt.Printf("{\n")
|
||||
fmt.Printf("\tif (%s == 0)\n", v)
|
||||
fmt.Printf("\t\t%s = %sRegisterType(%q, ",
|
||||
v,
|
||||
prefix,
|
||||
prefix + iface.Name)
|
||||
if iface.From != "" {
|
||||
fmt.Printf("%sType%s()", prefix, iface.From)
|
||||
} else {
|
||||
fmt.Printf("0")
|
||||
}
|
||||
fmt.Printf(");\n")
|
||||
fmt.Printf("\treturn %s;\n", v)
|
||||
fmt.Printf("}\n")
|
||||
}
|
||||
|
||||
func genpkg(p *pgidl.Package) {
|
||||
for _, o := range p.Order {
|
||||
switch o.Which {
|
||||
case pgidl.Interfaces:
|
||||
geniface(p.Interfaces[o.Index], p.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
idl, errs := pgidl.Parse(os.Stdin, "<stdin>")
|
||||
if len(errs) != 0 {
|
||||
for _, e := range errs {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", e)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("// generated by idl2h; do not edit\n")
|
||||
fmt.Printf("#include %q\n", os.Args[1])
|
||||
for _, p := range idl {
|
||||
genpkg(p)
|
||||
}
|
||||
}
|
|
@ -35,8 +35,10 @@ void *uiIsA(void *p, uintmax_t id, int fail)
|
|||
complain("invalid type ID given to uiIsA()");
|
||||
t = (uiTyped *) p;
|
||||
compareTo = t->Type;
|
||||
if (compareTo == 0)
|
||||
complain("object %p has no type in uiIsA()", t);
|
||||
for (;;) {
|
||||
if (compareTo == 0 || compareTo >= types->len)
|
||||
if (compareTo >= types->len)
|
||||
complain("invalid type ID in uiIsA()", t);
|
||||
if (compareTo == id)
|
||||
return t;
|
||||
|
@ -46,7 +48,7 @@ void *uiIsA(void *p, uintmax_t id, int fail)
|
|||
compareTo = ti->parent;
|
||||
}
|
||||
if (fail) {
|
||||
ti = ptrArrayIndex(types, struct typeInfo *, t->Type);
|
||||
ti = ptrArrayIndex(types, struct typeinfo *, t->Type);
|
||||
complain("object %p not a %s in uiIsA()", t, ti->name);
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
@ -28,8 +28,8 @@ func OnShouldQuit(f *func(data *void) int, data *void);
|
|||
|
||||
func FreeText(text *char);
|
||||
|
||||
func RegisterType(name *const char, parent uintmax_t);
|
||||
func IsA(p *void, type uintmax_t, fail int);
|
||||
func RegisterType(name *const char, parent uintmax_t) uintmax_t;
|
||||
func IsA(p *void, type uintmax_t, fail int) *void;
|
||||
struct Typed {
|
||||
field Type uintmax_t;
|
||||
};
|
||||
|
|
|
@ -161,6 +161,7 @@ static uiMenuItem *newItem(struct menu *m, int type, const char *name)
|
|||
if (item->type == typeQuit)
|
||||
item->onClicked = onQuitClicked;
|
||||
|
||||
uiMenuItem(item)->Type = uiTypeMenuItem();
|
||||
uiMenuItem(item)->Enable = menuItemEnable;
|
||||
uiMenuItem(item)->Disable = menuItemDisable;
|
||||
uiMenuItem(item)->OnClicked = menuItemOnClicked;
|
||||
|
@ -229,6 +230,7 @@ uiMenu *uiNewMenu(const char *name)
|
|||
|
||||
m->name = toUTF16(name);
|
||||
|
||||
uiMenu(m)->Type = uiTypeMenu();
|
||||
uiMenu(m)->AppendItem = menuAppendItem;
|
||||
uiMenu(m)->AppendCheckItem = menuAppendCheckItem;
|
||||
uiMenu(m)->AppendQuitItem = menuAppendQuitItem;
|
||||
|
|
Loading…
Reference in New Issue