Class TypeChecker
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.smtlib.IVisitor
IVisitor.TreeVisitor<T>, IVisitor.VisitorException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<IExpr.ISymbol, TypeChecker.Variable> protected List<Map<IExpr.ISymbol, TypeChecker.Variable>> protected IExprThe body of the innermost quantifier being checked (the only place a :pattern may appear), or null.Compilation of errors -
Constructor Summary
ConstructorsConstructorDescriptionTypeChecker(SymbolTable symTable) Constructs a formula typechecker from the current symbol table; sorts computed while checking are recorded directly on each IExpr node via IExpr.setSort(). -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanReports a symbol that is not legal (see SMT.Configuration.isOKSymbol), which only the API (or declare-fun's name) can produce; returns true if it is not legalcheck(SymbolTable symTable, IExpr expr) The main entry point for type-checking an IExpr (expected to be a Bool)checkAssertion(SymbolTable symTable, IExpr expr) The main entry point for type-checking an assert expression (expected to be a Bool); unlikecheck(SymbolTable,IExpr), this checks the expression within a pushed scope that is merged into the enclosing scope on success (or popped on error).checkFcn(SymbolTable symTable, IExpr.IIdentifier id, List<IExpr.IDeclaration> params, ISort result, IExpr expr) checkFcn(SymbolTable symTable, IExpr.IIdentifier id, List<ISort> sorts, ISort result, IPos pos) checkFcnRec(SymbolTable symTable, boolean global, IExpr.ISymbol id, List<IExpr.IDeclaration> params, ISort result, IExpr expr) Type-checks a define-fun-rec command: verifies the symbol is new, validates sorts, pre-adds the function to the symbol table so the body may call it recursively, then checks the body expression.checkFcnsRec(SymbolTable symTable, boolean global, List<IExpr.IFunctionDeclaration> decls, List<IExpr> bodies) Type-checks a define-funs-rec command: for each declaration verifies the symbol is new and sorts are valid, pre-adds all functions to the symbol table for mutual recursion, then checks each body expression.protected booleanChecks that a pattern term is binder-free and has no annotations (SMT-LIB 2.7, Section 3.6.5); returns false, recording an error, if it is not.checkSortAbbreviation(SymbolTable symTable, IExpr.IIdentifier id, List<ISort.IParameter> params, ISort expr) checkTerm(SymbolTable symTable, IExpr expr) Type-checks a term of any sort (e.g.static voidclearSorts(IExpr expr) Walks the given expression subtree, nulling out the sort recorded on each node (e.g.protected voidUtility method for recording an errorprotected booleannoVariables(List<?> list, String binder, IPos pos) Reports a binder with no variables; returns true if the list is emptyprotected StringUtility method for printing an expression, using the default printerprotected StringUtility method for printing a sort, using the default printerstatic ISort.IFcnSortresolveFcnSort(SymbolTable symTable, IExpr.IIdentifier id, List<ISort> sorts, ISort result, IPos pos, List<IResponse> errors) Checks a function signature as checkFcn does, adding any errors to errors; returns the signature with its sorts resolved in the current scope (so a sort parameter in scope becomes its IParameter), or null if there were errors.protected booleanshadowsLogic(IExpr.ISymbol s, boolean sort) Reports a bound variable (sort parameter, if sort is true) with the name of a function (sort) symbol of the logic or its theories, which only --relax allows (SMT-LIB Remark 7); returns true if reportedvalidate(SMT.Configuration smtConfig, ICommand cmd) Validates non-syntactic well-formedness of a command (user IDs, duplicate names, list sizes).validateDatatypeNames(SymbolTable symTable, SMT.Configuration smtConfig, List<IExpr.ISortDeclaration> sortDecls, List<ISort.IDatatype> datatypes) Checks that constructor and selector names introduced by a datatype group are not already defined (neither in the symbol table nor duplicated within the group).visit(IExpr.IAttribute<?> e) Type-checks a lambda expression:(lambda (sorted_var+) term), SMT-LIB 2.7ff (the optional HO-Core theory -- seeSMT/logics/HO-Core.smt2).visit(IExpr.ILet e) visit(ISexpr.ISeq e) visit(ISexpr.IToken<?> e)
-
Field Details
-
result
Compilation of errors -
quantifierBody
The body of the innermost quantifier being checked (the only place a :pattern may appear), or null. -
currentScope
-
parameters
-
-
Constructor Details
-
TypeChecker
Constructs a formula typechecker from the current symbol table; sorts computed while checking are recorded directly on each IExpr node via IExpr.setSort().
-
-
Method Details
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
error
Utility method for recording an error -
badSymbol
Reports a symbol that is not legal (see SMT.Configuration.isOKSymbol), which only the API (or declare-fun's name) can produce; returns true if it is not legal -
shadowsLogic
Reports a bound variable (sort parameter, if sort is true) with the name of a function (sort) symbol of the logic or its theories, which only --relax allows (SMT-LIB Remark 7); returns true if reported -
noVariables
Reports a binder with no variables; returns true if the list is empty -
pr
Utility method for printing an expression, using the default printer -
pr
Utility method for printing a sort, using the default printer -
checkSortAbbreviation
public static List<IResponse> checkSortAbbreviation(SymbolTable symTable, IExpr.IIdentifier id, List<ISort.IParameter> params, ISort expr) -
checkFcn
public static List<IResponse> checkFcn(SymbolTable symTable, IExpr.IIdentifier id, List<ISort> sorts, ISort result, IPos pos) -
resolveFcnSort
public static ISort.IFcnSort resolveFcnSort(SymbolTable symTable, IExpr.IIdentifier id, List<ISort> sorts, ISort result, IPos pos, List<IResponse> errors) Checks a function signature as checkFcn does, adding any errors to errors; returns the signature with its sorts resolved in the current scope (so a sort parameter in scope becomes its IParameter), or null if there were errors. -
checkFcn
public static List<IResponse> checkFcn(SymbolTable symTable, IExpr.IIdentifier id, List<IExpr.IDeclaration> params, ISort result, IExpr expr) -
checkFcnRec
public static List<IResponse> checkFcnRec(SymbolTable symTable, boolean global, IExpr.ISymbol id, List<IExpr.IDeclaration> params, ISort result, IExpr expr) Type-checks a define-fun-rec command: verifies the symbol is new, validates sorts, pre-adds the function to the symbol table so the body may call it recursively, then checks the body expression. On success the entry's definition is set. Delegates to checkFcnsRec as the N=1 case (a singleton declaration group). -
checkFcnsRec
public static List<IResponse> checkFcnsRec(SymbolTable symTable, boolean global, List<IExpr.IFunctionDeclaration> decls, List<IExpr> bodies) Type-checks a define-funs-rec command: for each declaration verifies the symbol is new and sorts are valid, pre-adds all functions to the symbol table for mutual recursion, then checks each body expression. On success all entries' definitions are set. -
check
The main entry point for type-checking an IExpr (expected to be a Bool) -
checkTerm
Type-checks a term of any sort (e.g. a get-value term) and checks it against the logic in use, if any. -
checkAssertion
The main entry point for type-checking an assert expression (expected to be a Bool); unlikecheck(SymbolTable,IExpr), this checks the expression within a pushed scope that is merged into the enclosing scope on success (or popped on error). -
save
-
clearSorts
Walks the given expression subtree, nulling out the sort recorded on each node (e.g. because it is leaving the live assertion set, on pop or reset-assertions).- Throws:
IVisitor.VisitorException
-
visit
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
-
visit
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
-
visit
-
visit
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
checkPatternTerm
Checks that a pattern term is binder-free and has no annotations (SMT-LIB 2.7, Section 3.6.5); returns false, recording an error, if it is not. -
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
Type-checks a lambda expression:(lambda (sorted_var+) term), SMT-LIB 2.7ff (the optional HO-Core theory -- seeSMT/logics/HO-Core.smt2).Parameter/body scoping is identical to visit(IForall)/visit(IExists) above: push a new scope, type-check each parameter declaration into it (catching duplicate names), then type-check the body in that scope. Unlike a quantifier, though, a lambda's body is not required to be Bool -- it can be any sort -- and the lambda expression's own computed sort is not its body's sort but the function sort mapping its parameters' sorts to its body's sort.
Design decision (see jSMTLIB issue #125): SMT-LIB 2.7 also introduces a
(-> sort+ sort)function-sort constructor for exactly this purpose, and that constructor already exists in this codebase -- not as new work for lambda, but as an ordinary theory-declared sort: HO-Core.smt2 declares:sorts ( (-> 2 :right-assoc) ), so->is a plain 2-ary sort family, resolved through the same generic path as any other declared sort (visit(ISort.IApplication) already has a special case unfolding->via its :right-assoc attribute when given more than its declared arity of 2 arguments -- see the comment there). So rather than fabricating a placeholder sort (e.g. just the body's sort) or throwing a not-yet-supported error, this builds an (unchecked)(-> paramSort1 ... paramSortN bodySort)sort-application node and runs it through this same type checker, exactly the way makeBitVec()/makeFloatingPoint()/makeReal() above already construct-then-check a sort expression rather than hand-building one. Two honest, non-fabricated outcomes follow directly from reusing that existing machinery, with no new logic of its own:- If the active logic/theory declares
->(i.e. HO-Core is loaded, as with(set-logic ALL)), the lambda's sort is the real, correctly-computed function sort -- e.g.(-> Int Int)for(lambda ((x Int)) (+ x 1)). - If it does not, this reports the same "No such sort symbol declared: ->" error that any other undeclared sort symbol would get -- exactly like using any other theory-specific symbol without its theory loaded, not a crash or a silently-wrong sort.
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
- If the active logic/theory declares
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
visit
- Specified by:
visitin interfaceIVisitor<ISort>- Throws:
IVisitor.VisitorException
-
validate
Validates non-syntactic well-formedness of a command (user IDs, duplicate names, list sizes). Returns a list of errors; an empty list means the command is well-formed. -
validateDatatypeNames
public static List<IResponse> validateDatatypeNames(SymbolTable symTable, SMT.Configuration smtConfig, List<IExpr.ISortDeclaration> sortDecls, List<ISort.IDatatype> datatypes) Checks that constructor and selector names introduced by a datatype group are not already defined (neither in the symbol table nor duplicated within the group). Returns any errors found; empty list means all names are fresh.
-