1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
//! Solver configuration, contains backend-solver-specific info.
//!
//! Do **NOT** use wildcards when matching over `SmtStyle`. We want the code to fail to compile
//! whenever we add a solver. Likewise, do not use `if let` with `SmtStyle`.
//!
//! Note that the command for each solver can be passed through environment variables, see
//! - [`Z3_ENV_VAR`],
//! - [`CVC4_ENV_VAR`],
//! - [`YICES_2_ENV_VAR`], and
//! - the [`SmtConf::z3_or_env`], [`SmtConf::cvc4_or_env`], and [`SmtConf::yices_2_or_env`]
//!   constructors.

use std::fmt;

use crate::{SmtRes, Solver};

use self::SmtStyle::*;

/// A configuration item is either a keyword or unsupported.
pub type ConfItem = Option<&'static str>;

/// Value of an unsupported configuration item.
#[inline]
fn unsupported() -> ConfItem {
    None
}
/// Keyword for a configuration item.
#[inline]
fn supported(keyword: &'static str) -> ConfItem {
    Some(keyword)
}

/// Environment variable providing the command for z3.
pub const Z3_ENV_VAR: &str = "RSMT2_Z3_CMD";
/// Environment variable providing the command for CVC4.
pub const CVC4_ENV_VAR: &str = "RSMT2_CVC4_CMD";
/// Environment variable providing the command for Yices 2.
pub const YICES_2_ENV_VAR: &str = "RSMT2_YICES_2_CMD";

/// Retrieves the value of an environment variable.
fn get_env_var(env_var: &str) -> SmtRes<Option<String>> {
    match std::env::var(env_var) {
        Ok(res) => Ok(Some(res)),
        Err(std::env::VarError::NotPresent) => Ok(None),
        Err(std::env::VarError::NotUnicode(cmd)) => bail!(
            "value of environment variable `{}` is not legal unicode: `{}`",
            env_var,
            cmd.to_string_lossy(),
        ),
    }
}

/// Solver styles.
///
/// - [z3][z3]: full support
/// - [cvc4][cvc4]: full support in theory, but only partially tested. Note that `get-value` is
///   known to crash some versions of CVC4.
/// - [yices 2][yices 2]: full support in theory, but only partially tested. Command `get-model`
///   will only work on Yices 2 > `2.6.1`, and needs to be activated in [`SmtConf`] with
///   [`SmtConf::models`]. To understand why, see <https://github.com/SRI-CSL/yices2/issues/162>.
///   
/// [z3]: https://github.com/Z3Prover/z3 (z3 github repository)
/// [cvc4]: https://cvc4.github.io/ (cvc4 github pages)
/// [yices 2]: https://yices.csl.sri.com/ (yices 2 official page)
#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub enum SmtStyle {
    /// Z3-style smt solver.
    Z3,
    /// CVC4-style smt solver.
    ///
    /// **NB**: CVC4 has only been partially tested at this point.
    CVC4,
    /// Yices-2-style smt solver.
    ///
    /// **NB**: Yices 2 has only been partially tested at this point.
    Yices2,
}

impl SmtStyle {
    /// Configuration constructor.
    pub fn new(self, cmd: impl Into<String>) -> SmtConf {
        let cmd = cmd.into();
        match self {
            Z3 => SmtConf {
                style: self,
                cmd,
                options: vec!["-in".into(), "-smt2".into()],
                models: true,
                incremental: true,
                parse_success: false,
                unsat_cores: false,
                check_sat_assuming: supported("check-sat-assuming"),
            },
            CVC4 => SmtConf {
                style: self,
                cmd,
                options: vec![
                    "-q".into(),
                    "--no-interactive".into(),
                    "--lang".into(),
                    "smt2".into(),
                ],
                models: false,
                incremental: false,
                parse_success: false,
                unsat_cores: false,
                check_sat_assuming: unsupported(),
            },
            Yices2 => SmtConf {
                style: self,
                cmd,
                options: vec![],
                models: false,
                incremental: false,
                parse_success: false,
                unsat_cores: false,
                check_sat_assuming: supported("check-sat-assuming"),
            },
        }
    }

    /// Default configuration for a solver style.
    ///
    /// # Warning
    ///
    /// The command used to run a particular solver is up to the end-user. As such, it **does not
    /// make sense** to use default commands for anything else than local testing. You should
    /// explicitely pass the command to use with [`Self::new`] instead.
    pub fn default(self) -> SmtConf {
        self.new(self.cmd())
    }

