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
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
21 #include "sourcelocation.h"
22 #include "charptrless.h"
23 #include "elementarylength.h"
25 #include <sys/types.h>
33 #ifndef FLEXINT_H // Else *FlexLexer will be defined twice
35 # define yyFlexLexer shapesFlexLexer
36 # include <FlexLexer.h>
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
;
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
;
54 std::istream
* preludeFile_
;
55 std::list
< std::string
>::const_iterator preludeIterator_
;
56 std::list
< std::pair
< std::istream
*, const Shapes::Ast::FileID
* > > yyinQueue_
;
59 std::list
< std::pair
< char *, size_t > > dataStringChunks_
;
60 size_t dataStringTotalLength_
;
63 // Ast::SourceLocation loc;
65 virtual ~ShapesScanner( );
66 void setInteractive( bool interactive
);
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
, bool runtime
= false ) const;
72 std::string
searchFile( const std::string
& suffix
, struct stat
* dstStat
, bool runtime
= false ) const;
73 void setShowFiles( bool _showFiles
);
75 void doBeforeEachAction( );
77 double lookupUnitFactor( const char * name
) const;
78 Shapes::Concrete::Length
strtoLength( const char * str
) const;
80 std::string currentNeedFile
;
81 size_t currentNeedPushCount
;
82 bool currentNeedIsNeed
;
83 void push_frontNeedPath( const std::string
& path
);
84 void pop_frontNeedPath( );
87 void concatenateDataString( );
88 std::string
needpathWithSuffix( const std::string
& needpath
, const std::string
& suffix
) const;