Update procedures
[shapes.git] / source / shapesscanner.h
blobaf53185a08f62a3ccd8b2746b59fa85182ff832c
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, 2010, 2014, 2015 Henrik Tidefelt
19 #pragma once
21 #include "sourcelocation.h"
22 #include "namespacedirectory.h"
23 #include "identifier.h"
24 #include "charptrless.h"
25 #include "elementarylength.h"
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <stack>
30 #include <map>
31 #include <set>
32 #include <list>
33 #include <string>
34 #include <stdint.h>
36 #ifndef FLEXINT_H // Else *FlexLexer will be defined twice
37 # undef yyFlexLexer
38 # define yyFlexLexer shapesFlexLexer
39 # include <FlexLexer.h>
40 #endif
43 typedef std::pair< RefCountPtr< const Shapes::Ast::NamespacePath >, const Shapes::Ast::FileID * > NeededFile;
44 bool operator < ( const NeededFile & n1, const NeededFile & n2 );
46 class ShapesScanner : public shapesFlexLexer
48 std::stack< yy_buffer_state * > stateStack_;
49 std::stack< ::Shapes::Ast::SourceLocation * > locStack_;
50 std::stack< size_t > pathCountStack_;
51 std::stack< size_t > loadStackSizeStack_;
52 std::stack< size_t > stateStackSizeStack_;
53 unsigned int quoteDepth_;
54 bool moreState_;
55 int lastleng_;
56 void more( );
57 size_t bracketDepth_;
58 RefCountPtr< const Shapes::Ast::SearchContext > searchContext_;
59 std::stack< RefCountPtr< const Shapes::Ast::SearchContext > > searchContextStack_;
60 size_t uniqueNamespaceNumber_;
61 std::map< const char *, double, charPtrLess > angleUnits_;
62 std::map< const char *, double, charPtrLess > lengthUnits_;
63 const char * newUnitName_;
64 Shapes::Ast::SourceLocation aliasLoc_;
65 Shapes::Ast::PlacedIdentifier * treeNamespaceAlias_;
66 std::set< NeededFile > neededFiles_;
67 std::string sourceDir_;
68 std::list< std::string > needSearchPath_;
69 std::stack< size_t > namespaceLimits_;
70 ::Shapes::Ast::NamespaceLoader loader_;
71 bool inPrelude_;
72 std::list< std::pair< std::istream *, const Shapes::Ast::FileID * > > yyinQueue_;
73 Shapes::Ast::LoadStack loadStack_;
74 bool showFiles_;
75 bool randSeedSet_;
76 std::list< std::pair< char *, size_t > > dataStringChunks_;
77 size_t dataStringTotalLength_;
78 bool interactive_;
80 public:
81 ShapesScanner( );
82 virtual ~ShapesScanner( );
83 void setInteractive( bool interactive );
84 void start( );
85 void queueStream( std::istream * is, const Shapes::Ast::FileID * yyinFile );
86 void setSourceDir( const std::string & sourceDir );
87 void push_backNeedPath( const std::string & path );
88 std::string searchFile( const std::string & filename, bool runtime = false ) const;
89 std::string searchFile( const std::string & filename, struct stat * dstStat, bool runtime = false ) const;
90 std::string searchNamespaceIndexFile( const RefCountPtr< const Shapes::Ast::NamespacePath > & path ) const;
91 std::string needpathWithSuffix( const std::string & needpath, const std::string & suffix ) const;
92 void setShowFiles( bool showFiles );
93 virtual int yylex( );
94 void doBeforeEachAction( );
95 double lookupLengthUnitFactor( const char * name ) const;
96 Shapes::Concrete::Length strtoLength( const char * str ) const;
97 RefCountPtr< const char > newPrivateName( );
98 RefCountPtr< const char > newEncapsulationName( );
100 private:
101 std::string currentNeedFile;
102 size_t currentNeedPushCount;
103 bool currentNeedIsNeed;
104 bool currentNeedHasNamespace; /* File or namespace form of ##need? */
105 void endOfLine( ); /* Use each time a token ending in a newline has been consumed. */
106 void push_frontNeedPath( const std::string & path );
107 void pop_frontNeedPath( );
108 void doInclusion( );
109 void rinseString( );
110 void concatenateDataString( );
111 uint32_t unicodeFromGlyphname( const char * name );
113 /* Note that it is important that the identifier constructors below are not used outside the scanner,
114 * since only the scanner can know for sure that the current environment has not changed since the
115 * scanning of the identifier string.
117 Shapes::Ast::NamespaceReference namespace_;
118 size_t namespace_yyleng_;
119 void setNamespace( char * str ); /* The contents of the given string will be destroyed after the call. */
120 Shapes::Ast::Identifier * prependNamespace( const char * idstr ) const;
121 Shapes::Ast::Identifier * simpleIdentifier( const char * idstr ) const;
122 Shapes::Ast::PlacedIdentifier * placedIdentifier( const char * idstr ) const;
123 RefCountPtr< const Shapes::Ast::NamespacePath > resolvedNamespace( ) const;