LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/parser - input.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 22 100.0 %
Date: 2026-03-27 10:29:52 Functions: 12 12 100.0 %
Branches: 2 2 100.0 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * This file is part of the cvc5 project.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
       5                 :            :  * in the top-level source directory and their institutional affiliations.
       6                 :            :  * All rights reserved.  See the file COPYING in the top-level source
       7                 :            :  * directory for licensing information.
       8                 :            :  * ****************************************************************************
       9                 :            :  *
      10                 :            :  *  input class.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "parser/input.h"
      14                 :            : 
      15                 :            : #include <fstream>
      16                 :            : 
      17                 :            : #include <cvc5/cvc5_parser.h>
      18                 :            : 
      19                 :            : namespace cvc5 {
      20                 :            : namespace parser {
      21                 :            : 
      22                 :            : /** File input class */
      23                 :            : class FileInput : public Input
      24                 :            : {
      25                 :            :  public:
      26                 :      24033 :   FileInput(const std::string& filename) : Input()
      27                 :            :   {
      28                 :      24033 :     d_fs.open(filename, std::fstream::in);
      29         [ +  + ]:      24033 :     if (!d_fs.is_open())
      30                 :            :     {
      31                 :          2 :       std::stringstream ss;
      32                 :          2 :       ss << "Couldn't open file: " << filename;
      33                 :          2 :       throw ParserException(ss.str());
      34                 :          2 :     }
      35                 :      24035 :   }
      36                 :      24031 :   std::istream* getStream() override { return &d_fs; }
      37                 :            : 
      38                 :            :  private:
      39                 :            :   /** File stream */
      40                 :            :   std::ifstream d_fs;
      41                 :            : };
      42                 :            : 
      43                 :            : /** Stream reference input class */
      44                 :            : class StreamInput : public Input
      45                 :            : {
      46                 :            :  public:
      47                 :        205 :   StreamInput(std::istream& input) : Input(), d_input(input) {}
      48                 :        205 :   std::istream* getStream() override { return &d_input; }
      49                 :        205 :   bool isInteractive() const override { return true; }
      50                 :            : 
      51                 :            :  private:
      52                 :            :   /** Reference to stream */
      53                 :            :   std::istream& d_input;
      54                 :            : };
      55                 :            : 
      56                 :            : /** String input class, which buffers to a std::stringstream */
      57                 :            : class StringInput : public Input
      58                 :            : {
      59                 :            :  public:
      60                 :        152 :   StringInput(const std::string& input) : Input() { d_input << input; }
      61                 :        152 :   std::istream* getStream() override { return &d_input; }
      62                 :            : 
      63                 :            :  private:
      64                 :            :   /** Reference to stream */
      65                 :            :   std::stringstream d_input;
      66                 :            : };
      67                 :            : 
      68                 :      24390 : Input::Input() {}
      69                 :            : 
      70                 :      24033 : std::unique_ptr<Input> Input::mkFileInput(const std::string& filename)
      71                 :            : {
      72                 :      24033 :   return std::unique_ptr<Input>(new FileInput(filename));
      73                 :            : }
      74                 :            : 
      75                 :        205 : std::unique_ptr<Input> Input::mkStreamInput(std::istream& input)
      76                 :            : {
      77                 :        205 :   return std::unique_ptr<Input>(new StreamInput(input));
      78                 :            : }
      79                 :            : 
      80                 :        152 : std::unique_ptr<Input> Input::mkStringInput(const std::string& input)
      81                 :            : {
      82                 :        152 :   return std::unique_ptr<Input>(new StringInput(input));
      83                 :            : }
      84                 :      24183 : bool Input::isInteractive() const { return false; }
      85                 :            : 
      86                 :            : }  // namespace parser
      87                 :            : }  // namespace cvc5

Generated by: LCOV version 1.14