Changeset 3857 for devel-tools


Ignore:
Timestamp:
Jul 21, 2008, 5:27:15 PM (12 years ago)
Author:
yura
Message:
  • Const declaration can go in any order. Recursion is error.
Location:
devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/compiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/compiler/ExprChecker.java

    r3856 r3857  
    11package org.refal.rfpdt.compiler;
     2
     3import java.util.HashSet;
    24
    35import org.refal.rfpdt.ast.AstAlt;
     
    5456    }
    5557
    56     private final class ConstChecker implements ExprVisitorWithEnv<ContainerWithVar> {
    57         public void visit (AstCall astCall, ContainerWithVar e) {
     58    private final class ConstChecker implements ExprVisitorWithEnv<Container> {
     59        public void visit (AstCall astCall, Container e) {
    5860            msgHandler.send(astCall.pos, MsgCode.UnexpectedFunctionCallInConst);
    5961            e.noError = false;
    6062        }
    6163
    62         public void visit (AstCharSymbol astCharSymbol, ContainerWithVar e) {}
    63 
    64         public void visit (AstExpr astExpr, ContainerWithVar e) {
    65             ContainerWithVar e1 = new ContainerWithVar();
     64        public void visit (AstCharSymbol astCharSymbol, Container e) {}
     65
     66        public void visit (AstExpr astExpr, Container e) {
     67            Container e1 = new Container();
    6668            for (AstTerm astTerm : astExpr.termList)
    6769                astTerm.accept(this, e1);
     
    6971        }
    7072
    71         public void visit (AstNumberSymbol astNumberSymbol, ContainerWithVar e) {}
    72 
    73         public void visit (AstParen astParen, ContainerWithVar e) {
     73        public void visit (AstNumberSymbol astNumberSymbol, Container e) {}
     74
     75        public void visit (AstParen astParen, Container e) {
    7476            astParen.expr.accept(this, e);
    7577        }
    7678
    77         public void visit (AstRef astRef, ContainerWithVar e) {
     79        public void visit (AstRef astRef, Container e) {
    7880            if (astRef.decl == null)
    7981                e.noError = false;
    80             else if (astRef.decl instanceof AstConstBinding && !((AstConstBinding) astRef.decl).expr.noError) {
    81                 msgHandler.send(astRef.name.pos, MsgCode.UncheckedConstInConst);
    82                 e.noError = false;
     82            else if (astRef.decl instanceof AstConstBinding) {
     83                AstConstBinding astConstBinding = (AstConstBinding) astRef.decl;
     84                if (stackConstBinding.contains(astConstBinding)) {
     85                    msgHandler.send(astRef.name.pos, MsgCode.RecursiveDefinitionInConst);
     86                    e.noError = false;
     87                } else {
     88                    checkAstConstBinding(astConstBinding);
     89                    e.noError &= astConstBinding.expr.noError;                   
     90                }
    8391            }
    8492        }
    8593
    86         public void visit (AstVar astVar, ContainerWithVar e) {
     94        public void visit (AstVar astVar, Container e) {
    8795            msgHandler.send(astVar.pos, MsgCode.UnexpectedVariableInConst);
    8896            e.noError = false;
    8997        }
    9098
    91         public void visit (AstWordSymbol astWordSymbol, ContainerWithVar e) {}
     99        public void visit (AstWordSymbol astWordSymbol, Container e) {}
    92100    }
    93101
     
    194202
    195203    private final MsgHandler msgHandler;
     204   
     205    private final HashSet<AstConstBinding> checkedConstBinding;
     206    private HashSet<AstConstBinding> stackConstBinding;
    196207
    197208    private ExprChecker (final MsgHandler msgHandler) {
    198209        this.msgHandler = msgHandler;
    199     }
    200 
    201     private void checkConst (AstExpr astExpr) {
    202         ContainerWithVar e = new ContainerWithVar();
     210        this.checkedConstBinding = new HashSet<AstConstBinding>();
     211    }
     212
     213    private void checkAstConstBinding (AstConstBinding astConstBinding) {
     214        if (checkedConstBinding.contains(astConstBinding))
     215            return;
     216        stackConstBinding.add(astConstBinding);
     217        AstExpr astExpr = astConstBinding.expr;
     218        Container e = new Container();
    203219        astExpr.accept(new ConstChecker(), e);
    204220        astExpr.noError = e.noError;
     221        checkedConstBinding.add(astConstBinding);
    205222    }
    206223
     
    226243
    227244    public void visit (AstConstBinding astConstBinding) {
    228         checkConst(astConstBinding.expr);
     245        stackConstBinding = new HashSet<AstConstBinding>();
     246        checkAstConstBinding(astConstBinding);
    229247    }
    230248
  • devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/compiler/MsgCode.java

    r3856 r3857  
    4343    TwoOccurrencesOfTheVariable_X_HaveDifferentTypes(Severity.Error,
    4444            "Two occurrences of the variable %s have different types"), //
    45     UncheckedConstInConst(Severity.Error, "Unchecked constant reference in constant expression"), //
     45    RecursiveDefinitionInConst(Severity.Error, "Recursive definition of constant expression"), //
    4646    UnexpectedEndOfComment(Severity.Error, "Unexpected end of comment"), //
    4747    UnexpectedEndOfWord(Severity.Error, "Word literal is not properly closed by a double-quote"), //
Note: See TracChangeset for help on using the changeset viewer.