    /// A solver style from a string.
    #[allow(dead_code)]
    pub fn of_str(s: &str) -> Option<Self> {
        match s {
            "z3" | "Z3" => Some(Z3),
            "cvc4" | "CVC4" => Some(CVC4),
            "Yices2" | "yices2" | "YICES2" | "Yices 2" | "yices 2" | "YICES 2" => Some(Yices2),
            _ => None,
        }
    }
    /// Legal string representations of solver styles.
    #[allow(dead_code)]
    pub fn str_keys() -> Vec<&'static str> {
        vec![
            "z3", "Z3", "cvc4", "CVC4", "Yices2", "yices2", "YICES2", "Yices 2", "yices 2",
            "YICES 2",
        ]
    }

    /// Solver style command from the corresponding environment variable.
    ///
    /// The environement variables scanned are [`Z3_ENV_VAR`], [`CVC4_ENV_VAR`] and
    /// [`YICES_2_ENV_VAR`].
    pub fn env_cmd(self) -> SmtRes<Option<String>> {
        match self {
            Z3 => get_env_var(Z3_ENV_VAR),
            CVC4 => get_env_var(CVC4_ENV_VAR),
            Yices2 => get_env_var(YICES_2_ENV_VAR),
        }
    }

    /// Default command for a solver style.
    #[cfg(not(windows))]
    pub fn cmd(self) -> &'static str {
        match self {
            Z3 => "z3",
            CVC4 => "cvc4",
            Yices2 => "yices",
        }
    }
    /// Default command for a solver style.
    #[cfg(windows)]
    pub fn cmd(self) -> &'static str {
        match self {
            Z3 => "z3.exe",
            CVC4 => "cvc4.exe",
            Yices2 => "yices.exe",
        }
    }
}

impl fmt::Display for SmtStyle {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Z3 => write!(fmt, "z3"),
            CVC4 => write!(fmt, "cvc4"),
            Yices2 => write!(fmt, "yices2"),
        }
    }
}

/// Configuration and solver specific info.
///
/// - [z3][z3]: full support
/// - [cvc4][cvc4]: full support in theory, but only partially tested. Note that `get-value` is
///   known to crash some versions of CVC4.
/// - [yices 2][yices 2]: full support in theory, but only partially tested. Command `get-model`
///   will only work on Yices 2 > `2.6.1`, and needs to be activated with [`Self::models`]. To
///   understand why, see <https://github.com/SRI-CSL/yices2/issues/162>.
///   
/// [z3]: https://github.com/Z3Prover/z3 (z3 github repository)
/// [cvc4]: https://cvc4.github.io/ (cvc4 github pages)
/// [yices 2]: https://yices.csl.sri.com/ (yices 2 official page)
#[derive(Debug, Clone)]
pub struct SmtConf {
    /// Solver style.
    style: SmtStyle,
    /// Solver command.
    cmd: String,
    /// Options to call the solver with.
    options: Vec<String>,
    /// Model production.
    models: bool,
    /// Incrementality.
    incremental: bool,
    /// Parse success.
    parse_success: bool,
    /// Triggers unsat-core production.
    unsat_cores: bool,
    /// Keyword for check-sat with assumptions.
    check_sat_assuming: ConfItem,
}

impl SmtConf {
    /// Creates a new z3-like solver configuration.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let conf = SmtConf::z3("my_z3_command");
    /// assert!(conf.get_cmd() == "my_z3_command")
    /// ```
    #[inline]
    pub fn z3(cmd: impl Into<String>) -> Self {
        Z3.new(cmd)
    }

    /// Creates a new cvc4-like solver configuration.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let conf = SmtConf::cvc4("my_cvc4_command");
    /// assert!(conf.get_cmd() == "my_cvc4_command")
    /// ```
    #[inline]
    pub fn cvc4(cmd: impl Into<String>) -> Self {
        CVC4.new(cmd)
    }

    /// Creates a new yices-2-like solver configuration.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let conf = SmtConf::yices_2("my_yices_2_command");
    /// assert!(conf.get_cmd() == "my_yices_2_command")
    /// ```
    #[inline]
    pub fn yices_2(cmd: impl Into<String>) -> Self {
        Yices2.new(cmd)
    }

