More type stuff. Almost working.
This commit is contained in:
parent
1307bbdfcc
commit
bec0cdce84
|
@ -15,6 +15,7 @@ xHFILES = \
|
||||||
|
|
||||||
OFILES = \
|
OFILES = \
|
||||||
$(baseCFILES:%.c=$(OBJDIR)/%.o) \
|
$(baseCFILES:%.c=$(OBJDIR)/%.o) \
|
||||||
|
$(IDLFILES:%.idl=$(OBJDIR)/z%typefuncs.o) \
|
||||||
$(baseMFILES:%.m=$(OBJDIR)/%.o)
|
$(baseMFILES:%.m=$(OBJDIR)/%.o)
|
||||||
|
|
||||||
xCFLAGS = \
|
xCFLAGS = \
|
||||||
|
@ -59,6 +60,11 @@ $(OUTDIR)/%.h: %.idl tools/idl2h.go | $(OUTDIR)/.phony
|
||||||
@echo ====== Generated `basename $@`
|
@echo ====== Generated `basename $@`
|
||||||
.PRECIOUS: $(OUTDIR)/%.h
|
.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:
|
clean:
|
||||||
rm -rf $(OUTDIR) $(OBJDIR) ui.h
|
rm -rf $(OUTDIR) $(OBJDIR) z*
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|
|
@ -28,6 +28,7 @@ baseCFILES = \
|
||||||
box.c \
|
box.c \
|
||||||
ptrarray.c \
|
ptrarray.c \
|
||||||
shouldquit.c \
|
shouldquit.c \
|
||||||
|
types.c \
|
||||||
$(osCFILES)
|
$(osCFILES)
|
||||||
|
|
||||||
baseMFILES = $(osMFILES)
|
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()");
|
complain("invalid type ID given to uiIsA()");
|
||||||
t = (uiTyped *) p;
|
t = (uiTyped *) p;
|
||||||
compareTo = t->Type;
|
compareTo = t->Type;
|
||||||
|
if (compareTo == 0)
|
||||||
|
complain("object %p has no type in uiIsA()", t);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (compareTo == 0 || compareTo >= types->len)
|
if (compareTo >= types->len)
|
||||||
complain("invalid type ID in uiIsA()", t);
|
complain("invalid type ID in uiIsA()", t);
|
||||||
if (compareTo == id)
|
if (compareTo == id)
|
||||||
return t;
|
return t;
|
||||||
|
@ -46,7 +48,7 @@ void *uiIsA(void *p, uintmax_t id, int fail)
|
||||||
compareTo = ti->parent;
|
compareTo = ti->parent;
|
||||||
}
|
}
|
||||||
if (fail) {
|
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);
|
complain("object %p not a %s in uiIsA()", t, ti->name);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -28,8 +28,8 @@ func OnShouldQuit(f *func(data *void) int, data *void);
|
||||||
|
|
||||||
func FreeText(text *char);
|
func FreeText(text *char);
|
||||||
|
|
||||||
func RegisterType(name *const char, parent uintmax_t);
|
func RegisterType(name *const char, parent uintmax_t) uintmax_t;
|
||||||
func IsA(p *void, type uintmax_t, fail int);
|
func IsA(p *void, type uintmax_t, fail int) *void;
|
||||||
struct Typed {
|
struct Typed {
|
||||||
field Type uintmax_t;
|
field Type uintmax_t;
|
||||||
};
|
};
|
||||||
|
|
|
@ -161,6 +161,7 @@ static uiMenuItem *newItem(struct menu *m, int type, const char *name)
|
||||||
if (item->type == typeQuit)
|
if (item->type == typeQuit)
|
||||||
item->onClicked = onQuitClicked;
|
item->onClicked = onQuitClicked;
|
||||||
|
|
||||||
|
uiMenuItem(item)->Type = uiTypeMenuItem();
|
||||||
uiMenuItem(item)->Enable = menuItemEnable;
|
uiMenuItem(item)->Enable = menuItemEnable;
|
||||||
uiMenuItem(item)->Disable = menuItemDisable;
|
uiMenuItem(item)->Disable = menuItemDisable;
|
||||||
uiMenuItem(item)->OnClicked = menuItemOnClicked;
|
uiMenuItem(item)->OnClicked = menuItemOnClicked;
|
||||||
|
@ -229,6 +230,7 @@ uiMenu *uiNewMenu(const char *name)
|
||||||
|
|
||||||
m->name = toUTF16(name);
|
m->name = toUTF16(name);
|
||||||
|
|
||||||
|
uiMenu(m)->Type = uiTypeMenu();
|
||||||
uiMenu(m)->AppendItem = menuAppendItem;
|
uiMenu(m)->AppendItem = menuAppendItem;
|
||||||
uiMenu(m)->AppendCheckItem = menuAppendCheckItem;
|
uiMenu(m)->AppendCheckItem = menuAppendCheckItem;
|
||||||
uiMenu(m)->AppendQuitItem = menuAppendQuitItem;
|
uiMenu(m)->AppendQuitItem = menuAppendQuitItem;
|
||||||
|
|
Loading…
Reference in New Issue