浏览代码

js -> eberon transition

Vladislav Folts 10 年之前
父节点
当前提交
a1fb49756f
共有 5 个文件被更改,包括 60 次插入37 次删除
  1. 二进制
      bin/compiled.zip
  2. 2 33
      src/context.js
  3. 2 1
      src/eberon/eberon_grammar.js
  4. 55 2
      src/ob/ContextType.ob
  5. 1 1
      src/oberon/oberon_grammar.js

二进制
bin/compiled.zip


+ 2 - 33
src/context.js

@@ -680,16 +680,6 @@ exports.ConstDecl = ChainedContext.extend({
     }
 });
 
-function checkIfFieldCanBeExported(name, idents, hint){
-    for(var i = 0; i < idents.length; ++i){
-        var id = idents[i];
-        if (!id.exported())
-            throw new Errors.Error(
-                "field '" + name + "' can be exported only if " + hint + " '" +
-                id.id() + "' itself is exported too");
-    }
-}
-
 exports.VariableDeclaration = HandleSymbolAsType.extend({
     init: function Context$VariableDeclaration(context){
         HandleSymbolAsType.prototype.init.call(this, context);
@@ -698,7 +688,7 @@ exports.VariableDeclaration = HandleSymbolAsType.extend({
     },
     handleIdentdef: function(id){this.__idents.push(id);},
     exportField: function(name){
-        checkIfFieldCanBeExported(name, this.__idents, "variable");
+        ContextType.checkIfFieldCanBeExported(name, this.__idents, "variable");
     },
     setType: function(type){this.__type = type;},
     type: function(){return this.__type;},
@@ -731,27 +721,6 @@ exports.VariableDeclaration = HandleSymbolAsType.extend({
     }
 });
 
-exports.FieldListDeclaration = HandleSymbolAsType.extend({
-    init: function Context$FieldListDeclaration(context){
-        HandleSymbolAsType.prototype.init.call(this, context);
-        this.__idents = [];
-        this.__type = undefined;
-    },
-    typeName: function(){return undefined;},
-    handleIdentdef: function(id) {this.__idents.push(id);},
-    exportField: function(name){
-        checkIfFieldCanBeExported(name, this.__idents, "field");
-    },
-    setType: function(type) {this.__type = type;},
-    isAnonymousDeclaration: function(){return true;},
-    endParse: function(){
-        var idents = this.__idents;
-        var parent = this.parent();
-        for(var i = 0; i < idents.length; ++i)
-            parent.addField(idents[i], this.__type);
-    }
-});
-
 function assertProcType(type, info){
     var unexpected;
     if ( !type )
@@ -811,7 +780,7 @@ exports.TypeDeclaration = ChainedContext.extend({
     isAnonymousDeclaration: function(){return false;},
     type: function(){return this.parent().type();},
     exportField: function(name){
-        checkIfFieldCanBeExported(name, [this.__id], "record");
+        ContextType.checkIfFieldCanBeExported(name, [this.__id], "record");
     }
 });
 

+ 2 - 1
src/eberon/eberon_grammar.js

@@ -4,6 +4,7 @@ var Cast = require("js/EberonCast.js");
 var Context = require("context.js");
 var EbArray = require("js/EberonArray.js");
 var CodeGenerator = require("js/CodeGenerator.js");
+var ContextType = require("js/ContextType.js");
 var EbContext = require("eberon/eberon_context.js");
 var Grammar = require("grammar.js");
 var EbRtl = require("js/EberonRtl.js");
@@ -87,7 +88,7 @@ function makeFieldList(identdef, identList, type, formalParameters){
     return context(
         or(makeMethodHeading(identdef, formalParameters),
                and(identList, ":", type)),
-        Context.FieldListDeclaration);
+        ContextType.FieldList);
 }
 
 function makeFieldListSequence(base){

+ 55 - 2
src/ob/ContextType.ob

@@ -47,16 +47,26 @@ TYPE
 
         PROCEDURE addField(field: Context.PIdentdefInfo; type: Types.PStorageType);
         PROCEDURE setBaseType(type: Types.PType);
+        PROCEDURE generateInheritance(): STRING;
+        PROCEDURE qualifiedBaseConstructor(): STRING;
+
         PROCEDURE doMakeField(field: Context.PIdentdefInfo; type: Types.PStorageType): Types.PField;
         PROCEDURE doGenerateConstructor(): STRING;
-        PROCEDURE generateInheritance(): STRING;
         PROCEDURE doGenerateBaseConstructorCallCode(): STRING;
-        PROCEDURE qualifiedBaseConstructor(): STRING;
 
         declaration: PDeclaration;
         cons: STRING;
         type: R.PType;
     END;
+    PRecord = POINTER TO Record;
+
+    FieldList* = RECORD(Declaration)
+        PROCEDURE handleIdentdef(id: Context.PIdentdefInfo);
+        PROCEDURE typeName(): STRING;
+
+        idents: ARRAY * OF Context.PIdentdefInfo;
+        type: Types.PStorageType;
+    END;
 
 PROCEDURE HandleSymbolAsType.handleQIdent(q: ContextHierarchy.QIdent);
 BEGIN
@@ -304,4 +314,47 @@ BEGIN
         );
 END;
 
+PROCEDURE checkIfFieldCanBeExported*(name: STRING; idents: ARRAY OF Context.PIdentdefInfo; hint: STRING);
+BEGIN
+    FOR i <- 0 TO LEN(idents) - 1 DO
+        id <- idents[i];
+        IF ~id.exported() THEN
+            Errors.raise(
+                "field '" + name + "' can be exported only if " + hint + " '" +
+                id.id() + "' itself is exported too");
+        END;
+    END;
+END;
+
+PROCEDURE FieldList.isAnonymousDeclaration(): BOOLEAN;
+    RETURN TRUE;
+END;
+
+PROCEDURE FieldList.exportField(name: STRING);
+BEGIN
+    checkIfFieldCanBeExported(name, SELF.idents, "field");
+END;
+
+PROCEDURE FieldList.setType(type: Types.PStorageType);
+BEGIN
+    SELF.type := type;    
+END;
+
+PROCEDURE FieldList.handleIdentdef(id: Context.PIdentdefInfo);
+BEGIN
+    SELF.idents.add(id);
+END;
+
+PROCEDURE FieldList.typeName(): STRING;
+    RETURN "";
+END;
+
+PROCEDURE FieldList.endParse();
+BEGIN
+    parent <- SELF.parent()(PRecord);
+    FOR i <- 0 TO LEN(SELF.idents) - 1 DO
+        parent.addField(SELF.idents[i], SELF.type);
+    END;
+END;
+
 END ContextType.

+ 1 - 1
src/oberon/oberon_grammar.js

@@ -66,7 +66,7 @@ function makeProcedureDeclaration(ident, procedureHeading, procedureBody){
 }
 
 function makeFieldList(identdef, identList, type){
-    return context(and(identList, ":", type), Context.FieldListDeclaration);
+    return context(and(identList, ":", type), ContextType.FieldList);
 }
 
 function makeFieldListSequence(base){