*/
void newfunc(void) {
char n[NAMESIZE];
- int idx, type;
+ int type;
fexitlab = getlabel();
if (!symname(n)) {
do_kill();
return;
}
+ if (!match("("))
+ error("missing open paren");
+ newfunc_typed(PUBLIC, n, CINT);
+}
+
+void newfunc_typed(int storage, char *n, int type)
+{
+ int idx;
+ /* TODO: external storage */
+ if (storage == EXTERN)
+ error("not yet supported");
if ((idx = find_global(n)) > -1) {
if (symbol_table[idx].identity != FUNCTION)
multidef(n);
else
symbol_table[idx].offset = FUNCTION;
} else
- add_global(n, FUNCTION, CINT, FUNCTION, PUBLIC);
- if (!match("("))
- error("missing open paren");
+ add_global(n, FUNCTION, CINT, FUNCTION, storage);
output_string(n);
output_label_terminator();
newline();
int otag; // tag of struct object being declared
int sflag; // TRUE for struct definition, zero for union
char sname[NAMESIZE];
+ int ns = 0;
blanks();
if ((sflag=amatch("struct", 6)) || amatch("union", 5)) {
}
declare_global(STRUCT, stclass, mtag, otag, is_struct);
} else if ((type = get_type()) != 0) {
- declare_global(type, stclass, mtag, 0, is_struct);
+ ns = declare_global(type, stclass, mtag, 0, is_struct);
} else if (stclass == PUBLIC) {
return (0);
} else {
- declare_global(CINT, stclass, mtag, 0, is_struct);
+ ns = declare_global(CINT, stclass, mtag, 0, is_struct);
}
- need_semicolon();
+ if (!ns)
+ need_semicolon();
return (1);
}
extern int hier10(LVALUE *lval);
extern int hier11(LVALUE *lval);
extern void newfunc(void);
+extern void newfunc_typed(int storage, char *n, int type);
extern void getarg(int t);
extern int doAnsiArguments(void);
extern void doLocalAnsiArgument(int type);
extern SYMBOL *find_member(TAG_SYMBOL *tag, char *sname);
extern void add_member(char *sname, char identity, char type, int offset, int storage_class);
extern int define_struct(char *sname, int storage, int is_struct);
-extern void declare_global(int type, int storage, TAG_SYMBOL *mtag, int otag, int is_struct);
+extern int declare_global(int type, int storage, TAG_SYMBOL *mtag, int otag, int is_struct);
extern int initials(char *symbol_name, int type, int identity, int dim, int otag);
extern void struct_init(TAG_SYMBOL *tag, char *symbol_name);
extern int init(char *symbol_name, int type, int identity, int *dim, TAG_SYMBOL *tag);
* @param mtag tag of struct whose members are being declared, or zero
* @param otag tag of struct object being declared. only matters if mtag is non-zero
* @param is_struct struct or union or no meaning
- * @return
+ * @return 1 if a function was parsed
*/
-void declare_global(int type, int storage, TAG_SYMBOL *mtag, int otag, int is_struct) {
+int declare_global(int type, int storage, TAG_SYMBOL *mtag, int otag, int is_struct) {
int dim, identity;
char sname[NAMESIZE];
FOREVER {
FOREVER {
if (endst ())
- return;
+ return 0;
dim = 1;
if (match ("*")) {
identity = POINTER;
illname ();
if (find_global (sname) > -1)
multidef (sname);
+ if (match ("(")) {
+ /* FIXME: We need to deal with pointer types properly here */
+ newfunc_typed(storage, sname, type);
+ /* Can't int foo(x){blah),a=4; */
+ return 1;
+ }
if (match ("[")) {
dim = needsub ();
//if (dim || storage == EXTERN) {
}
}
if (!match (","))
- return;
+ return 0;
}
}