Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / shapesscanner.h
blobef342b29ca7920a7f19654e94042200299624254
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008 Henrik Tidefelt
19 #pragma once
21 #include "sourcelocation.h"
22 #include "charptrless.h"
23 #include "elementarylength.h"
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <stack>
28 #include <map>
29 #include <set>
30 #include <list>
31 #include <string>
33 #ifndef FLEXINT_H // Else *FlexLexer will be defined twice
34 # undef yyFlexLexer
35 # define yyFlexLexer shapesFlexLexer
36 # include <FlexLexer.h>
37 #endif
39 class ShapesScanner : public shapesFlexLexer
41 std::stack< yy_buffer_state * > stateStack;
42 std::stack< ::Shapes::Ast::SourceLocation > locStack;
43 std::stack< size_t > pathCountStack;
44 unsigned int quoteDepth;
45 bool moreState;
46 int lastleng;
47 void more( );
48 std::map< const char *, double, charPtrLess > unitTable;
49 const char * newUnitName;
50 std::set< const Shapes::Ast::FileID *, Shapes::Ast::FileIDPtrLess > neededFiles;
51 std::string sourceDir_;
52 std::list< std::string > needSearchPath;
53 bool inPrelude_;
54 std::istream * preludeFile_;
55 std::list< std::string >::const_iterator preludeIterator_;
56 std::list< std::pair< std::istream *, const Shapes::Ast::FileID * > > yyinQueue_;
57 bool showFiles;
58 bool randSeedSet;
59 std::list< std::pair< char *, size_t > > dataStringChunks_;
60 size_t dataStringTotalLength_;
61 bool interactive_;
62 public:
63 // Ast::SourceLocation loc;
64 ShapesScanner( );
65 virtual ~ShapesScanner( );
66 void setInteractive( bool interactive );
67 void start( );
68 void queueStream( std::istream * is, const Shapes::Ast::FileID * yyinFile );
69 void setSourceDir( const std::string & sourceDir );
70 void push_backNeedPath( const std::string & path );
71 std::string searchFile( const std::string & suffix ) const;
72 std::string searchFile( const std::string & suffix, struct stat * dstStat ) const;
73 void setShowFiles( bool _showFiles );
74 virtual int yylex( );
75 void doBeforeEachAction( );
77 double lookupUnitFactor( const char * name ) const;
78 Shapes::Concrete::Length strtoLength( const char * str ) const;
79 private:
80 std::string currentNeedFile;
81 size_t currentNeedPushCount;
82 bool currentNeedIsNeed;
83 void push_frontNeedPath( const std::string & path );
84 void pop_frontNeedPath( );
85 void doInclusion( );
86 void rinseString( );
87 void concatenateDataString( );
88 std::string needpathWithSuffix( const std::string & needpath, const std::string & suffix ) const;