compiler/libec: (#772) error on using wrong class name for constructors/destructors
authorJerome St-Louis <jerome@ecere.com>
Mon, 19 May 2014 01:04:19 +0000 (21:04 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 19 May 2014 01:07:35 +0000 (21:07 -0400)
- A syntax error was being generated for an unrecognized type, but not if using an existing (mismatched) type

compiler/bootstrap/libec/bootstrap/firstPass.c
compiler/bootstrap/libec/bootstrap/grammar.c
compiler/libec/precompiled/grammar.c
compiler/libec/src/firstPass.ec
compiler/libec/src/grammar.ec
compiler/libec/src/grammar.y
ecere/src/sys/Date.ec
ecere/src/sys/GlobalAppSettings.ec
ecere/src/sys/TempFile.ec

index 02fec76..c025b2c 100644 (file)
@@ -1281,6 +1281,12 @@ extern struct __ecereNameSpace__ecere__com__Class * __ecereNameSpace__ecere__com
 
 extern unsigned int buildingECERECOMModule;
 
+extern int strcmp(const char * , const char * );
+
+extern void FreeList(struct __ecereNameSpace__ecere__sys__OldList * list, void (*  FreeFunction)(void * ));
+
+extern void FreeSpecifier(struct Specifier * spec);
+
 extern struct Declarator * GetFuncDecl(struct Declarator * decl);
 
 extern struct __ecereNameSpace__ecere__com__Method * __ecereNameSpace__ecere__com__eClass_AddVirtualMethod(struct __ecereNameSpace__ecere__com__Class * _class, char *  name, char *  type, void *  function, int declMode);
@@ -1493,6 +1499,18 @@ if(definitions != (((void *)0)))
 {
 for(def = definitions->first; def; def = def->next)
 {
+if(def->type == 0 && (def->function->isConstructor || def->function->isDestructor))
+{
+struct Specifier * spec = def->function->specifiers ? (*def->function->specifiers).last : (((void *)0));
+
+if(!spec || spec->type != 1 || !spec->name || (strcmp(spec->name, regClass->name) && (!spec->symbol || !spec->symbol->registered || strcmp(spec->symbol->registered->name, regClass->name))))
+{
+yylloc = def->function->loc;
+Compiler_Error(__ecereNameSpace__ecere__GetTranslatedString("ec", "wrong class name specified for %s\n", (((void *)0))), def->function->isConstructor ? __ecereNameSpace__ecere__GetTranslatedString("ec", "constructor", (((void *)0))) : __ecereNameSpace__ecere__GetTranslatedString("ec", "destructor", (((void *)0))));
+}
+FreeList(def->function->specifiers, FreeSpecifier);
+def->function->specifiers = (((void *)0));
+}
 if(def->type == 0 && def->function->declarator)
 {
 struct ClassFunction * func = def->function;
index 480acdc..e0b59b2 100644 (file)
@@ -3278,21 +3278,20 @@ yyval.classFunction->id = ++globalContext->nextID;
 break;
 case 13:
 {
-yyval.classFunction = MkClassFunction((((void *)0)), (((void *)0)), (((void *)0)), (((void *)0)));
+yyval.classFunction = MkClassFunction(yyvsp[(1) - (3)].list, (((void *)0)), (((void *)0)), (((void *)0)));
 yyval.classFunction->isConstructor = 0x1;
 yyval.classFunction->loc = (yyloc);
 yyval.classFunction->id = ++globalContext->nextID;
-FreeList(yyvsp[(1) - (3)].list, FreeSpecifier);
 ;
 }
 break;
 case 14:
 {
-yyval.classFunction = MkClassFunction((((void *)0)), (((void *)0)), (((void *)0)), (((void *)0)));
+yyval.classFunction = MkClassFunction(yyvsp[(2) - (4)].list, (((void *)0)), (((void *)0)), (((void *)0)));
 yyval.classFunction->isDestructor = 0x1;
 yyval.classFunction->loc = (yyloc);
 yyval.classFunction->id = ++globalContext->nextID;
-FreeList(yyvsp[(2) - (4)].list, FreeSpecifier);
+;
 }
 break;
 case 15:
index 8d197bc..4f71929 100644 (file)
@@ -3278,21 +3278,20 @@ yyval.classFunction->id = ++globalContext->nextID;
 break;
 case 13:
 {
-yyval.classFunction = MkClassFunction((((void *)0)), (((void *)0)), (((void *)0)), (((void *)0)));
+yyval.classFunction = MkClassFunction(yyvsp[(1) - (3)].list, (((void *)0)), (((void *)0)), (((void *)0)));
 yyval.classFunction->isConstructor = 0x1;
 yyval.classFunction->loc = (yyloc);
 yyval.classFunction->id = ++globalContext->nextID;
-FreeList(yyvsp[(1) - (3)].list, FreeSpecifier);
 ;
 }
 break;
 case 14:
 {
-yyval.classFunction = MkClassFunction((((void *)0)), (((void *)0)), (((void *)0)), (((void *)0)));
+yyval.classFunction = MkClassFunction(yyvsp[(2) - (4)].list, (((void *)0)), (((void *)0)), (((void *)0)));
 yyval.classFunction->isDestructor = 0x1;
 yyval.classFunction->loc = (yyloc);
 yyval.classFunction->id = ++globalContext->nextID;
-FreeList(yyvsp[(2) - (4)].list, FreeSpecifier);
+;
 }
 break;
 case 15:
index 501310e..7a76530 100644 (file)
@@ -425,6 +425,18 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
    {
       for(def = definitions.first; def; def = def.next)
       {
+         if(def.type == functionClassDef && (def.function.isConstructor || def.function.isDestructor))
+         {
+            Specifier spec = def.function.specifiers ? def.function.specifiers->last : null;
+            if(!spec || spec.type != nameSpecifier || !spec.name ||
+               (strcmp(spec.name, regClass.name) && (!spec.symbol || !spec.symbol.registered || strcmp(spec.symbol.registered.name, regClass.name))) )
+            {
+               yylloc = def.function.loc;
+               Compiler_Error($"wrong class name specified for %s\n", def.function.isConstructor ? $"constructor" : $"destructor");
+            }
+            FreeList(def.function.specifiers, FreeSpecifier);
+            def.function.specifiers = null;
+         }
          if(def.type == functionClassDef && def.function.declarator)
          {
             ClassFunction func = def.function;
index e72de03..940f90a 100644 (file)
@@ -13299,14 +13299,14 @@ yyreduce:
 
 /* Line 1464 of yacc.c  */
 #line 545 "grammar.y"
-    { (yyval.classFunction) = MkClassFunction(null, null, null, null); (yyval.classFunction).isConstructor = true; (yyval.classFunction).loc = (yyloc); (yyval.classFunction).id = ++globalContext.nextID; FreeList((yyvsp[(1) - (3)].list), FreeSpecifier); ;}
+    { (yyval.classFunction) = MkClassFunction((yyvsp[(1) - (3)].list), null, null, null); (yyval.classFunction).isConstructor = true; (yyval.classFunction).loc = (yyloc); (yyval.classFunction).id = ++globalContext.nextID; ;}
     break;
 
   case 14:
 
 /* Line 1464 of yacc.c  */
 #line 550 "grammar.y"
-    { (yyval.classFunction) = MkClassFunction(null, null, null, null); (yyval.classFunction).isDestructor = true; (yyval.classFunction).loc = (yyloc); (yyval.classFunction).id = ++globalContext.nextID; FreeList((yyvsp[(2) - (4)].list), FreeSpecifier) ;}
+    { (yyval.classFunction) = MkClassFunction((yyvsp[(2) - (4)].list), null, null, null); (yyval.classFunction).isDestructor = true; (yyval.classFunction).loc = (yyloc); (yyval.classFunction).id = ++globalContext.nextID; ;}
     break;
 
   case 15:
index 6504bfc..8382cde 100644 (file)
@@ -542,12 +542,12 @@ class_function_definition_start:
 
 constructor_function_definition_start:
    guess_declaration_specifiers '(' ')'
-      { $$ = MkClassFunction(null, null, null, null); $$.isConstructor = true; $$.loc = @$; $$.id = ++globalContext.nextID; FreeList($1, FreeSpecifier); }
+      { $$ = MkClassFunction($1, null, null, null); $$.isConstructor = true; $$.loc = @$; $$.id = ++globalContext.nextID; }
    ;
 
 destructor_function_definition_start:
    '~' guess_declaration_specifiers '(' ')'
-      { $$ = MkClassFunction(null, null, null, null); $$.isDestructor = true; $$.loc = @$; $$.id = ++globalContext.nextID; FreeList($2, FreeSpecifier) }
+      { $$ = MkClassFunction($2, null, null, null); $$.isDestructor = true; $$.loc = @$; $$.id = ++globalContext.nextID; }
    ;
 
 virtual_class_function_definition_start:
index 35e0458..c327225 100644 (file)
@@ -386,7 +386,7 @@ class DateDropBox : DropBox
       if(pullDown && sKey == enter)
       {
          // Because we can still edit the date text while the calendar is dropped, enter on the date box should validate it
-         NotifyTextEntry(master, this, contents /*null*/, true);//false);
+         NotifyTextEntry(master, this, contents, true);
          ((DataBox)master).SetData(&calendar.dateValue, false);
          ((DataBox)master).Refresh();
          return false;
index 18b4f40..077158d 100644 (file)
@@ -144,7 +144,7 @@ private:
 
    subclass(GlobalSettingsDriver) driverClass;
 
-   ~GlobalAppSettings()
+   ~GlobalSettings()
    {
       if(f)
          f.Unlock(0, 0, true);
@@ -541,7 +541,7 @@ public:
    void CloseAndMonitor()
    {
       Close();
-      if(settingsFilePath && OnAskReloadSettings != GlobalAppSettings::OnAskReloadSettings)
+      if(settingsFilePath && OnAskReloadSettings != GlobalSettings::OnAskReloadSettings)
       {
          settingsMonitor.fileName = settingsFilePath;
          settingsMonitor.StartMonitoring();
@@ -745,4 +745,3 @@ public:
       return result;
    }
 };
-
index 0feb666..8f9d32e 100644 (file)
@@ -13,7 +13,7 @@ public class TempFile : File
 
    openMode = writeRead;
 
-   ~File()
+   ~TempFile()
    {
       delete buffer;
    }