Change some error names, mark a few things static that should be. Instead

of using a colon to specify a parent class in a GIB class definition,
"extends" is now used.  If no parent class is specified, it now defaults to
Object.
This commit is contained in:
Brian Koropoff 2003-11-29 02:01:31 +00:00
parent 82975dfe1f
commit 37a64e59ab
5 changed files with 53 additions and 34 deletions

View file

@ -178,7 +178,7 @@ extern char gib_null_string[];
#define GIB_Argd(x) ((x) < cbuf_active->args->argc ? cbuf_active->args->argv[(x)] : NULL) #define GIB_Argd(x) ((x) < cbuf_active->args->argc ? cbuf_active->args->argv[(x)] : NULL)
#define GIB_Argm(x) ((x) < cbuf_active->args->argc ? (gib_tree_t *)cbuf_active->args->argm[(x)] : NULL) #define GIB_Argm(x) ((x) < cbuf_active->args->argc ? (gib_tree_t *)cbuf_active->args->argm[(x)] : NULL)
#define GIB_USAGE(x) (GIB_Error ("syntax", "%s: invalid syntax\nusage: %s %s", GIB_Argv(0), GIB_Argv(0), (x))) #define GIB_USAGE(x) (GIB_Error ("SyntaxError", "%s: invalid syntax\nusage: %s %s", GIB_Argv(0), GIB_Argv(0), (x)))
#define GIB_CanReturn() (GIB_DATA(cbuf_active)->waitret) #define GIB_CanReturn() (GIB_DATA(cbuf_active)->waitret)

View file

