From be3dc4cee63da92cfa1fa44a0bf90ab11ec7aaca Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 15 Nov 2016 16:57:48 +0200 Subject: Start switch to build2 --- cli/parser.cxx | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'cli/parser.cxx') 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 // stat -#include // stat -#include // stat +#ifndef _WIN32 +# include // stat +# include // stat +# include // stat +#else +# include // _stat +# include // _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 #include #include -#include "token.hxx" -#include "lexer.hxx" -#include "parser.hxx" +#include +#include +#include -#include "semantics.hxx" +#include 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 parser:: +unique_ptr parser:: parse (std::istream& is, path const& p) { - auto_ptr unit (new cli_unit (p, 1, 1)); + unique_ptr 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 (); -- cgit v1.1