Quellcode durchsuchen

expression parsing refactoring

Vladislav Folts vor 9 Jahren
Ursprung
Commit
b67fd7a2d8

BIN
bin/compiled.zip


+ 4 - 4
src/eberon/EberonContextDesignator.ob

@@ -57,9 +57,9 @@ TYPE
     END;
 
     TransferPromotedTypesMsg* = RECORD(ContextHierarchy.Message)
-        PROCEDURE TransferPromotedTypesMsg*(p: EberonTypePromotion.PCombined); 
+        PROCEDURE TransferPromotedTypesMsg*(p: EberonTypePromotion.PType); 
 
-        promotion: EberonTypePromotion.PCombined;
+        promotion-: EberonTypePromotion.PType;
     END;
 
     GetMethodSelfMsg* = RECORD(ContextHierarchy.Message)
@@ -162,7 +162,7 @@ PROCEDURE breakTypePromotion*(VAR msg: ContextHierarchy.Message): BOOLEAN;
 BEGIN
     result <- FALSE;
     IF msg IS TransferPromotedTypesMsg THEN
-        msg.promotion.clear();
+        msg.promotion.reset();
         result := TRUE;
     END;
     RETURN result;
@@ -418,7 +418,7 @@ PROCEDURE OperatorNewMsg.OperatorNewMsg(e: Expression.PType)
     | expression(e);
 END;
 
-PROCEDURE TransferPromotedTypesMsg.TransferPromotedTypesMsg(p: EberonTypePromotion.PCombined)
+PROCEDURE TransferPromotedTypesMsg.TransferPromotedTypesMsg(p: EberonTypePromotion.PType)
     | promotion(p); 
 END;
 

+ 11 - 37
src/eberon/EberonContextExpression.ob

@@ -67,12 +67,6 @@ TYPE
         termList: PTermList;
     END;
 
-    ExpressionTypePromotion* = RECORD(ContextHierarchy.Message)
-        PROCEDURE ExpressionTypePromotion(typePromotion: EberonTypePromotion.PType);
-
-        typePromotion-: EberonTypePromotion.PType;
-    END;         
-
 VAR
     setTermTypePromotion: PROCEDURE(VAR term: TermList): EberonTypePromotion.PMaybe;
     globalOps: POINTER TO Ops;
@@ -181,17 +175,6 @@ PROCEDURE RelationExpression.RelationExpression(parent: ContextExpression.PExpre
     | SUPER(parent, NEW Node(parentTerm(parent^)));
 END;
 
-PROCEDURE RelationExpression.handleMessage(VAR msg: ContextHierarchy.Message): Object.PType;
-VAR
-    result: Object.PType;
-BEGIN
-    IF msg IS EberonContextDesignator.TransferPromotedTypesMsg THEN
-    ELSE
-        result := SUPER(msg);
-    END;
-    RETURN result;
-END;
-
 PROCEDURE Ops.in(left, right: Types.PType; cx: ContextHierarchy.Node): ExpressionTree.BinaryOperatorCx;
 VAR
     result: ExpressionTree.BinaryOperatorCx;
@@ -206,25 +189,20 @@ BEGIN
 END;
 
 PROCEDURE RelationExpression.endParse(): BOOLEAN;
+VAR
+    typePromotion: EberonTypePromotion.PType;
 BEGIN
     node <- SELF.node(PNode); 
-    IF node.combinedTypePromotion # NIL THEN
-        msg <- EberonContextDesignator.TransferPromotedTypesMsg(node.combinedTypePromotion);
-        void <- SELF.parent().handleMessage(msg);
-    END;
-    IF node.varTypePromotion # NIL THEN
-        msg <- ExpressionTypePromotion(node.varTypePromotion);
-        void <- SELF.parent().handleMessage(msg);
-    END;
-    RETURN SUPER();
-END;
+    IF node.parentTerm = NIL THEN 
+        typePromotion := node.combinedTypePromotion;
+        IF typePromotion = NIL THEN
+            typePromotion := node.varTypePromotion;
+        END;
 
-PROCEDURE SimpleExpression.endParse(): BOOLEAN;
-BEGIN
-    s <- SELF.list(PSimpleList);
-    IF (s.parentTerm = NIL) & (s.typePromotion # NIL) THEN 
-        msg <- ExpressionTypePromotion(s.typePromotion);
-        void <- SELF.parent().handleMessage(msg);
+        IF typePromotion # NIL THEN
+            msg <- EberonContextDesignator.TransferPromotedTypesMsg(typePromotion);
+            void <- SELF.parent().handleMessage(msg);
+        END;
     END;
     RETURN SUPER();
 END;
@@ -463,10 +441,6 @@ BEGIN
     END;
 END;
 
-PROCEDURE ExpressionTypePromotion.ExpressionTypePromotion(typePromotion: EberonTypePromotion.PType)
-    | typePromotion(typePromotion);
-END;
-
 BEGIN
     (*resolve recursive calls*)
     setTermTypePromotion := setTermTypePromotionProc;

+ 2 - 9
src/eberon/EberonContextProcedure.ob

@@ -3,7 +3,7 @@ IMPORT
     Chars, CodeGenerator,
     Context, ContextDesignator, ContextExpression, ContextHierarchy, ContextModule, 
     ContextProcedure, ContextType, 
-    EberonConstructor, EberonContext, EberonContextDesignator, EberonContextExpression, 
+    EberonConstructor, EberonContext, EberonContextDesignator, 
     EberonDynamicArray, EberonMap, EberonRecord, EberonTypes,
     Errors, Expression, ExpressionTree, LanguageContext, Object, Procedure, Record, Types, Variable;
 TYPE
@@ -111,14 +111,7 @@ BEGIN
 END;
 
 PROCEDURE handleTypePromotionMadeInSeparateStatement(VAR msg: ContextHierarchy.Message): BOOLEAN;
-BEGIN
-    result <- FALSE;
-    IF EberonContextDesignator.breakTypePromotion(msg) THEN
-        result := TRUE;
-    ELSIF msg IS EberonContextExpression.ExpressionTypePromotion THEN
-        result := TRUE;
-    END
-    RETURN result;
+    RETURN EberonContextDesignator.breakTypePromotion(msg);
 END;
 
 PROCEDURE ProcOrMethodDeclaration.handleMessage(VAR msg: ContextHierarchy.Message): Object.PType;

+ 2 - 4
src/eberon/EberonContextTypePromotion.ob

@@ -1,7 +1,7 @@
 MODULE EberonContextTypePromotion;
 IMPORT
     ContextHierarchy, 
-    EberonContextDesignator, EberonContextExpression,
+    EberonContextDesignator,
     EberonTypePromotion;
 TYPE
     Type* = RECORD
@@ -22,9 +22,7 @@ BEGIN
 
     IF SELF.ignorePromotions THEN
     ELSIF msg IS EberonContextDesignator.TransferPromotedTypesMsg THEN
-        result := TRUE;
-    ELSIF msg IS EberonContextExpression.ExpressionTypePromotion THEN
-        SELF.typePromotion := msg.typePromotion;
+        SELF.typePromotion := msg.promotion;
         SELF.typePromotions.add(SELF.typePromotion);
         result := TRUE;
     END;

+ 1 - 1
src/ob/ContextExpression.ob

@@ -13,7 +13,7 @@ TYPE
         PROCEDURE SimpleExpression*(parent: ContextHierarchy.PNode); 
         PROCEDURE handleOperator*(op: STRING);
 
-        list-: ExpressionTree.PSimpleList;
+        list: ExpressionTree.PSimpleList;
     END;
     PSimpleExpression = POINTER TO SimpleExpression;