diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-15 16:57:48 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-15 16:57:48 +0200 |
commit | be3dc4cee63da92cfa1fa44a0bf90ab11ec7aaca (patch) | |
tree | e74b26a798e0ff71bc140bbba3ea30e2eb3ac3e3 /cli/parser.cxx | |
parent | f8c61f71ebf44572c9e865a620dc053e94371beb (diff) | |
download | cli-be3dc4cee63da92cfa1fa44a0bf90ab11ec7aaca.tar.gz cli-be3dc4cee63da92cfa1fa44a0bf90ab11ec7aaca.tar.xz cli-be3dc4cee63da92cfa1fa44a0bf90ab11ec7aaca.zip |
Start switch to build2
Diffstat (limited to 'cli/parser.cxx')
-rw-r--r-- | cli/parser.cxx | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/cli/parser.cxx b/cli/parser.cxx index 43b2764..d8c11c5 100644 --- a/cli/parser.cxx +++ b/cli/parser.cxx @@ -3,23 +3,48 @@ // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file -#include <unistd.h> // stat -#include <sys/types.h> // stat -#include <sys/stat.h> // stat +#ifndef _WIN32 +# include <unistd.h> // stat +# include <sys/types.h> // stat +# include <sys/stat.h> // stat +#else +# include <sys/types.h> // _stat +# include <sys/stat.h> // _stat(), S_I* + +# ifdef _MSC_VER // Unlikely to be fixed in newer versions. +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# endif +#endif #include <fstream> #include <sstream> #include <iostream> -#include "token.hxx" -#include "lexer.hxx" -#include "parser.hxx" +#include <cli/token.hxx> +#include <cli/lexer.hxx> +#include <cli/parser.hxx> -#include "semantics.hxx" +#include <cli/semantics.hxx> using namespace std; using namespace semantics; +// Check that the file exist without checking for permissions, etc. +// +inline static bool +file_exists (const path& p) +{ +#ifndef _WIN32 + struct stat s; + int r (stat (p.string ().c_str (), &s)); +#else + struct _stat s; + int r (_stat (p.string ().c_str (), &s)); +#endif + + return r == 0 && S_ISREG (s.st_mode); +} + const char* keywords[] = { "include", @@ -160,10 +185,10 @@ recover (token& t) } } -auto_ptr<cli_unit> parser:: +unique_ptr<cli_unit> parser:: parse (std::istream& is, path const& p) { - auto_ptr<cli_unit> unit (new cli_unit (p, 1, 1)); + unique_ptr<cli_unit> unit (new cli_unit (p, 1, 1)); { path ap (p); @@ -303,16 +328,13 @@ source_decl () // else { - struct stat s; for (paths::const_iterator i (include_paths_.begin ()); i != include_paths_.end (); ++i) { p = *i / f; p.normalize (); - // Check that the file exist without checking for permissions, etc. - // - if (stat (p.string ().c_str (), &s) == 0 && S_ISREG (s.st_mode)) + if (file_exists (p)) break; p.clear (); @@ -421,16 +443,13 @@ include_decl () // else { - struct stat s; for (paths::const_iterator i (include_paths_.begin ()); i != include_paths_.end (); ++i) { p = *i / f; p.normalize (); - // Check that the file exist without checking for permissions, etc. - // - if (stat (p.string ().c_str (), &s) == 0 && S_ISREG (s.st_mode)) + if (file_exists (p)) break; p.clear (); |