Update to commit e33eef4f8fab800eaf4a32b2d159cde6c4bbb38e
[inform.git] / src / objects.c
index 6039828132c7efd34c8a3b64fcd687b4bf4de3c7..b957073d941f73c109ecf8b760bdb9d0d8dd0c54 100644 (file)
@@ -6,9 +6,8 @@
 /*                    checks syntax and translates such directives into      */
 /*                    specifications for the object-maker.                   */
 /*                                                                           */
-/* Copyright (c) Graham Nelson 1993 - 2020                                   */
-/*                                                                           */
-/* This file is part of Inform.                                              */
+/*   Part of Inform 6.35                                                     */
+/*   copyright (c) Graham Nelson 1993 - 2021                                 */
 /*                                                                           */
 /* Inform is free software: you can redistribute it and/or modify            */
 /* it under the terms of the GNU General Public License as published by      */
@@ -21,7 +20,7 @@
 /* GNU General Public License for more details.                              */
 /*                                                                           */
 /* You should have received a copy of the GNU General Public License         */
-/* along with Inform. If not, see https://gnu.org/licenses/                  */
+/* along with Inform. If not, see https://gnu.org/licenses/                  *
 /*                                                                           */
 /* ------------------------------------------------------------------------- */
 
@@ -135,13 +134,20 @@ more than",
 
     get_next_token();
     i = token_value; name = token_text;
-    if ((token_type != SYMBOL_TT) || (!(sflags[i] & UNKNOWN_SFLAG)))
+    if (token_type != SYMBOL_TT)
     {   discard_token_location(beginning_debug_location);
         ebf_error("new attribute name", token_text);
         panic_mode_error_recovery(); 
         put_token_back();
         return;
     }
+    if (!(sflags[i] & UNKNOWN_SFLAG))
+    {   discard_token_location(beginning_debug_location);
+        ebf_symbol_error("new attribute name", token_text, typename(stypes[i]), slines[i]);
+        panic_mode_error_recovery(); 
+        put_token_back();
+        return;
+    }
 
     directive_keywords.enabled = TRUE;
     get_next_token();
@@ -226,13 +232,20 @@ Advanced game to get an extra 62)");
     get_next_token();
 
     i = token_value; name = token_text;
-    if ((token_type != SYMBOL_TT) || (!(sflags[i] & UNKNOWN_SFLAG)))
+    if (token_type != SYMBOL_TT)
     {   discard_token_location(beginning_debug_location);
         ebf_error("new property name", token_text);
         panic_mode_error_recovery();
         put_token_back();
         return;
     }
+    if (!(sflags[i] & UNKNOWN_SFLAG))
+    {   discard_token_location(beginning_debug_location);
+        ebf_symbol_error("new property name", token_text, typename(stypes[i]), slines[i]);
+        panic_mode_error_recovery();
+        put_token_back();
+        return;
+    }
 
     directive_keywords.enabled = TRUE;
     get_next_token();
