浏览代码

js -> eberon transition

Vladislav Folts 10 年之前
父节点
当前提交
c9557ea3a1
共有 7 个文件被更改,包括 51 次插入34 次删除
  1. 二进制
      bin/compiled.zip
  2. 0 20
      src/context.js
  3. 2 1
      src/grammar.js
  4. 27 2
      src/ob/ContextDesignator.ob
  5. 13 6
      src/ob/ContextExpression.ob
  6. 1 1
      src/ob/ContextHierarchy.ob
  7. 8 4
      src/ob/ContextType.ob

二进制
bin/compiled.zip


+ 0 - 20
src/context.js

@@ -807,26 +807,6 @@ exports.TypeSection = ChainedContext.extend({
     }
 });
 
-exports.TypeCast = ChainedContext.extend({
-    init: function TypeCastContext(context){
-        ChainedContext.prototype.init.call(this, context);
-        this.__type = undefined;
-    },
-    handleQIdent: function(q){
-        var s = ContextHierarchy.getQIdSymbolAndScope(this.root(), q);
-        s = s.symbol();
-        if (!s.isType())
-            return; // this is not a type cast, may be procedure call
-        this.__type = s.info().type();
-    },
-    endParse: function(){
-        if (this.__type === undefined)
-            return false;
-        this.parent().handleTypeCast(this.__type);
-        return true;
-    }
-});
-
 exports.ModuleDeclaration = ChainedContext.extend({
     init: function ModuleDeclarationContext(context){
         ChainedContext.prototype.init.call(this, context);

+ 2 - 1
src/grammar.js

@@ -1,6 +1,7 @@
 "use strict";
 
 var Context = require("context.js");
+var ContextDesignator = require("js/ContextDesignator.js");
 var ContextExpression = require("js/ContextExpression.js");
 var Lexer = require("js/Lexer.js");
 var Parser = require("parser.js");
@@ -50,7 +51,7 @@ var selector = or(and(point, ident)
                 // break recursive declaration of expList
                 , and("[", function(stream, context){return expList(stream, context);}, "]")
                 , "^"
-                , context(and("(", qualident, ")"), Context.TypeCast)
+                , context(and("(", qualident, ")"), ContextDesignator.TypeCast)
                 );
 var designator = makeDesignator(
         ident,

+ 27 - 2
src/ob/ContextDesignator.ob

@@ -1,7 +1,7 @@
 MODULE ContextDesignator;
 IMPORT
     Code, ConstValue, ContextExpression, ContextHierarchy, 
-    Designator, Errors, Expression, 
+    Designator, Errors, Expression,
     Record, ScopeBase, String, TypeId, Types, Variable;
 TYPE
     Index = RECORD
@@ -34,6 +34,12 @@ TYPE
         indexExpression: Expression.PType;
     END;
 
+    TypeCast* = RECORD(ContextHierarchy.Node)
+        PROCEDURE handleQIdent(q: ContextHierarchy.QIdent);
+
+        type: Types.PType;
+    END;
+
 PROCEDURE Index.Index(length: INTEGER; type: Types.PType; info: Types.PId; code, lval, asProperty: STRING)
     | length(length),
       type(type),
@@ -239,7 +245,7 @@ PROCEDURE Type.doMakeDerefVar(info: Types.PId): Types.PVariable;
    RETURN NEW Variable.DerefVariable(SELF.currentType(Types.PStorageType), SELF.code);
 END;
 
-PROCEDURE Type.endParse();
+PROCEDURE Type.endParse(): BOOLEAN;
 BEGIN
     code <- SELF.code;
     lval <- SELF.lval;
@@ -248,6 +254,25 @@ BEGIN
     END;
     SELF.parent().attributes.designator :=
         NEW Designator.Type(code, lval, SELF.currentType, SELF.info, SELF.scope);
+    RETURN TRUE;
+END;
+
+PROCEDURE TypeCast.handleQIdent(q: ContextHierarchy.QIdent);
+BEGIN
+    info <- ContextHierarchy.getQIdSymbolAndScope(SELF.root()^, q).symbol().info();
+    IF info IS TypeId.PType THEN (* this is a type cast, not a procedure call *)
+        SELF.type := info.type();
+    END;
+END;
+
+PROCEDURE TypeCast.endParse(): BOOLEAN;
+BEGIN
+    result <- FALSE;
+    IF SELF.type # NIL THEN
+        SELF.parent()^(Type).handleTypeCast(SELF.type);
+        result := TRUE;
+    END;
+    RETURN result;
 END;
 
 END ContextDesignator.

+ 13 - 6
src/ob/ContextExpression.ob

@@ -616,7 +616,7 @@ PROCEDURE ExpressionNode.codeGenerator(): CodeGenerator.PIGenerator;
     RETURN CodeGenerator.nullGenerator;
 END;
 
-PROCEDURE ExpressionNode.endParse();
+PROCEDURE ExpressionNode.endParse(): BOOLEAN;
 BEGIN
     notTypeId(SELF.expression);
 
@@ -628,6 +628,8 @@ BEGIN
     parent <- SELF.expressionHandler;
     parent.codeGenerator().write(SELF.expression.code());
     parent.handleExpression(SELF.expression);
+
+    RETURN TRUE;
 END;
 
 PROCEDURE SimpleExpression.SimpleExpression(parent: PExpressionNode)
@@ -695,9 +697,10 @@ BEGIN
     SELF.binaryOperator := o;
 END;
 
-PROCEDURE SimpleExpression.endParse();
+PROCEDURE SimpleExpression.endParse(): BOOLEAN;
 BEGIN
     SELF.parentExpression.handleSimpleExpression(SELF.expression);
+    RETURN TRUE;
 END;
 
 PROCEDURE Factor.handleConst(type: Types.PType; value: ConstValue.PType; code: STRING);
@@ -728,7 +731,7 @@ BEGIN
     SELF.expression := e;
 END;
 
-PROCEDURE Factor.endParse();
+PROCEDURE Factor.endParse(): BOOLEAN;
 BEGIN
     IF SELF.logicalNot THEN
         notTypeId(SELF.expression);
@@ -736,6 +739,7 @@ BEGIN
         SELF.expression := Operator.not(SELF.expression);
     END;
     SELF.parent()^(ExpressionHandler).handleExpression(SELF.expression);
+    RETURN TRUE;
 END;
 
 PROCEDURE Term.type(): Types.PType;
@@ -767,7 +771,7 @@ BEGIN
     END;
 END;
 
-PROCEDURE Term.endParse();
+PROCEDURE Term.endParse(): BOOLEAN;
 VAR
     const: ConstValue.PType;
 BEGIN
@@ -781,6 +785,7 @@ BEGIN
         e := Expression.make(d.code(), d.type(), d, const);
     END;
     SELF.parent()(PSimpleExpression).handleTerm(e);
+    RETURN TRUE;
 END;
 
 PROCEDURE MulOperator.handleLiteral(s: STRING);
@@ -947,9 +952,10 @@ BEGIN
     END;
 END;
 
-PROCEDURE SetElement.endParse();
+PROCEDURE SetElement.endParse(): BOOLEAN;
 BEGIN
     SELF.parent()^(Set).handleElement(SELF);
+    RETURN TRUE;
 END;
 
 PROCEDURE Set.handleElement(s: SetElement);
@@ -974,7 +980,7 @@ BEGIN
     END;
 END;
 
-PROCEDURE Set.endParse();
+PROCEDURE Set.endParse(): BOOLEAN;
 BEGIN
     parent <- SELF.parent()(PFactor);
     IF LEN(SELF.expression) = 0 THEN
@@ -987,6 +993,7 @@ BEGIN
         e <- Expression.makeSimple(code, Types.basic.set);
         parent.handleExpression(e);
     END;
+    RETURN TRUE;
 END;
 
 PROCEDURE IntOpTypeCheck.expect(): STRING;

+ 1 - 1
src/ob/ContextHierarchy.ob

@@ -32,7 +32,7 @@ TYPE
         PROCEDURE handleLiteral*(s: STRING);
         PROCEDURE handleIdent*(s: STRING);
         PROCEDURE genTypeName*(): STRING;
-        PROCEDURE endParse*();
+        PROCEDURE endParse*(): BOOLEAN;
 
         mParent: PNode;
         attributes*: Attributes;

+ 8 - 4
src/ob/ContextType.ob

@@ -149,9 +149,10 @@ PROCEDURE Array.doMakeType(elementsType: Types.PType; init: STRING; length: INTE
     RETURN SELF.root().language().types.makeStaticArray(elementsType, init, length);
 END;
 
-PROCEDURE Array.endParse();
+PROCEDURE Array.endParse(): BOOLEAN;
 BEGIN
     SELF.handleType.setType(SELF.type);
+    RETURN TRUE;
 END;
 
 PROCEDURE ArrayDimensions.handleExpression(e: Expression.PType);
@@ -180,9 +181,10 @@ PROCEDURE ArrayDimensions.codeGenerator(): CodeGenerator.PIGenerator;
     RETURN CodeGenerator.nullGenerator;
 END;
 
-PROCEDURE ArrayDimensions.endParse();
+PROCEDURE ArrayDimensions.endParse(): BOOLEAN;
 BEGIN
     SELF.parent()^(Array).dimensions := SELF(POINTER);
+    RETURN TRUE;
 END;
 
 PROCEDURE isTypeRecursive(type, base: Types.PType): BOOLEAN;
@@ -306,12 +308,13 @@ BEGIN
     RETURN result;
 END;
 
-PROCEDURE Record.endParse();
+PROCEDURE Record.endParse(): BOOLEAN;
 BEGIN
     SELF.codeGenerator().write(
           SELF.doGenerateConstructor()
         + SELF.generateInheritance()
         );
+    RETURN TRUE;
 END;
 
 PROCEDURE checkIfFieldCanBeExported*(name: STRING; idents: ARRAY OF Context.PIdentdefInfo; hint: STRING);
@@ -349,12 +352,13 @@ PROCEDURE FieldList.typeName(): STRING;
     RETURN "";
 END;
 
-PROCEDURE FieldList.endParse();
+PROCEDURE FieldList.endParse(): BOOLEAN;
 BEGIN
     parent <- SELF.parent()(PRecord);
     FOR i <- 0 TO LEN(SELF.idents) - 1 DO
         parent.addField(SELF.idents[i], SELF.type);
     END;
+    RETURN TRUE;
 END;
 
 END ContextType.