    /// Creates a z3-like solver configuration from an optional, or the value of the [`Z3_ENV_VAR`]
    /// environment variable.
    ///
    /// Fails if `cmd.is_none()` and [`Z3_ENV_VAR`] is not set.
    ///
    /// ```rust
    /// use rsmt2::conf::{SmtConf, Z3_ENV_VAR};
    /// use std::env::{set_var, var_os};
    ///
    /// // Passes the command directly.
    /// let cmd = "z3_explicit";
    /// let explicit_cmd = SmtConf::z3_or_env(Some(cmd.into())).expect("explicit");
    /// assert_eq!(explicit_cmd.get_cmd(), cmd);
    ///
    /// // Error if no command + environment variable not set.
    /// assert_eq!(var_os(Z3_ENV_VAR), None);
    /// let error = SmtConf::z3_or_env(None);
    /// match error {
    ///     Ok(_) => panic!("expected error, got an SMT style"),
    ///     Err(e) => assert_eq!(
    ///         &e.to_string(),
    ///         "no command for z3 provided, \
    ///         and `RSMT2_Z3_CMD` environment variable not set; \
    ///         cannot spawn z3 solver"
    ///     ),
    /// }
    ///
    /// // Retrieves the command from the environment.
    /// let cmd = "z3_implicit";
    /// assert_eq!(Z3_ENV_VAR, "RSMT2_Z3_CMD");
    /// set_var(Z3_ENV_VAR, cmd);
    /// let implicit_cmd = SmtConf::z3_or_env(None).expect("implicit");
    /// assert_eq!(implicit_cmd.get_cmd(), cmd);
    /// ```
    #[inline]
    pub fn z3_or_env(cmd: Option<String>) -> SmtRes<Self> {
        if let Some(cmd) = cmd {
            Ok(Self::z3(cmd))
        } else {
            let cmd = SmtStyle::Z3.env_cmd()?;
            if let Some(cmd) = cmd {
                Ok(Self::z3(cmd))
            } else {
                bail!(
                    "no command for z3 provided, \
                    and `{}` environment variable not set; cannot spawn z3 solver",
                    Z3_ENV_VAR,
                )
            }
        }
    }

    /// Creates a CVC4-like solver configuration from an optional, or the value of the
    /// [`CVC4_ENV_VAR`] environment variable.
    ///
    /// Fails if `cmd.is_none()` and [`CVC4_ENV_VAR`] is not set.
    ///
    /// ```rust
    /// use rsmt2::conf::{SmtConf, CVC4_ENV_VAR};
    /// use std::env::{set_var, var_os};
    ///
    /// // Passes the command directly.
    /// let cmd = "cvc4_explicit";
    /// let explicit_cmd = SmtConf::cvc4_or_env(Some(cmd.into())).expect("explicit");
    /// assert_eq!(explicit_cmd.get_cmd(), cmd);
    ///
    /// // Error if no command + environment variable not set.
    /// assert_eq!(var_os(CVC4_ENV_VAR), None);
    /// let error = SmtConf::cvc4_or_env(None);
    /// match error {
    ///     Ok(_) => panic!("expected error, got an SMT style"),
    ///     Err(e) => assert_eq!(
    ///         &e.to_string(),
    ///         "no command for CVC4 provided, \
    ///         and `RSMT2_CVC4_CMD` environment variable not set; \
    ///         cannot spawn CVC4 solver"
    ///     ),
    /// }
    ///
    /// // Retrieves the command from the environment.
    /// let cmd = "cvc4_implicit";
    /// assert_eq!(CVC4_ENV_VAR, "RSMT2_CVC4_CMD");
    /// set_var(CVC4_ENV_VAR, cmd);
    /// let implicit_cmd = SmtConf::cvc4_or_env(None).expect("implicit");
    /// assert_eq!(implicit_cmd.get_cmd(), cmd);
    /// ```
    #[inline]
    pub fn cvc4_or_env(cmd: Option<String>) -> SmtRes<Self> {
        if let Some(cmd) = cmd {
            Ok(Self::cvc4(cmd))
        } else {
            let cmd = SmtStyle::CVC4.env_cmd()?;
            if let Some(cmd) = cmd {
                Ok(Self::cvc4(cmd))
            } else {
                bail!(
                    "no command for CVC4 provided, \
                    and `{}` environment variable not set; cannot spawn CVC4 solver",
                    CVC4_ENV_VAR,
                )
            }
        }
    }

