Update procedures
[shapes.git] / source / namespacescanner.cc
blob54cd20a88f851a5e728b808d0e1037e31d9cb44d
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 2015 Henrik Tidefelt
19 #include "namespacescanner.h"
21 using namespace Shapes;
24 NamespaceScanner::NamespaceScanner( Shapes::Ast::NamespaceDeclarations * declarations, std::istream * yyin, const Shapes::Ast::FileID * fileID )
25 : yyFlexLexer( yyin, 0 ), moreState_( false ), lastleng_( 0 ),
26 declarations_( declarations )
28 namespacelloc = Ast::SourceLocation( fileID );
32 void
33 NamespaceScanner::more( )
35 moreState_ = true; /* This one is for ourselves to use in doBeforeEachAction. */
36 yy_more_flag = 1; /* This one is for flex, and will be reset before we reach doBeforeEachAction. */
37 lastleng_ = yyleng;
41 void
42 NamespaceScanner::doBeforeEachAction( )
44 if( moreState_ ){
45 namespacelloc.lastColumn += yyleng - lastleng_;
46 }else{
47 namespacelloc.firstLine = namespacelloc.lastLine;
48 namespacelloc.firstColumn = namespacelloc.lastColumn;
49 namespacelloc.lastColumn = namespacelloc.firstColumn + yyleng;
51 moreState_ = false;
55 void
56 NamespaceScanner::endOfLine( )
58 namespacelloc.firstLine = namespacelloc.lastLine + 1;
59 namespacelloc.lastLine = namespacelloc.firstLine;
60 namespacelloc.lastColumn = 0;
64 std::string
65 NamespaceScanner::rinseString( const char * str )
67 /* A string is always terminated by the one byte sequence in both ends: " */
68 size_t bytecount = std::strlen(str) - 2;
69 char * mem = new char[ bytecount + 1 ];
70 memcpy( mem, str, bytecount );
71 mem[ bytecount ] = '\0';
72 std::string res(mem);
73 delete mem;
74 return res;