Changeset 3856 for devel-tools


Ignore:
Timestamp:
Jul 18, 2008, 11:49:13 PM (12 years ago)
Author:
yura
Message:
  • Constant expression checker is added (if next expression has reference to previous then error - must be corrected).
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

    r3846 r3856  
    5454    }
    5555
     56    private final class ConstChecker implements ExprVisitorWithEnv<ContainerWithVar> {
     57        public void visit (AstCall astCall, ContainerWithVar e) {
     58            msgHandler.send(astCall.pos, MsgCode.UnexpectedFunctionCallInConst);
     59            e.noError = false;
     60        }
     61
     62        public void visit (AstCharSymbol astCharSymbol, ContainerWithVar e) {}
     63
     64        public void visit (AstExpr astExpr, ContainerWithVar e) {
     65            ContainerWithVar e1 = new ContainerWithVar();
     66            for (AstTerm astTerm : astExpr.termList)
     67                astTerm.accept(this, e1);
     68            e.noError &= e1.noError;
     69        }
     70
     71        public void visit (AstNumberSymbol astNumberSymbol, ContainerWithVar e) {}
     72
     73        public void visit (AstParen astParen, ContainerWithVar e) {
     74            astParen.expr.accept(this, e);
     75        }
     76
     77        public void visit (AstRef astRef, ContainerWithVar e) {
     78            if (astRef.decl == null)
     79                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;
     83            }
     84        }
     85
     86        public void visit (AstVar astVar, ContainerWithVar e) {
     87            msgHandler.send(astVar.pos, MsgCode.UnexpectedVariableInConst);
     88            e.noError = false;
     89        }
     90
     91        public void visit (AstWordSymbol astWordSymbol, ContainerWithVar e) {}
     92    }
     93
    5694    private final class FormatChecker implements ExprVisitorWithEnv<ContainerWithVar> {
    5795        public void visit (AstCall astCall, ContainerWithVar e) {
     
    161199    }
    162200
     201    private void checkConst (AstExpr astExpr) {
     202        ContainerWithVar e = new ContainerWithVar();
     203        astExpr.accept(new ConstChecker(), e);
     204        astExpr.noError = e.noError;
     205    }
     206
    163207    private void checkFormat (AstExpr astExpr) {
    164208        ContainerWithVar e = new ContainerWithVar();
     
    182226
    183227    public void visit (AstConstBinding astConstBinding) {
    184         checkFormat(astConstBinding.expr);
     228        checkConst(astConstBinding.expr);
    185229    }
    186230
  • devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/compiler/MsgCode.java

    r3566 r3856  
    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"), //
    4546    UnexpectedEndOfComment(Severity.Error, "Unexpected end of comment"), //
    4647    UnexpectedEndOfWord(Severity.Error, "Word literal is not properly closed by a double-quote"), //
    4748    UnexpectedEndOfCharacters(Severity.Error, "Characters literal is not properly closed by a single-quote"), //
     49    UnexpectedFunctionCallInConst(Severity.Error, "Unexpected function call in constant expression"), //
    4850    UnexpectedFunctionCallInFormat(Severity.Error, "Unexpected function call in format"), //
    4951    UnexpectedFunctionCallInPattern(Severity.Error, "Unexpected function call in pattern"), //
    5052    UnexpectedToken(Severity.Error, "Unexpected token %s"), //
     53    UnexpectedVariableInConst(Severity.Error, "Unexpected variable in constant expression"), //
    5154    // UnexpectedEOFInCharacterString(Severity.Error, "Unexpected EOF in character string"), //
    5255    // UnexpectedEOFInWord(Severity.Error, "Unexpected EOF in word"), //
Note: See TracChangeset for help on using the changeset viewer.