コード例 #1
0
ファイル: scanner.cpp プロジェクト: bd808/hhvm
Scanner::Scanner(const std::string& filename, int type, bool md5 /* = false */)
    : m_filename(filename), m_stream(nullptr), m_source(nullptr), m_len(0), m_pos(0),
      m_state(Start), m_type(type), m_yyscanner(nullptr), m_token(nullptr),
      m_loc(nullptr), m_lastToken(-1), m_isHHFile(0), m_lookaheadLtDepth(0),
      m_listener(nullptr) {
#ifdef _MSC_VER
  // I really don't know why this doesn't work properly with MSVC,
  // but I know this fixes the problem, so use it instead.
  std::ifstream ifs =
    std::ifstream(m_filename, std::ifstream::in | std::ifstream::binary);
  if (ifs.fail()) {
    throw FileOpenException(m_filename);
  }

  std::stringstream ss;
  ss << ifs.rdbuf();
  m_stream = new std::istringstream(ss.str());
  m_streamOwner = true;
#else
  m_stream = new std::ifstream(m_filename);
  m_streamOwner = true;
  if (m_stream->fail()) {
    delete m_stream; m_stream = nullptr;
    throw FileOpenException(m_filename);
  }
#endif
  if (md5) computeMd5();
  init();
}
コード例 #2
0
ファイル: scanner.cpp プロジェクト: cuiwow/hiphop-php
Scanner::Scanner(std::istream &stream, int type,
                 const char *fileName /* = "" */,
                 bool md5 /* = false */)
    : m_filename(fileName), m_source(nullptr), m_len(0), m_pos(0),
      m_state(Start), m_type(type), m_yyscanner(nullptr), m_token(nullptr),
      m_loc(nullptr), m_lastToken(-1), m_isStrictMode(0), m_lookaheadLtDepth(0) {
  m_stream = &stream;
  m_streamOwner = false;
  if (md5) computeMd5();
  init();
}
コード例 #3
0
ファイル: scanner.cpp プロジェクト: cuiwow/hiphop-php
Scanner::Scanner(const char *filename, int type, bool md5 /* = false */)
    : m_filename(filename), m_stream(nullptr), m_source(nullptr), m_len(0), m_pos(0),
      m_state(Start), m_type(type), m_yyscanner(nullptr), m_token(nullptr),
      m_loc(nullptr), m_lastToken(-1), m_isStrictMode(0), m_lookaheadLtDepth(0) {
  m_stream = new std::ifstream(filename);
  m_streamOwner = true;
  if (m_stream->fail()) {
    delete m_stream; m_stream = nullptr;
    throw FileOpenException(filename);
  }
  if (md5) computeMd5();
  init();
}
コード例 #4
0
ファイル: scanner.cpp プロジェクト: bd808/hhvm
Scanner::Scanner(const char *source, int len, int type,
                 const char *fileName /* = "" */, bool md5 /* = false */)
    : m_filename(fileName), m_stream(nullptr), m_source(source), m_len(len),
      m_pos(0), m_state(Start), m_type(type), m_yyscanner(nullptr),
      m_token(nullptr), m_loc(nullptr), m_lastToken(-1), m_isHHFile(0),
      m_lookaheadLtDepth(0), m_listener(nullptr) {
  assert(m_source);
  m_streamOwner = false;
  if (md5) {
    m_stream = new std::istringstream(std::string(source, len));
    m_streamOwner = true;
    computeMd5();
  }

  init();
}