Prechádzať zdrojové kódy

All variables are always exported in read-only mode - according to the
last report.

Vladislav Folts 9 rokov pred
rodič
commit
58b6b12934

BIN
bin/compiled.zip


+ 0 - 7
src/ob/ContextVar.ob

@@ -5,7 +5,6 @@ IMPORT
 TYPE
     Declaration* = RECORD(ContextType.DeclarationAndIdentHandle)
         PROCEDURE doInitCode*(): STRING;
-        PROCEDURE doCheckExport*(name: STRING);
 
         idents: ARRAY * OF Context.PIdentdefInfo;
         type-: Types.PStorageType;
@@ -50,17 +49,11 @@ PROCEDURE Declaration.doInitCode(): STRING;
     RETURN SELF.type.initializer(SELF);
 END;
 
-PROCEDURE Declaration.doCheckExport(name: STRING);
-END;
-
 PROCEDURE Declaration.endParse(): BOOLEAN;
 BEGIN
     gen <- SELF.codeGenerator();
     FOR id IN SELF.idents DO
         varName <- id.id();
-        IF id.exported() THEN
-            SELF.doCheckExport(varName);
-        END;
 
         v <- NEW Variable.Declared(varName, SELF.type);
         SELF.root().currentScope().addSymbol(NEW Symbols.Symbol(varName, v), id.exported());

+ 0 - 8
src/oberon/OberonContextVar.ob

@@ -5,12 +5,4 @@ TYPE
     Declaration* = RECORD(ContextVar.Declaration)
     END;
 
-PROCEDURE Declaration.doCheckExport(id: STRING);
-BEGIN
-    type <- SELF.type;
-    IF (type IS Types.PRecord) OR (type IS Types.PArray) THEN
-        Errors.raise("variable '" + id + "' cannot be exported: only scalar variables can be exported");
-    END;
-END;
-
 END OberonContextVar.

+ 9 - 0
test/test_unit.js

@@ -1548,6 +1548,15 @@ return {
          ["MODULE m; IMPORT J := JS; BEGIN JS.alert(\"test\") END m.", "undeclared identifier: 'JS'"]
          )
     ),
+"variables exported as read-only": testWithModule(
+    "MODULE test; TYPE T* = RECORD i*: INTEGER END; VAR r*: T; p*: POINTER TO T; i*: INTEGER; END test.",
+    pass("MODULE m; IMPORT test; BEGIN ASSERT(test.r.i = 0); END m.",
+         "MODULE m; IMPORT test; BEGIN ASSERT(test.i = 0); END m.",
+         "MODULE m; IMPORT test; BEGIN test.p.i := 0; END m."
+        ),
+    fail(["MODULE m; IMPORT test; BEGIN test.i := 0; END m.", "cannot assign to imported variable"],
+         ["MODULE m; IMPORT test; BEGIN test.r.i := 0; END m.", "cannot assign to read-only record's field"]
+        )),
 "syntax errors": testWithGrammar(
     grammar.module,
     pass(),

+ 0 - 9
test/test_unit_oberon.js

@@ -23,15 +23,6 @@ exports.suite = {
     pass(),
     fail(["b1 := b1 + b1", "operator '+' type mismatch: numeric type or SET expected, got 'BOOLEAN'"])
     ),
-"scalar variables cannot be exported": testWithGrammar(
-    grammar.declarationSequence,
-    pass(),
-    fail(["VAR r*: RECORD END;",
-          "variable 'r' cannot be exported: only scalar variables can be exported"],
-         ["VAR a*: ARRAY 5 OF INTEGER;",
-          "variable 'a' cannot be exported: only scalar variables can be exported"]
-        )
-    ),
 "eberon key words can be identifiers": testWithGrammar(
     grammar.variableDeclaration,
     pass("SELF: INTEGER",