GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/parser/parser.h Lines: 23 33 69.7 %
Date: 2021-05-22 Branches: 1 6 16.7 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Morgan Deters, Christopher L. Conway
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * A collection of state for use by parser implementations.
14
 */
15
16
#include "cvc5parser_public.h"
17
18
#ifndef CVC5__PARSER__PARSER_H
19
#define CVC5__PARSER__PARSER_H
20
21
#include <list>
22
#include <memory>
23
#include <set>
24
#include <string>
25
26
#include "api/cpp/cvc5.h"
27
#include "cvc5_export.h"
28
#include "expr/kind.h"
29
#include "expr/symbol_manager.h"
30
#include "expr/symbol_table.h"
31
#include "parser/input.h"
32
#include "parser/parse_op.h"
33
#include "parser/parser_exception.h"
34
#include "util/unsafe_interrupt_exception.h"
35
36
namespace cvc5 {
37
38
// Forward declarations
39
class Command;
40
class ResourceManager;
41
42
namespace parser {
43
44
class Input;
45
46
/** Types of checks for the symbols */
47
enum DeclarationCheck {
48
  /** Enforce that the symbol has been declared */
49
  CHECK_DECLARED,
50
  /** Enforce that the symbol has not been declared */
51
  CHECK_UNDECLARED,
52
  /** Don't check anything */
53
  CHECK_NONE
54
};/* enum DeclarationCheck */
55
56
/**
57
 * Returns a string representation of the given object (for
58
 * debugging).
59
 */
60
inline std::ostream& operator<<(std::ostream& out, DeclarationCheck check);
61
inline std::ostream& operator<<(std::ostream& out, DeclarationCheck check) {
62
  switch(check) {
63
  case CHECK_NONE:
64
    return out << "CHECK_NONE";
65
  case CHECK_DECLARED:
66
    return out << "CHECK_DECLARED";
67
  case CHECK_UNDECLARED:
68
    return out << "CHECK_UNDECLARED";
69
  default:
70
    return out << "DeclarationCheck!UNKNOWN";
71
  }
72
}
73
74
/**
75
 * Types of symbols. Used to define namespaces.
76
 */
77
enum SymbolType {
78
  /** Variables */
79
  SYM_VARIABLE,
80
  /** Sorts */
81
  SYM_SORT
82
};/* enum SymbolType */
83
84
/**
85
 * Returns a string representation of the given object (for
86
 * debugging).
87
 */
88
inline std::ostream& operator<<(std::ostream& out, SymbolType type);
89
inline std::ostream& operator<<(std::ostream& out, SymbolType type) {
90
  switch(type) {
91
  case SYM_VARIABLE:
92
    return out << "SYM_VARIABLE";
93
  case SYM_SORT:
94
    return out << "SYM_SORT";
95
  default:
96
    return out << "SymbolType!UNKNOWN";
97
  }
98
}
99
100
/**
101
 * This class encapsulates all of the state of a parser, including the
102
 * name of the file, line number and column information, and in-scope
103
 * declarations.
104
 */
105
class CVC5_EXPORT Parser
106
{
107
  friend class ParserBuilder;
108
private:
109
110
 /** The input that we're parsing. */
111
 std::unique_ptr<Input> d_input;
112
113
 /**
114
  * Reference to the symbol manager, which manages the symbol table used by
115
  * this parser.
116
  */
117
 SymbolManager* d_symman;
118
119
 /**
120
  * This current symbol table used by this parser, from symbol manager.
121
  */
122
 SymbolTable* d_symtab;
123
124
 /**
125
  * The level of the assertions in the declaration scope.  Things declared
126
  * after this level are bindings from e.g. a let, a quantifier, or a
127
  * lambda.
128
  */
129
 size_t d_assertionLevel;
130
131
 /** How many anonymous functions we've created. */
132
 size_t d_anonymousFunctionCount;
133
134
 /** Are we done */
135
 bool d_done;
136
137
 /** Are semantic checks enabled during parsing? */
138
 bool d_checksEnabled;
139
140
 /** Are we parsing in strict mode? */
141
 bool d_strictMode;
142
143
 /** Are we only parsing? */
144
 bool d_parseOnly;
145
146
 /**
147
  * Can we include files?  (Set to false for security purposes in
148
  * e.g. the online version.)
149
  */
150
 bool d_canIncludeFile;
151
152
 /**
153
  * Whether the logic has been forced with --force-logic.
154
  */
155
 bool d_logicIsForced;
156
157
 /**
158
  * The logic, if d_logicIsForced == true.
159
  */
160
 std::string d_forcedLogic;
161
162
 /** The set of operators available in the current logic. */
163
 std::set<api::Kind> d_logicOperators;
164
165
 /** The set of attributes already warned about. */
166
 std::set<std::string> d_attributesWarnedAbout;
167
168
 /**
169
  * The current set of unresolved types.  We can get by with this NOT
170
  * being on the scope, because we can only have one DATATYPE
171
  * definition going on at one time.  This is a bit hackish; we
172
  * depend on mkMutualDatatypeTypes() to check everything and clear
173
  * this out.
174
  */
175
 std::set<api::Sort> d_unresolved;
176
177
 /**
178
  * "Preemption commands": extra commands implied by subterms that
179
  * should be issued before the currently-being-parsed command is
180
  * issued.  Used to support SMT-LIBv2 ":named" attribute on terms.
181
  *
182
  * Owns the memory of the Commands in the queue.
183
  */
184
 std::list<Command*> d_commandQueue;
185
186
 /** Lookup a symbol in the given namespace (as specified by the type).
187
  * Only returns a symbol if it is not overloaded, returns null otherwise.
188
  */
189
 api::Term getSymbol(const std::string& var_name, SymbolType type);
190
191
protected:
192
 /** The API Solver object. */
193
 api::Solver* d_solver;
194
195
 /**
196
  * Create a parser state.
197
  *
198
  * @attention The parser takes "ownership" of the given
199
  * input and will delete it on destruction.
200
  *
201
  * @param solver solver API object
202
  * @param symm reference to the symbol manager
203
  * @param input the parser input
204
  * @param strictMode whether to incorporate strict(er) compliance checks
205
  * @param parseOnly whether we are parsing only (and therefore certain checks
206
  * need not be performed, like those about unimplemented features, @see
207
  * unimplementedFeature())
208
  */
209
 Parser(api::Solver* solver,
210
        SymbolManager* sm,
211
        bool strictMode = false,
212
        bool parseOnly = false);
213
214
public:
215
216
  virtual ~Parser();
217
218
  /** Get the associated solver. */
219
  api::Solver* getSolver() const;
220
221
  /** Get the associated input. */
222
98
  Input* getInput() const { return d_input.get(); }
223
224
  /** Get unresolved sorts */
225
  inline std::set<api::Sort>& getUnresolvedSorts() { return d_unresolved; }
226
227
  /** Deletes and replaces the current parser input. */
228
6175
  void setInput(Input* input)  {
229
6175
    d_input.reset(input);
230
6175
    d_input->setParser(*this);
231
6175
    d_done = false;
232
6175
  }
233
234
  /**
235
   * Check if we are done -- either the end of input has been reached, or some
236
   * error has been encountered.
237
   * @return true if parser is done
238
   */
239
488
  inline bool done() const {
240
488
    return d_done;
241
  }
242
243
  /** Sets the done flag */
244
298958
  inline void setDone(bool done = true) {
245
298958
    d_done = done;
246
298958
  }
247
248
  /** Enable semantic checks during parsing. */
249
6147
  void enableChecks() { d_checksEnabled = true; }
250
251
  /** Disable semantic checks during parsing. Disabling checks may lead to crashes on bad inputs. */
252
  void disableChecks() { d_checksEnabled = false; }
253
254
  /** Enable strict parsing, according to the language standards. */
255
  void enableStrictMode() { d_strictMode = true; }
256
257
  /** Disable strict parsing. Allows certain syntactic infelicities to
258
      pass without comment. */
259
  void disableStrictMode() { d_strictMode = false; }
260
261
4183211
  bool strictModeEnabled() { return d_strictMode; }
262
263
6147
  void allowIncludeFile() { d_canIncludeFile = true; }
264
  void disallowIncludeFile() { d_canIncludeFile = false; }
265
7
  bool canIncludeFile() const { return d_canIncludeFile; }
266
267
  /** Expose the functionality from SMT/SMT2 parsers, while making
268
      implementation optional by returning false by default. */
269
  virtual bool logicIsSet() { return false; }
270
271
  virtual void forceLogic(const std::string& logic);
272
273
8
  const std::string& getForcedLogic() const { return d_forcedLogic; }
274
5132
  bool logicIsForced() const { return d_logicIsForced; }
275
276
  /**
277
   * Gets the variable currently bound to name.
278
   *
279
   * @param name the name of the variable
280
   * @return the variable expression
281
   * Only returns a variable if its name is not overloaded, returns null otherwise.
282
   */
283
  api::Term getVariable(const std::string& name);
284
285
  /**
286
   * Gets the function currently bound to name.
287
   *
288
   * @param name the name of the variable
289
   * @return the variable expression
290
   * Only returns a function if its name is not overloaded, returns null otherwise.
291
   */
292
  api::Term getFunction(const std::string& name);
293
294
  /**
295
   * Returns the expression that name should be interpreted as, based on the current binding.
296
   *
297
   * The symbol name should be declared.
298
   * This creates the expression that the string "name" should be interpreted as.
299
   * Typically this corresponds to a variable, but it may also correspond to
300
   * a nullary constructor or a defined function.
301
   * Only returns an expression if its name is not overloaded, returns null otherwise.
302
   */
303
  virtual api::Term getExpressionForName(const std::string& name);
304
305
  /**
306
   * Returns the expression that name should be interpreted as, based on the current binding.
307
   *
308
   * This is the same as above but where the name has been type cast to t.
309
   */
310
  virtual api::Term getExpressionForNameAndType(const std::string& name,
311
                                                api::Sort t);
312
313
  /**
314
   * If this method returns true, then name is updated with the tester name
315
   * for constructor cons.
316
   *
317
   * In detail, notice that (user-defined) datatypes associate a unary predicate
318
   * for each constructor, called its "tester". This symbol is automatically
319
   * defined when a datatype is defined. The tester name for a constructor
320
   * (e.g. "cons") depends on the language:
321
   * - In smt versions < 2.6, the (non-standard) syntax is "is-cons",
322
   * - In smt versions >= 2.6, the indexed symbol "(_ is cons)" is used. Thus,
323
   * no tester symbol is necessary, since "is" is a builtin symbol. We still use
324
   * the above syntax if strict mode is disabled.
325
   * - In cvc, the syntax for testers is "is_cons".
326
   */
327
  virtual bool getTesterName(api::Term cons, std::string& name);
328
329
  /**
330
   * Returns the kind that should be used for applications of expression fun.
331
   * This is a generalization of ExprManager::operatorToKind that also
332
   * handles variables whose types are "function-like", i.e. where
333
   * checkFunctionLike(fun) returns true.
334
   *
335
   * For examples of the latter, this function returns
336
   *   APPLY_UF if fun has function type,
337
   *   APPLY_CONSTRUCTOR if fun has constructor type.
338
   */
339
  api::Kind getKindForFunction(api::Term fun);
340
341
  /**
342
   * Returns a sort, given a name.
343
   * @param sort_name the name to look up
344
   */
345
  api::Sort getSort(const std::string& sort_name);
346
347
  /**
348
   * Returns a (parameterized) sort, given a name and args.
349
   */
350
  api::Sort getSort(const std::string& sort_name,
351
                    const std::vector<api::Sort>& params);
352
353
  /**
354
   * Returns arity of a (parameterized) sort, given a name and args.
355
   */
356
  size_t getArity(const std::string& sort_name);
357
358
  /**
359
   * Checks if a symbol has been declared.
360
   * @param name the symbol name
361
   * @param type the symbol type
362
   * @return true iff the symbol has been declared with the given type
363
   */
364
  bool isDeclared(const std::string& name, SymbolType type = SYM_VARIABLE);
365
366
  /**
367
   * Checks if the declaration policy we want to enforce holds
368
   * for the given symbol.
369
   * @param name the symbol to check
370
   * @param check the kind of check to perform
371
   * @param type the type of the symbol
372
   * @param notes notes to add to a parse error (if one is generated)
373
   * @throws ParserException if checks are enabled and the check fails
374
   */
375
  void checkDeclaration(const std::string& name,
376
                        DeclarationCheck check,
377
                        SymbolType type = SYM_VARIABLE,
378
                        std::string notes = "");
379
380
  /**
381
   * Checks whether the given expression is function-like, i.e.
382
   * it expects arguments. This is checked by looking at the type
383
   * of fun. Examples of function types are function, constructor,
384
   * selector, tester.
385
   * @param fun the expression to check
386
   * @throws ParserException if checks are enabled and fun is not
387
   * a function
388
   */
389
  void checkFunctionLike(api::Term fun);
390
391
  /** Create a new cvc5 variable expression of the given type.
392
   *
393
   * It is inserted at context level zero in the symbol table if levelZero is
394
   * true, or if we are using global declarations.
395
   *
396
   * If a symbol with name already exists,
397
   *  then if doOverload is true, we create overloaded operators.
398
   *  else if doOverload is false, the existing expression is shadowed by the
399
   * new expression.
400
   */
401
  api::Term bindVar(const std::string& name,
402
                    const api::Sort& type,
403
                    bool levelZero = false,
404
                    bool doOverload = false);
405
406
  /**
407
   * Create a set of new cvc5 variable expressions of the given type.
408
   *
409
   * It is inserted at context level zero in the symbol table if levelZero is
410
   * true, or if we are using global declarations.
411
   *
412
   * For each name, if a symbol with name already exists,
413
   *  then if doOverload is true, we create overloaded operators.
414
   *  else if doOverload is false, the existing expression is shadowed by the
415
   * new expression.
416
   */
417
  std::vector<api::Term> bindVars(const std::vector<std::string> names,
418
                                  const api::Sort& type,
419
                                  bool levelZero = false,
420
                                  bool doOverload = false);
421
422
  /**
423
   * Create a new cvc5 bound variable expression of the given type. This binds
424
   * the symbol name to that variable in the current scope.
425
   */
426
  api::Term bindBoundVar(const std::string& name, const api::Sort& type);
427
  /**
428
   * Create a new cvc5 bound variable expressions of the given names and types.
429
   * Like the method above, this binds these names to those variables in the
430
   * current scope.
431
   */
432
  std::vector<api::Term> bindBoundVars(
433
      std::vector<std::pair<std::string, api::Sort> >& sortedVarNames);
434
435
  /**
436
   * Create a set of new cvc5 bound variable expressions of the given type.
437
   *
438
   * For each name, if a symbol with name already exists,
439
   *  then if doOverload is true, we create overloaded operators.
440
   *  else if doOverload is false, the existing expression is shadowed by the
441
   * new expression.
442
   */
443
  std::vector<api::Term> bindBoundVars(const std::vector<std::string> names,
444
                                       const api::Sort& type);
445
446
  /** Create a new variable definition (e.g., from a let binding).
447
   * levelZero is set if the binding must be done at level 0.
448
   * If a symbol with name already exists,
449
   *  then if doOverload is true, we create overloaded operators.
450
   *  else if doOverload is false, the existing expression is shadowed by the new expression.
451
   */
452
  void defineVar(const std::string& name,
453
                 const api::Term& val,
454
                 bool levelZero = false,
455
                 bool doOverload = false);
456
457
  /**
458
   * Create a new type definition.
459
   *
460
   * @param name The name of the type
461
   * @param type The type that should be associated with the name
462
   * @param levelZero If true, the type definition is considered global and
463
   *                  cannot be removed by popping the user context
464
   * @param skipExisting If true, the type definition is ignored if the same
465
   *                     symbol has already been defined. It is assumed that
466
   *                     the definition is the exact same as the existing one.
467
   */
468
  void defineType(const std::string& name,
469
                  const api::Sort& type,
470
                  bool levelZero = false,
471
                  bool skipExisting = false);
472
473
  /**
474
   * Create a new (parameterized) type definition.
475
   *
476
   * @param name The name of the type
477
   * @param params The type parameters
478
   * @param type The type that should be associated with the name
479
   * @param levelZero If true, the type definition is considered global and
480
   *                  cannot be removed by poppoing the user context
481
   */
482
  void defineType(const std::string& name,
483
                  const std::vector<api::Sort>& params,
484
                  const api::Sort& type,
485
                  bool levelZero = false);
486
487
  /** Create a new type definition (e.g., from an SMT-LIBv2 define-sort). */
488
  void defineParameterizedType(const std::string& name,
489
                               const std::vector<api::Sort>& params,
490
                               const api::Sort& type);
491
492
  /**
493
   * Creates a new sort with the given name.
494
   */
495
  api::Sort mkSort(const std::string& name);
496
497
  /**
498
   * Creates a new sort constructor with the given name and arity.
499
   */
500
  api::Sort mkSortConstructor(const std::string& name, size_t arity);
501
502
  /**
503
   * Creates a new "unresolved type," used only during parsing.
504
   */
505
  api::Sort mkUnresolvedType(const std::string& name);
506
507
  /**
508
   * Creates a new unresolved (parameterized) type constructor of the given
509
   * arity.
510
   */
511
  api::Sort mkUnresolvedTypeConstructor(const std::string& name, size_t arity);
512
  /**
513
   * Creates a new unresolved (parameterized) type constructor given the type
514
   * parameters.
515
   */
516
  api::Sort mkUnresolvedTypeConstructor(const std::string& name,
517
                                        const std::vector<api::Sort>& params);
518
519
  /**
520
   * Creates a new unresolved (parameterized) type constructor of the given
521
   * arity. Calls either mkUnresolvedType or mkUnresolvedTypeConstructor
522
   * depending on the arity.
523
   */
524
  api::Sort mkUnresolvedType(const std::string& name, size_t arity);
525
526
  /**
527
   * Returns true IFF name is an unresolved type.
528
   */
529
  bool isUnresolvedType(const std::string& name);
530
531
  /**
532
   * Creates and binds sorts of a list of mutually-recursive datatype
533
   * declarations.
534
   *
535
   * For each symbol defined by the datatype, if a symbol with name already
536
   * exists, then if doOverload is true, we create overloaded operators. Else, if
537
   * doOverload is false, the existing expression is shadowed by the new
538
   * expression.
539
   */
540
  std::vector<api::Sort> bindMutualDatatypeTypes(
541
      std::vector<api::DatatypeDecl>& datatypes, bool doOverload = false);
542
543
  /** make flat function type
544
   *
545
   * Returns the "flat" function type corresponding to the function taking
546
   * argument types "sorts" and range type "range".  A flat function type is
547
   * one whose range is not a function. Notice that if sorts is empty and range
548
   * is not a function, then this function returns range itself.
549
   *
550
   * If range is a function type, we add its function argument sorts to sorts
551
   * and consider its function range as the new range. For each sort S added
552
   * to sorts in this process, we add a new bound variable of sort S to
553
   * flattenVars.
554
   *
555
   * For example:
556
   * mkFlattenFunctionType( { Int, (-> Real Real) }, (-> Int Bool), {} ):
557
   * - returns the the function type (-> Int (-> Real Real) Int Bool)
558
   * - updates sorts to { Int, (-> Real Real), Int },
559
   * - updates flattenVars to { x }, where x is bound variable of type Int.
560
   *
561
   * Notice that this method performs only one level of flattening, for example,
562
   * mkFlattenFunctionType({ Int, (-> Real Real) }, (-> Int (-> Int Bool)), {}):
563
   * - returns the the function type (-> Int (-> Real Real) Int (-> Int Bool))
564
   * - updates sorts to { Int, (-> Real Real), Int },
565
   * - updates flattenVars to { x }, where x is bound variable of type Int.
566
   *
567
   * This method is required so that we do not return functions
568
   * that have function return type (these give an unhandled exception
569
   * in the ExprManager). For examples of the equivalence between function
570
   * definitions in the proposed higher-order extension of the smt2 language,
571
   * see page 3 of http://matryoshka.gforge.inria.fr/pubs/PxTP2017.pdf.
572
   *
573
   * The argument flattenVars is needed in the case of defined functions
574
   * with function return type. These have implicit arguments, for instance:
575
   *    (define-fun Q ((x Int)) (-> Int Int) (lambda y (P x)))
576
   * is equivalent to the command:
577
   *    (define-fun Q ((x Int) (z Int)) Int (@ (lambda y (P x)) z))
578
   * where @ is (higher-order) application. In this example, z is added to
579
   * flattenVars.
580
   */
581
  api::Sort mkFlatFunctionType(std::vector<api::Sort>& sorts,
582
                               api::Sort range,
583
                               std::vector<api::Term>& flattenVars);
584
585
  /** make flat function type
586
   *
587
   * Same as above, but does not take argument flattenVars.
588
   * This is used when the arguments of the function are not important (for
589
   * instance, if we are only using this type in a declare-fun).
590
   */
591
  api::Sort mkFlatFunctionType(std::vector<api::Sort>& sorts, api::Sort range);
592
593
  /** make higher-order apply
594
   *
595
   * This returns the left-associative curried application of (function) expr to
596
   * the arguments in args.
597
   *
598
   * For example, mkHoApply( f, { a, b }, 0 ) returns
599
   *  (HO_APPLY (HO_APPLY f a) b)
600
   *
601
   * If args is non-empty, the expected type of expr is (-> T0 ... Tn T), where
602
   *    args[i].getType() = Ti
603
   * for each i where 0 <= i < args.size(). If expr is not of this
604
   * type, the expression returned by this method will not be well typed.
605
   */
606
  api::Term mkHoApply(api::Term expr, const std::vector<api::Term>& args);
607
608
  /** Apply type ascription
609
   *
610
   * Return term t with a type ascription applied to it. This is used for
611
   * syntax like (as t T) in smt2 and t::T in the CVC language. This includes:
612
   * - (as emptyset (Set T))
613
   * - (as emptybag (Bag T))
614
   * - (as univset (Set T))
615
   * - (as sep.nil T)
616
   * - (cons T)
617
   * - ((as cons T) t1 ... tn) where cons is a parametric datatype constructor.
618
   *
619
   * The term to ascribe t is a term whose kind and children (but not type)
620
   * are equivalent to that of the term returned by this method.
621
   *
622
   * Notice that method is not necessarily a cast. In actuality, the above terms
623
   * should be understood as symbols indexed by types. However, SMT-LIB does not
624
   * permit types as indices, so we must use, e.g. (as emptyset (Set T))
625
   * instead of (_ emptyset (Set T)).
626
   *
627
   * @param t The term to ascribe a type
628
   * @param s The sort to ascribe
629
   * @return Term t with sort s ascribed.
630
   */
631
  api::Term applyTypeAscription(api::Term t, api::Sort s);
632
633
  /**
634
   * Add an operator to the current legal set.
635
   *
636
   * @param kind the built-in operator to add
637
   */
638
  void addOperator(api::Kind kind);
639
640
  /**
641
   * Preempt the next returned command with other ones; used to
642
   * support the :named attribute in SMT-LIBv2, which implicitly
643
   * inserts a new command before the current one. Also used in TPTP
644
   * because function and predicate symbols are implicitly declared.
645
   */
646
  void preemptCommand(Command* cmd);
647
648
  /** Is the symbol bound to a boolean variable? */
649
  bool isBoolean(const std::string& name);
650
651
  /** Is fun a function (or function-like thing)?
652
  * Currently this means its type is either a function, constructor, tester, or selector.
653
  */
654
  bool isFunctionLike(api::Term fun);
655
656
  /** Is the symbol bound to a predicate? */
657
  bool isPredicate(const std::string& name);
658
659
  /** Parse and return the next command. */
660
  Command* nextCommand();
661
662
  /** Parse and return the next expression. */
663
  api::Term nextExpression();
664
665
  /** Issue a warning to the user. */
666
208
  void warning(const std::string& msg) { d_input->warning(msg); }
667
  /** Issue a warning to the user, but only once per attribute. */
668
  void attributeNotSupported(const std::string& attr);
669
670
  /** Raise a parse error with the given message. */
671
73
  inline void parseError(const std::string& msg) { d_input->parseError(msg); }
672
  /** Unexpectedly encountered an EOF */
673
  inline void unexpectedEOF(const std::string& msg)
674
  {
675
    d_input->parseError(msg, true);
676
  }
677
678
  /**
679
   * If we are parsing only, don't raise an exception; if we are not,
680
   * raise a parse error with the given message.  There is no actual
681
   * parse error, everything is as expected, but we cannot create the
682
   * Expr, Type, or other requested thing yet due to internal
683
   * limitations.  Even though it's not a parse error, we throw a
684
   * parse error so that the input line and column information is
685
   * available.
686
   *
687
   * Think quantifiers.  We don't have a TheoryQuantifiers yet, so we
688
   * have no kind::FORALL or kind::EXISTS.  But we might want to
689
   * support parsing quantifiers (just not doing anything with them).
690
   * So this mechanism gives you a way to do it with --parse-only.
691
   */
692
  inline void unimplementedFeature(const std::string& msg)
693
  {
694
    if(!d_parseOnly) {
695
      parseError("Unimplemented feature: " + msg);
696
    }
697
  }
698
699
  /**
700
   * Gets the current declaration level.
701
   */
702
  size_t scopeLevel() const;
703
704
  /**
705
   * Pushes a scope. All subsequent symbol declarations made are only valid in
706
   * this scope, i.e. they are deleted on the next call to popScope.
707
   *
708
   * The argument isUserContext is true, when we are pushing a user context
709
   * e.g. via the smt2 command (push n). This may also include one initial
710
   * pushScope when the parser is initialized. User-context pushes and pops
711
   * have an impact on both expression names and the symbol table, whereas
712
   * other pushes and pops only have an impact on the symbol table.
713
   */
714
  void pushScope(bool isUserContext = false);
715
716
  void popScope();
717
718
  virtual void reset();
719
720
  /** Return the symbol manager used by this parser. */
721
  SymbolManager* getSymbolManager();
722
723
  //------------------------ operator overloading
724
  /** is this function overloaded? */
725
  bool isOverloadedFunction(api::Term fun)
726
  {
727
    return d_symtab->isOverloadedFunction(fun);
728
  }
729
730
  /** Get overloaded constant for type.
731
   * If possible, it returns a defined symbol with name
732
   * that has type t. Otherwise returns null expression.
733
  */
734
6
  api::Term getOverloadedConstantForType(const std::string& name, api::Sort t)
735
  {
736
6
    return d_symtab->getOverloadedConstantForType(name, t);
737
  }
738
739
  /**
740
   * If possible, returns a defined function for a name
741
   * and a vector of expected argument types. Otherwise returns
742
   * null expression.
743
   */
744
14
  api::Term getOverloadedFunctionForTypes(const std::string& name,
745
                                          std::vector<api::Sort>& argTypes)
746
  {
747
14
    return d_symtab->getOverloadedFunctionForTypes(name, argTypes);
748
  }
749
  //------------------------ end operator overloading
750
  /**
751
   * Make string constant
752
   *
753
   * This makes the string constant based on the string s. This may involve
754
   * processing ad-hoc escape sequences (if the language is not
755
   * SMT-LIB 2.6 or higher), or otherwise calling the solver to construct
756
   * the string.
757
   */
758
  api::Term mkStringConstant(const std::string& s);
759
760
  /**
761
   * Make string constant from a single character in hex representation
762
   *
763
   * This makes the string constant based on the character from the strings,
764
   * represented as a hexadecimal code point.
765
   */
766
  api::Term mkCharConstant(const std::string& s);
767
768
  /** ad-hoc string escaping
769
   *
770
   * Returns the (internal) vector of code points corresponding to processing
771
   * the escape sequences in string s. This is to support string inputs that
772
   * do no comply with the SMT-LIB standard.
773
   *
774
   * This method handles escape sequences, including \n, \t, \v, \b, \r, \f, \a,
775
   * \\, \x[N] and octal escape sequences of the form \[c1]([c2]([c3])?)? where
776
   * c1, c2, c3 are digits from 0 to 7.
777
   */
778
  std::wstring processAdHocStringEsc(const std::string& s);
779
}; /* class Parser */
780
781
}  // namespace parser
782
}  // namespace cvc5
783
784
#endif /* CVC5__PARSER__PARSER_STATE_H */