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, 2010 Henrik Tidefelt
21 #include "sourcelocation.h"
22 #include "charptrless.h"
23 #include "elementarylength.h"
25 #include <sys/types.h>
34 #ifndef FLEXINT_H // Else *FlexLexer will be defined twice
36 # define yyFlexLexer shapesFlexLexer
37 # include <FlexLexer.h>
40 class ShapesScanner
: public shapesFlexLexer
42 std::stack
< yy_buffer_state
* > stateStack
;
43 std::stack
< ::Shapes::Ast::SourceLocation
> locStack
;
44 std::stack
< size_t > pathCountStack
;
45 unsigned int quoteDepth
;
49 std::map
< const char *, double, charPtrLess
> unitTable
;
50 const char * newUnitName
;
51 std::set
< const Shapes::Ast::FileID
*, Shapes::Ast::FileIDPtrLess
> neededFiles
;
52 std::string sourceDir_
;
53 std::list
< std::string
> needSearchPath
;
55 std::istream
* preludeFile_
;
56 std::list
< std::string
>::const_iterator preludeIterator_
;
57 std::list
< std::pair
< std::istream
*, const Shapes::Ast::FileID
* > > yyinQueue_
;
60 std::list
< std::pair
< char *, size_t > > dataStringChunks_
;
61 size_t dataStringTotalLength_
;
64 // Ast::SourceLocation loc;
66 virtual ~ShapesScanner( );
67 void setInteractive( bool interactive
);
69 void queueStream( std::istream
* is
, const Shapes::Ast::FileID
* yyinFile
);
70 void setSourceDir( const std::string
& sourceDir
);
71 void push_backNeedPath( const std::string
& path
);
72 std::string
searchFile( const std::string
& suffix
, bool runtime
= false ) const;
73 std::string
searchFile( const std::string
& suffix
, struct stat
* dstStat
, bool runtime
= false ) const;
74 void setShowFiles( bool _showFiles
);
76 void doBeforeEachAction( );
78 double lookupUnitFactor( const char * name
) const;
79 Shapes::Concrete::Length
strtoLength( const char * str
) const;
81 std::string currentNeedFile
;
82 size_t currentNeedPushCount
;
83 bool currentNeedIsNeed
;
84 void push_frontNeedPath( const std::string
& path
);
85 void pop_frontNeedPath( );
88 void concatenateDataString( );
89 uint32_t unicodeFromGlyphname( const char * name
);
90 std::string
needpathWithSuffix( const std::string
& needpath
, const std::string
& suffix
) const;