2
0
Эх сурвалжийг харах

Fix export for pointer types.

Vladislav Folts 11 жил өмнө
parent
commit
887bf8ff1d

BIN
bin/compiled.zip


+ 17 - 7
src/ob/Code.ob

@@ -371,22 +371,30 @@ BEGIN
     RETURN result
 END adjustPrecedence;
 
-PROCEDURE isPointerShouldBeExported(type: Types.Pointer): BOOLEAN;
+PROCEDURE isPointerShouldBeExported(type: Types.Pointer): JsString.Type;
 VAR
     r: Types.PRecord;
+    result: JsString.Type;
 BEGIN
     r := Types.pointerBase(type);
-    RETURN Types.typeName(r^) = NIL
+    IF Types.typeName(r^) = NIL THEN
+        result := Types.recordConstructor(r^);
+    END;
+    RETURN result
 END isPointerShouldBeExported;
 
-PROCEDURE typeShouldBeExported(typeId: Types.PId): BOOLEAN;
+PROCEDURE typeShouldBeExported(typeId: Types.PId; defaultId: JsString.Type): JsString.Type;
 VAR
+    result: JsString.Type;
     type: Types.PType;
 BEGIN
     type := typeId(Types.PTypeId).type();
-    RETURN (type IS Types.PRecord)
-        OR ((type IS Types.PPointer) 
-            & isPointerShouldBeExported(type^(Types.Pointer)))
+    IF type IS Types.PRecord THEN
+        result := defaultId;
+    ELSIF type IS Types.PPointer THEN
+        result := isPointerShouldBeExported(type^(Types.Pointer));
+    END;
+    RETURN result
 END typeShouldBeExported;
 
 PROCEDURE genExport*(s: Symbols.Symbol): JsString.Type;
@@ -398,8 +406,10 @@ BEGIN
             JsString.make("function(){return "),
             s.id()),
             JsString.make(";}"));
-    ELSIF ~s.isType() OR typeShouldBeExported(s.info()) THEN
+    ELSIF ~s.isType() THEN
         result := s.id();
+    ELSE
+        result := typeShouldBeExported(s.info(), s.id())
     END;
     RETURN result
 END genExport;

+ 2 - 2
src/ob/Types.ob

@@ -56,10 +56,10 @@ TYPE
 
     PVariable* = POINTER TO Variable;
 
-    VariableImpl* = RECORD(Variable) (*TO FIX*)
+    VariableImpl = RECORD(Variable)
         mType: PType
     END;
-    PVariableImpl* = POINTER TO VariableImpl;
+    PVariableImpl = POINTER TO VariableImpl;
 
     ReadOnlyVariable = RECORD(VariableImpl)
     END;

+ 5 - 0
test/expected/export.js

@@ -38,6 +38,10 @@ var T1 = RTL$.extend({
 	init: function T1(){
 	}
 });
+var NotExportedRecord = RTL$.extend({
+	init: function NotExportedRecord(){
+	}
+});
 var pr1 = null;
 var p2 = null;
 var vi = 0;
@@ -47,6 +51,7 @@ function p1(){
 return {
 	ci: ci,
 	T1: T1,
+	PNotExportedRecord: NotExportedRecord,
 	pr1: function(){return pr1;},
 	p2: function(){return p2;},
 	vi: function(){return vi;},

+ 3 - 0
test/input/export.ob

@@ -5,6 +5,9 @@ TYPE
     T1* = RECORD END;
     T2* = PROCEDURE;
     T3* = ARRAY 5 OF INTEGER;
+
+    NotExportedRecord = RECORD END;
+    PNotExportedRecord* = POINTER TO NotExportedRecord;
 VAR
     pr1*: POINTER TO T1;
     p2*: T2;