@ -187,7 +187,7 @@ GIB_Function_f (void)
if (!(program = GIB_Parse_Lines (GIB_Argv if (!(program = GIB_Parse_Lines (GIB_Argv
(GIB_Argc()-1), 0))) { (GIB_Argc()-1), 0))) {
// Error! // Error!
GIB_Error ("parse", "Parse error while defining function '%s'.", GIB_Error ("ParseError", "Parse error while defining function '%s'.",
GIB_Argv (1)); GIB_Argv (1));
return; return;
} }
@ -394,11 +394,11 @@ GIB_Function_Export_f (void)
GIB_USAGE ("function1 [function2 function3 ...]"); GIB_USAGE ("function1 [function2 function3 ...]");
for (i = 1; i < GIB_Argc (); i++) { for (i = 1; i < GIB_Argc (); i++) {
if (!(f = GIB_Function_Find (GIB_Argv (i)))) if (!(f = GIB_Function_Find (GIB_Argv (i))))
GIB_Error ("function", "%s: function '%s' not found.", GIB_Argv (0), GIB_Error ("UnknownFunctionError", "%s: function '%s' not found.", GIB_Argv (0),
GIB_Argv (i)); GIB_Argv (i));
else if (!f->exported) { else if (!f->exported) {
if (Cmd_Exists (f->name)) { if (Cmd_Exists (f->name)) {
GIB_Error ("export", GIB_Error ("NameConflictError",
"%s: A console command with the name '%s' already exists.", "%s: A console command with the name '%s' already exists.",
GIB_Argv (0), GIB_Argv (i)); GIB_Argv (0), GIB_Argv (i));
return; return;
@ -570,7 +570,7 @@ GIB_Regex_Match_f (void)
GIB_Regex_Compile (GIB_Argv (2), GIB_Regex_Compile (GIB_Argv (2),
REG_EXTENDED | REG_EXTENDED |
GIB_Regex_Translate_Options (GIB_Argv (3))))) GIB_Regex_Translate_Options (GIB_Argv (3)))))
GIB_Error ("regex", "%s: %s", GIB_Argv (0), GIB_Regex_Error ()); GIB_Error ("RegexError", "%s: %s", GIB_Argv (0), GIB_Regex_Error ());
else if (regexec (reg, GIB_Argv (1), 0, 0, GIB_Regex_Translate_Runtime_Options (GIB_Argv (3)))) else if (regexec (reg, GIB_Argv (1), 0, 0, GIB_Regex_Translate_Runtime_Options (GIB_Argv (3))))
GIB_Return ("0"); GIB_Return ("0");
else else
@ -597,7 +597,7 @@ GIB_Regex_Replace_f (void)
GIB_Regex_Compile (GIB_Argv (2), GIB_Regex_Compile (GIB_Argv (2),
REG_EXTENDED | REG_EXTENDED |
GIB_Regex_Translate_Options (GIB_Argv (3))))) GIB_Regex_Translate_Options (GIB_Argv (3)))))
GIB_Error ("regex", "%s: %s", GIB_Argv (0), GIB_Regex_Error ()); GIB_Error ("RegexError", "%s: %s", GIB_Argv (0), GIB_Regex_Error ());
else if (strchr (GIB_Argv (3), 'g')) else if (strchr (GIB_Argv (3), 'g'))
while (!regexec while (!regexec
(reg, GIB_Argv (1) + ofs, 10, match, ofs > 0 ? REG_NOTBOL : 0) (reg, GIB_Argv (1) + ofs, 10, match, ofs > 0 ? REG_NOTBOL : 0)
@ -629,7 +629,7 @@ GIB_Regex_Extract_f (void)
GIB_Regex_Compile (GIB_Argv (2), GIB_Regex_Compile (GIB_Argv (2),
REG_EXTENDED | REG_EXTENDED |
GIB_Regex_Translate_Options (GIB_Argv (3))))) GIB_Regex_Translate_Options (GIB_Argv (3)))))
GIB_Error ("regex", "%s: %s", GIB_Argv (0), GIB_Regex_Error ()); GIB_Error ("RegexError", "%s: %s", GIB_Argv (0), GIB_Regex_Error ());
else if (!regexec (reg, GIB_Argv (1), 32, match, GIB_Regex_Translate_Runtime_Options (GIB_Argv (3))) && match[0].rm_eo) { else if (!regexec (reg, GIB_Argv (1), 32, match, GIB_Regex_Translate_Runtime_Options (GIB_Argv (3))) && match[0].rm_eo) {
dsprintf (GIB_Return (0), "%lu", (unsigned long) match[0].rm_eo); dsprintf (GIB_Return (0), "%lu", (unsigned long) match[0].rm_eo);
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
@ -742,9 +742,9 @@ GIB_Event_Register_f (void)
if (GIB_Argc () != 3) if (GIB_Argc () != 3)
GIB_USAGE ("event function"); GIB_USAGE ("event function");
else if (!(func = GIB_Function_Find (GIB_Argv (2))) && GIB_Argv (2)[0]) else if (!(func = GIB_Function_Find (GIB_Argv (2))) && GIB_Argv (2)[0])
GIB_Error ("function", "Function %s not found.", GIB_Argv (2)); GIB_Error ("UnknownFunctionError", "Function %s not found.", GIB_Argv (2));
else if (GIB_Event_Register (GIB_Argv (1), func)) else if (GIB_Event_Register (GIB_Argv (1), func))
GIB_Error ("event", "Event %s not found.", GIB_Argv (1)); GIB_Error ("UnknownEventError", "Event %s not found.", GIB_Argv (1));
} }
/* File access */ /* File access */
@ -792,7 +792,7 @@ GIB_File_Read_f (void)
return; return;
} }
if (!*GIB_Argv (1)) { if (!*GIB_Argv (1)) {
GIB_Error ("file", "%s: null filename provided", GIB_Argv (0)); GIB_Error ("FileAccessError", "%s: null filename provided", GIB_Argv (0));
return; return;
} }
@ -808,7 +808,7 @@ GIB_File_Read_f (void)
ret->str[len] = 0; ret->str[len] = 0;
Qclose (file); Qclose (file);
} else { } else {
GIB_Error ("file", GIB_Error ("FileAccessError",
"%s: could not read %s: %s", GIB_Argv (0), path, "%s: could not read %s: %s", GIB_Argv (0), path,
strerror (errno)); strerror (errno));
return; return;
@ -825,7 +825,7 @@ GIB_File_Write_f (void)
return; return;
} }
if (!*GIB_Argv (1)) { if (!*GIB_Argv (1)) {
GIB_Error ("file", "%s: null filename provided", GIB_Argv (0)); GIB_Error ("InvalidArgumentError", "%s: null filename provided", GIB_Argv (0));
return; return;
} }
@ -847,7 +847,7 @@ GIB_File_Find_f (void)
return; return;
} }
if (GIB_File_Transform_Path (GIB_Argd (1))) { if (GIB_File_Transform_Path (GIB_Argd (1))) {
GIB_Error ("access", GIB_Error ("FileAccessError",
"%s: access to %s denied", GIB_Argv (0), GIB_Argv (1)); "%s: access to %s denied", GIB_Argv (0), GIB_Argv (1));
return; return;
} }
@ -882,19 +882,19 @@ GIB_File_Move_f (void)
return; return;
} }
if (GIB_File_Transform_Path (GIB_Argd (1))) { if (GIB_File_Transform_Path (GIB_Argd (1))) {
GIB_Error ("access", GIB_Error ("FileAccessError",
"%s: access to %s denied", GIB_Argv (0), GIB_Argv (1)); "%s: access to %s denied", GIB_Argv (0), GIB_Argv (1));
return; return;
} }
if (GIB_File_Transform_Path (GIB_Argd (2))) { if (GIB_File_Transform_Path (GIB_Argd (2))) {
GIB_Error ("access", GIB_Error ("FileAccessError",
"%s: access to %s denied", GIB_Argv (0), GIB_Argv (2)); "%s: access to %s denied", GIB_Argv (0), GIB_Argv (2));
return; return;
} }
path1 = GIB_Argv (1); path1 = GIB_Argv (1);
path2 = GIB_Argv (2); path2 = GIB_Argv (2);
if (QFS_Rename (path1, path2)) if (QFS_Rename (path1, path2))
GIB_Error ("file", "%s: could not move %s to %s: %s", GIB_Argv (0), GIB_Error ("FileAccessError", "%s: could not move %s to %s: %s", GIB_Argv (0),
path1, path2, strerror (errno)); path1, path2, strerror (errno));
} }
@ -908,13 +908,13 @@ GIB_File_Delete_f (void)
return; return;
} }
if (GIB_File_Transform_Path (GIB_Argd (1))) { if (GIB_File_Transform_Path (GIB_Argd (1))) {
GIB_Error ("access", GIB_Error ("FileAccessError",
"%s: access to %s denied", GIB_Argv (0), GIB_Argv (1)); "%s: access to %s denied", GIB_Argv (0), GIB_Argv (1));
return; return;
} }
path = GIB_Argv (1); path = GIB_Argv (1);
if (QFS_Remove (path)) if (QFS_Remove (path))
GIB_Error ("file", "%s: could not delete %s: %s", GIB_Argv (0), path, GIB_Error ("FileAccessError", "%s: could not delete %s: %s", GIB_Argv (0), path,
strerror (errno)); strerror (errno));
} }
@ -955,12 +955,15 @@ GIB_Print_f (void)
static void static void
GIB_Class_f (void) GIB_Class_f (void)
{ {
if (GIB_Argc () == 5) if (GIB_Object_Get (GIB_Argv(1))) {
GIB_Error ("ClassRedefinitionError",
"Class '%s' already exists", GIB_Argv(1));
} else if (GIB_Argc () == 5)
GIB_Classes_Build_Scripted (GIB_Argv(1), GIB_Argv(3), GIB_Classes_Build_Scripted (GIB_Argv(1), GIB_Argv(3),
GIB_Argm (4)->children, GIB_Argm (4)->children,
GIB_DATA(cbuf_active)->script); GIB_DATA(cbuf_active)->script);
else else
GIB_Classes_Build_Scripted (GIB_Argv(1), NULL, GIB_Classes_Build_Scripted (GIB_Argv(1), "Object",
GIB_Argm (2)->children, GIB_Argm (2)->children,
GIB_DATA(cbuf_active)->script); GIB_DATA(cbuf_active)->script);
} }
@ -972,7 +975,7 @@ GIB_Emit_f (void)
GIB_USAGE ("signal [arg1 arg2 ...]"); GIB_USAGE ("signal [arg1 arg2 ...]");
return; return;
} else if (!GIB_DATA(cbuf_active)->reply.obj) { } else if (!GIB_DATA(cbuf_active)->reply.obj) {
GIB_Error ("emit", "Cannot emit signal in this context."); GIB_Error ("InvalidContextError", "Cannot emit signal in this context.");
return; return;
} else { } else {
int i; int i;
@ -1007,6 +1010,22 @@ GIB_Error_f (void)
GIB_Error (GIB_Argv(1), "%s", GIB_Argv(2)); GIB_Error (GIB_Argv(1), "%s", GIB_Argv(2));
} }
/*
static void
GIB_New_f (void)
{
GIB_Object_t *classobj;
if (GIB_Argc() < 2) {
GIB_USAGE ("classname");
} else if (
!(class = GIB_Object_Get(GIB_Argv(1)))
|| classobj->class->classobj != classobj) {
GIB_Error ("UnknownClassError", "Class '%s' does not exist",
GIB_Argv(1));
} else {
GIB_Send (classobj,
*/
static void static void
GIB_bp1_f (void) GIB_bp1_f (void)
{ {

View file

@ -226,7 +226,7 @@ Object_Destruct (void *data)
return; return;
} }
gib_methodtab_t Object_methods[] = { static gib_methodtab_t Object_methods[] = {
{"retain", Object_Retain_f, NULL}, {"retain", Object_Retain_f, NULL},
{"release", Object_Release_f, NULL}, {"release", Object_Release_f, NULL},
{"init", Object_Init_f, NULL}, {"init", Object_Init_f, NULL},
@ -239,7 +239,7 @@ gib_methodtab_t Object_methods[] = {
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
gib_methodtab_t Object_class_methods[] = { static gib_methodtab_t Object_class_methods[] = {
{"parent", Object_SuperClass_f, NULL}, {"parent", Object_SuperClass_f, NULL},
{"children", Object_Class_Children_f, NULL}, {"children", Object_Class_Children_f, NULL},
{"new", Object_Class_New_f, NULL}, {"new", Object_Class_New_f, NULL},
@ -248,7 +248,7 @@ gib_methodtab_t Object_class_methods[] = {
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
gib_classdesc_t Object_class = { static gib_classdesc_t Object_class = {
"Object", NULL, "Object", NULL,
Object_Construct, NULL, Object_Construct, NULL,
Object_Destruct, Object_Destruct,
@ -335,16 +335,16 @@ Thread_Destruct (void *data)
free (t); free (t);
} }
gib_methodtab_t Thread_methods[] = { static gib_methodtab_t Thread_methods[] = {
{"init", Thread_Init_f, NULL}, {"init", Thread_Init_f, NULL},
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
gib_methodtab_t Thread_class_methods[] = { static gib_methodtab_t Thread_class_methods[] = {
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
gib_classdesc_t Thread_class = { static gib_classdesc_t Thread_class = {
"Thread", "Object", "Thread", "Object",
Thread_Construct, NULL, Thread_Construct, NULL,
Thread_Destruct, Thread_Destruct,
@ -352,7 +352,7 @@ gib_classdesc_t Thread_class = {
}; };
/* /*
Object hash class Object Hash class
Stores references to objects in a Hash Stores references to objects in a Hash
*/ */
@ -489,18 +489,18 @@ ObjectHash_Remove_f (gib_object_t *obj, gib_method_t *method, void *data,
return 0; return 0;
} }
gib_methodtab_t ObjectHash_methods[] = { static gib_methodtab_t ObjectHash_methods[] = {
{"insert", ObjectHash_Insert_f, NULL}, {"insert", ObjectHash_Insert_f, NULL},
{"get", ObjectHash_Get_f, NULL}, {"get", ObjectHash_Get_f, NULL},
{"remove", ObjectHash_Remove_f, NULL}, {"remove", ObjectHash_Remove_f, NULL},
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
gib_methodtab_t ObjectHash_class_methods[] = { static gib_methodtab_t ObjectHash_class_methods[] = {
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
gib_classdesc_t ObjectHash_class = { static gib_classdesc_t ObjectHash_class = {
"ObjectHash", "Object", "ObjectHash", "Object",
ObjectHash_Construct, NULL, ObjectHash_Construct, NULL,
ObjectHash_Destruct, ObjectHash_Destruct,

View file

@ -352,7 +352,7 @@ GIB_Execute (cbuf_t * cbuf)
GIB_Execute_Generate_Composite (cbuf); GIB_Execute_Generate_Composite (cbuf);
if (Cmd_Command (cbuf->args)) if (Cmd_Command (cbuf->args))
GIB_Error ( GIB_Error (
"command", "UnknownCommandError",
"No builtin, function, or console command " "No builtin, function, or console command "
"named '%s' was found.", "named '%s' was found.",
cbuf->args->argv[0]->str cbuf->args->argv[0]->str

View file

@ -42,13 +42,13 @@ GIB_Semantic_Validate_Class (gib_tree_t * tokens)
if (!tokens->next || !tokens->next->next) { if (!tokens->next || !tokens->next->next) {
GIB_Parse_Error ("Malformed class definition; expected class " GIB_Parse_Error ("Malformed class definition; expected class "
"name, optional colon and parent class, and " "name, optional 'extends' and parent class, and "
"program block.", tokens->start); "program block.", tokens->start);
return -1; return -1;
} }
if (tokens->next->next->delim == ' ' && !strcmp if (tokens->next->next->delim == ' ' && !strcmp
(tokens->next->next->str, ":")) { (tokens->next->next->str, "extends")) {
if (!tokens->next->next->next) { if (!tokens->next->next->next) {
GIB_Parse_Error ("Malformed class definition; " GIB_Parse_Error ("Malformed class definition; "
"expected parent class after " "expected parent class after "