@@ -796,7 +809,7 @@ static int write_property_block_z(char *shortname)
     {   uchar *tmp;
         if (mark+1+510 >= MAX_PROP_TABLE_SIZE)
             memoryerror("MAX_PROP_TABLE_SIZE",MAX_PROP_TABLE_SIZE);
-        tmp = translate_text(p+mark+1,p+mark+1+510,shortname);
+        tmp = translate_text(p+mark+1,p+mark+1+510,shortname,STRCTX_OBJNAME);
         if (!tmp) error ("Short name of object exceeded 765 Z-characters");
         i = subtract_pointers(tmp,(p+mark+1));
         p[mark] = i/2;
@@ -989,7 +1002,7 @@ static void manufacture_object_g(void)
     }
 
     objectsg[no_objects].shortname = compile_string(shortname_buffer,
-      FALSE, FALSE);
+      STRCTX_OBJNAME);
 
         /*  The properties table consists simply of a sequence of property
             blocks, one for each object in order of definition, exactly as
@@ -1081,12 +1094,7 @@ static void properties_segment_z(int this_segment)
             {   if (stypes[token_value]==INDIVIDUAL_PROPERTY_T)
                     this_identifier_number = svals[token_value];
                 else
-                {   char already_error[128];
-                    sprintf(already_error,
-                        "\"%s\" is a name already in use (with type %s) \
-and may not be used as a property name too",
-                        token_text, typename(stypes[token_value]));
-                    error(already_error);
+                {   ebf_symbol_error("property name", token_text, typename(stypes[token_value]), slines[token_value]);
                     return;
                 }
             }
@@ -1276,7 +1284,7 @@ the names '%s' and '%s' actually refer to the same property",
        warning_named("Version 3 limit of 4 values per property exceeded \
 (use -v5 to get 32), so truncating property",
                     (char *) symbs[property_name_symbol]);
-                full_object.pp[next_prop].l=4;
+                length = 8;
             }
         }
 
@@ -1350,12 +1358,7 @@ static void properties_segment_g(int this_segment)
             {   if (stypes[token_value]==INDIVIDUAL_PROPERTY_T)
                     this_identifier_number = svals[token_value];
                 else
-                {   char already_error[128];
-                    sprintf(already_error,
-                        "\"%s\" is a name already in use (with type %s) \
-and may not be used as a property name too",
-                        token_text, typename(stypes[token_value]));
-                    error(already_error);
+                {   ebf_symbol_error("property name", token_text, typename(stypes[token_value]), slines[token_value]);
                     return;
                 }
             }
@@ -1430,7 +1433,8 @@ the names '%s' and '%s' actually refer to the same property",
             if (token_type == SEGMENT_MARKER_TT) { put_token_back(); break; }
 
             if ((!individual_property) && (property_number==1)
-                && (token_type != SQ_TT) && (token_type != DQ_TT)
+                && ((token_type != SQ_TT) || (strlen(token_text) <2 )) 
+                && (token_type != DQ_TT)
                 )
                 warning ("'name' property should only contain dictionary words");
 
@@ -1752,7 +1756,6 @@ extern void make_class(char * metaclass_name)
 {   int n, duplicates_to_make = 0, class_number = no_objects+1,
         metaclass_flag = (metaclass_name != NULL);
     char duplicate_name[128];
-    int class_symbol;
     debug_location_beginning beginning_debug_location =
         get_token_location_beginning();
 
@@ -1776,13 +1779,18 @@ inconvenience, please contact the maintainers.");
     }
     else
     {   get_next_token();
-        if ((token_type != SYMBOL_TT)
-            || (!(sflags[token_value] & UNKNOWN_SFLAG)))
+        if (token_type != SYMBOL_TT)
         {   discard_token_location(beginning_debug_location);
             ebf_error("new class name", token_text);
             panic_mode_error_recovery();
             return;
         }
+        if (!(sflags[token_value] & UNKNOWN_SFLAG))
+        {   discard_token_location(beginning_debug_location);
+            ebf_symbol_error("new class name", token_text, typename(stypes[token_value]), slines[token_value]);
+            panic_mode_error_recovery();
+            return;
+        }
     }
 
     /*  Each class also creates a modest object representing itself:         */
@@ -1838,8 +1846,6 @@ inconvenience, please contact the maintainers.");
       full_object_g.propdata[0].marker = OBJECT_MV;
     }
 
-    class_symbol = token_value;
-
     if (!metaclass_flag)
     {   get_next_token();
         if ((token_type == SEP_TT) && (token_value == OPENB_SEP))
@@ -1976,10 +1982,13 @@ extern void make_object(int nearby_flag,
 
     if (token_type == DQ_TT) textual_name = token_text;
     else
-    {   if ((token_type != SYMBOL_TT)
-            || (!(sflags[token_value] & UNKNOWN_SFLAG)))
+    {   if (token_type != SYMBOL_TT) {
             ebf_error("name for new object or its textual short name",
                 token_text);
+        }
+        else if (!(sflags[token_value] & UNKNOWN_SFLAG)) {
+            ebf_symbol_error("new object", token_text, typename(stypes[token_value]), slines[token_value]);
+        }
         else
         {   internal_name_symbol = token_value;
             strcpy(internal_name, token_text);