    /// Creates a Yices-2-like solver configuration from an optional, or the value of the
    /// [`YICES_2_ENV_VAR`] environment variable.
    ///
    /// Fails if `cmd.is_none()` and [`YICES_2_ENV_VAR`] is not set.
    ///
    /// ```rust
    /// use rsmt2::conf::{SmtConf, YICES_2_ENV_VAR};
    /// use std::env::{set_var, var_os};
    ///
    /// // Passes the command directly.
    /// let cmd = "yices_2_explicit";
    /// let explicit_cmd = SmtConf::yices_2_or_env(Some(cmd.into())).expect("explicit");
    /// assert_eq!(explicit_cmd.get_cmd(), cmd);
    ///
    /// // Error if no command + environment variable not set.
    /// assert_eq!(var_os(YICES_2_ENV_VAR), None);
    /// let error = SmtConf::yices_2_or_env(None);
    /// match error {
    ///     Ok(_) => panic!("expected error, got an SMT style"),
    ///     Err(e) => assert_eq!(
    ///         &e.to_string(),
    ///         "no command for Yices 2 provided, \
    ///         and `RSMT2_YICES_2_CMD` environment variable not set; \
    ///         cannot spawn Yices 2 solver"
    ///     ),
    /// }
    ///
    /// // Retrieves the command from the environment.
    /// let cmd = "yices_2_implicit";
    /// assert_eq!(YICES_2_ENV_VAR, "RSMT2_YICES_2_CMD");
    /// set_var(YICES_2_ENV_VAR, cmd);
    /// let implicit_cmd = SmtConf::yices_2_or_env(None).expect("implicit");
    /// assert_eq!(implicit_cmd.get_cmd(), cmd);
    /// ```
    #[inline]
    pub fn yices_2_or_env(cmd: Option<String>) -> SmtRes<Self> {
        if let Some(cmd) = cmd {
            Ok(Self::yices_2(cmd))
        } else {
            let cmd = SmtStyle::Yices2.env_cmd()?;
            if let Some(cmd) = cmd {
                Ok(Self::yices_2(cmd))
            } else {
                bail!(
                    "no command for Yices 2 provided, \
                    and `{}` environment variable not set; cannot spawn Yices 2 solver",
                    YICES_2_ENV_VAR,
                )
            }
        }
    }

    /// Creates a new z3-like solver configuration and command.
    ///
    /// # Warning
    ///
    /// The command used to run a particular solver is up to the end-user. As such, it **does not
    /// make sense** to use default commands for anything else than local testing. You should
    /// explicitely pass the command to use with [`Self::z3`] instead.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let conf = SmtConf::default_z3();
    /// assert! {
    ///     conf.get_cmd() == "z3" || conf.get_cmd() == "z3.exe"
    /// }
    /// ```
    #[inline]
    pub fn default_z3() -> Self {
        Z3.default()
    }

    /// Creates a new cvc4-like solver configuration and command.
    ///
    /// # Warning
    ///
    /// The command used to run a particular solver is up to the end-user. As such, it **does not
    /// make sense** to use default commands for anything else than local testing. You should
    /// explicitely pass the command to use with [`Self::cvc4`] instead.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let conf = SmtConf::default_cvc4();
    /// assert! {
    ///     conf.get_cmd() == "cvc4" || conf.get_cmd() == "cvc4.exe"
    /// }
    /// ```
    #[inline]
    pub fn default_cvc4() -> Self {
        CVC4.default()
    }

    /// Creates a new yices-2-like solver configuration and command.
    ///
    /// # Warning
    ///
    /// The command used to run a particular solver is up to the end-user. As such, it **does not
    /// make sense** to use default commands for anything else than local testing. You should
    /// explicitely pass the command to use with [`Self::yices_2`] instead.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let conf = SmtConf::default_yices_2();
    /// assert! {
    ///     conf.get_cmd() == "yices" || conf.get_cmd() == "yices.exe"
    /// }
    /// ```
    #[inline]
    pub fn default_yices_2() -> Self {
        Yices2.default()
    }

    /// Spawns the solver.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let _solver = SmtConf::default_z3().spawn(()).unwrap();
    /// ```
    #[inline]
    pub fn spawn<Parser>(self, parser: Parser) -> SmtRes<Solver<Parser>> {
        Solver::new(self, parser)
    }

    /// Concise description of the underlying solver.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// assert_eq! { SmtConf::default_z3().desc(), "z3" }
    /// ```
    #[inline]
    pub fn desc(&self) -> &str {
        match self.style {
            Z3 => "z3",
            CVC4 => "cvc4",
            Yices2 => "yices2",
        }
    }

    /// Model production flag.
    pub fn get_models(&self) -> bool {
        self.models
    }
    /// Activates model production.
    pub fn models(&mut self) {
        if self.models {
            return ();
        } else {
            self.models = true
        }
        match self.style {
            CVC4 => self.options.push("--produce-models".into()),
            Yices2 => self.options.push("--smt2-model-format".into()),
            Z3 => (),
        }
    }

    /// Incrementality.
    pub fn get_incremental(&self) -> bool {
        self.incremental
    }
    /// Activates incrementality (push/pop, check-sat-assuming).
    pub fn incremental(&mut self) {
        if self.incremental {
            return ();
        } else {
            self.incremental = true
        }
        match self.style {
            CVC4 | Yices2 => self.options.push("--incremental".into()),
            Z3 => (),
        }
    }

    /// Solver command.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let conf = SmtConf::default_z3();
    /// assert! {
    ///     conf.get_cmd() == "z3" || conf.get_cmd() == "z3.exe"
    /// }
    /// ```
    #[inline]
    pub fn get_cmd(&self) -> &str {
        &self.cmd
    }

    /// Options of the configuration.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// assert_eq! {
    ///     SmtConf::default_z3().get_options(), & [ "-in", "-smt2" ]
    /// }
    /// ```
    #[inline]
    pub fn get_options(&self) -> &[String] {
        &self.options
    }

    /// Indicates if print success is active.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// assert! { ! SmtConf::default_z3().get_print_success() }
    /// ```
    #[inline]
    pub fn get_print_success(&self) -> bool {
        self.parse_success
    }

    /// Indicates if unsat cores is active.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// assert! { ! SmtConf::default_z3().get_unsat_cores() }
    /// ```
    #[inline]
    pub fn get_unsat_cores(&self) -> bool {
        self.unsat_cores
    }

    /// Keyword for check-sat with assumptions.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// assert_eq! {
    ///     SmtConf::default_z3().get_check_sat_assuming(), Some("check-sat-assuming")
    /// }
    /// ```
    #[inline]
    pub fn get_check_sat_assuming(&self) -> ConfItem {
        self.check_sat_assuming.as_ref().map(|s| *s)
    }

    /// Adds an option to the configuration.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let mut conf = SmtConf::default_z3();
    /// conf.option("arith.euclidean_solver=true");
    /// assert_eq! {
    ///     conf.get_options(),
    ///     & [ "-in", "-smt2", "arith.euclidean_solver=true" ]
    /// }
    /// ```
    #[inline]
    pub fn option<S: Into<String>>(&mut self, o: S) -> &mut Self {
        self.options.push(o.into());
        self
    }

    /// Sets the command for the solver.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let mut conf = SmtConf::default_z3();
    /// conf.cmd("my_custom_z3_command");
    /// assert_eq! { conf.get_cmd(), "my_custom_z3_command" }
    /// ```
    #[inline]
    pub fn cmd<S: Into<String>>(&mut self, cmd: S) -> &mut Self {
        let cmd = cmd.into();
        let mut iter = cmd.split(' ');

        'set_cmd: while let Some(cmd) = iter.next() {
            if !cmd.is_empty() {
                self.cmd = cmd.into();
                break 'set_cmd;
            }
        }

        for option in iter {
            if !option.is_empty() {
                self.options.push(option.into())
            }
        }

        self
    }

    /// Activates parse sucess.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let mut conf = SmtConf::default_z3();
    /// conf.print_success();
    /// assert! { conf.get_print_success() }
    /// ```
    #[inline]
    #[cfg(not(no_parse_success))]
    pub fn print_success(&mut self) {
        self.parse_success = true
    }

    /// Activates unsat-core production.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use rsmt2::SmtConf;
    /// let mut conf = SmtConf::default_z3();
    /// conf.unsat_cores();
    /// assert! { conf.get_unsat_cores() }
    /// ```
    #[inline]
    pub fn unsat_cores(&mut self) {
        self.unsat_cores = true
    }
}

/// ## Solver-specific error-handling
impl SmtConf {
    /// Adds information to a `get-value` error message if needed.
    pub fn enrich_get_values_error(&self, e: crate::errors::Error) -> crate::errors::Error {
        match self.style {
            SmtStyle::CVC4 => e.chain_err(|| {
                "some versions of CVC4 produce errors on `get-value` commands, \
                 consider using `get-model` instead"
            }),
            SmtStyle::Z3 | SmtStyle::Yices2 => e,
        }
    }
}