LibreOffice Module idl (master) 1
lex.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_IDL_INC_LEX_HXX
21#define INCLUDED_IDL_INC_LEX_HXX
22
23#include <sal/types.h>
24#include "hash.hxx"
25#include <tools/stream.hxx>
26#include <vector>
27#include <memory>
28
32 Char,
34
36{
37friend class SvTokenStream;
38 sal_uInt64 nLine, nColumn;
40 OString aString;
41 union
42 {
43 sal_uInt64 nLong;
44 bool bBool;
45 char cChar;
47 };
48public:
49 SvToken();
50 SvToken( const SvToken & rObj ) = delete;
51
52 SvToken & operator = ( const SvToken & rObj );
53
54 OString GetTokenAsString() const;
55
56 void SetLine( sal_uInt64 nLineP ) { nLine = nLineP; }
57 sal_uInt64 GetLine() const { return nLine; }
58
59 void SetColumn( sal_uInt64 nColumnP ) { nColumn = nColumnP; }
60 sal_uInt64 GetColumn() const { return nColumn; }
61
62 bool IsComment() const { return nType == SVTOKENTYPE::Comment; }
63 bool IsInteger() const { return nType == SVTOKENTYPE::Integer; }
64 bool IsString() const { return nType == SVTOKENTYPE::String; }
65 bool IsBool() const { return nType == SVTOKENTYPE::Bool; }
66 bool IsIdentifierHash() const
67 { return nType == SVTOKENTYPE::HashId; }
68 bool IsIdentifier() const
69 {
72 }
73 bool IsChar() const { return nType == SVTOKENTYPE::Char; }
74 bool IsEof() const { return nType == SVTOKENTYPE::EndOfFile; }
75
76 const OString& GetString() const
77 {
78 return IsIdentifierHash()
79 ? pHash->GetName()
80 : aString;
81 }
82 sal_uInt64 GetNumber() const { return nLong; }
83 bool GetBool() const { return bBool; }
84 char GetChar() const { return cChar; }
85
86 void SetHash( SvStringHashEntry * pHashP )
87 { pHash = pHashP; nType = SVTOKENTYPE::HashId; }
88 bool Is( SvStringHashEntry const * pEntry ) const
89 { return IsIdentifierHash() && pHash == pEntry; }
90};
91
93 : nLine(0)
94 , nColumn(0)
96{
97}
98
100{
101 sal_uInt64 nLine, nColumn;
102 sal_Int32 nBufPos;
103 char c; // next character
104 static const sal_uInt16 nTabSize = 4; // length of tabulator
105 OString aStrTrue;
106 OString aStrFalse;
107 sal_uInt32 nMaxPos;
108
109 std::unique_ptr<SvFileStream> pInStream;
110 OUString aFileName;
111 std::vector<std::unique_ptr<SvToken> > aTokList;
112 std::vector<std::unique_ptr<SvToken> >::iterator pCurToken;
113
114 OString aBufStr;
115
116 void InitCtor();
117
118 char GetNextChar();
120 {
121 return (nBufPos < aBufStr.getLength())
122 ? aBufStr[nBufPos++]
123 : '\0';
124 }
125
126 void FillTokenList();
127 sal_uInt64 GetNumber();
128 bool MakeToken( SvToken & );
129 bool IsEof() const { return pInStream->eof(); }
130 void SetMax()
131 {
132 sal_uInt32 n = Tell();
133 if( n > nMaxPos )
134 nMaxPos = n;
135 }
137 {
138 // if end of line spare calculation
139 if( 0 != c )
140 {
141 sal_Int32 n = 0;
142 nColumn = 0;
143 while( n < nBufPos )
144 nColumn += aBufStr[n++] == '\t' ? nTabSize : 1;
145 }
146 }
147public:
148 SvTokenStream( const OUString & rFileName );
150
151 const OUString & GetFileName() const { return aFileName; }
152 SvStream & GetStream() { return *pInStream; }
153
155 {
156 std::vector<std::unique_ptr<SvToken> >::iterator pRetToken = pCurToken;
157
158 // current iterator always valid
159 if(pCurToken != aTokList.begin())
160 --pCurToken;
161
162 return *(*pRetToken);
163 }
164
166 {
167 std::vector<std::unique_ptr<SvToken> >::iterator pRetToken = pCurToken++;
168
169 if (pCurToken == aTokList.end())
170 pCurToken = pRetToken;
171
172 SetMax();
173
174 return *(*pRetToken);
175 }
176
177 SvToken& GetToken() const { return *(*pCurToken); }
178
179 bool ReadIf( char cChar )
180 {
181 if( GetToken().IsChar() && cChar == GetToken().GetChar() )
182 {
184 return true;
185 }
186 else
187 return false;
188 }
189
191 {
192 if( GetToken().IsChar()
193 && (';' == GetToken().GetChar()
194 || ',' == GetToken().GetChar()) )
195 {
197 }
198 }
199
200 sal_uInt32 Tell() const { return pCurToken-aTokList.begin(); }
201
202 void Seek( sal_uInt32 nPos )
203 {
204 pCurToken = aTokList.begin() + nPos;
205 SetMax();
206 }
207
209 {
210 pCurToken = aTokList.begin()+nMaxPos;
211 }
212};
213
214
215#endif // INCLUDED_IDL_INC_LEX_HXX
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OString & GetName() const
Definition: hash.hxx:40
OString aStrTrue
Definition: lex.hxx:105
SvStream & GetStream()
Definition: lex.hxx:152
void SetMax()
Definition: lex.hxx:130
OString aStrFalse
Definition: lex.hxx:106
bool MakeToken(SvToken &)
Definition: lex.cxx:191
void Seek(sal_uInt32 nPos)
Definition: lex.hxx:202
SvTokenStream(const OUString &rFileName)
Definition: lex.cxx:84
char GetNextChar()
Definition: lex.cxx:127
SvToken & GetToken() const
Definition: lex.hxx:177
std::vector< std::unique_ptr< SvToken > >::iterator pCurToken
Definition: lex.hxx:112
~SvTokenStream()
Definition: lex.cxx:91
void CalcColumn()
Definition: lex.hxx:136
OString aBufStr
Definition: lex.hxx:114
SvToken & GetToken_PrevAll()
Definition: lex.hxx:154
bool ReadIf(char cChar)
Definition: lex.hxx:179
SvToken & GetToken_Next()
Definition: lex.hxx:165
std::vector< std::unique_ptr< SvToken > > aTokList
Definition: lex.hxx:111
char GetFastNextChar()
Definition: lex.hxx:119
void SeekToMax()
Definition: lex.hxx:208
sal_uInt64 nLine
Definition: lex.hxx:101
sal_uInt64 nColumn
Definition: lex.hxx:101
char c
Definition: lex.hxx:103
sal_uInt32 nMaxPos
Definition: lex.hxx:107
const OUString & GetFileName() const
Definition: lex.hxx:151
std::unique_ptr< SvFileStream > pInStream
Definition: lex.hxx:109
sal_uInt64 GetNumber()
Definition: lex.cxx:151
OUString aFileName
Definition: lex.hxx:110
static const sal_uInt16 nTabSize
Definition: lex.hxx:104
void InitCtor()
Definition: lex.cxx:73
void ReadIfDelimiter()
Definition: lex.hxx:190
sal_uInt32 Tell() const
Definition: lex.hxx:200
bool IsEof() const
Definition: lex.hxx:129
sal_Int32 nBufPos
Definition: lex.hxx:102
void FillTokenList()
Definition: lex.cxx:95
Definition: lex.hxx:36
bool IsBool() const
Definition: lex.hxx:65
sal_uInt64 GetColumn() const
Definition: lex.hxx:60
char cChar
Definition: lex.hxx:45
sal_uInt64 GetLine() const
Definition: lex.hxx:57
void SetColumn(sal_uInt64 nColumnP)
Definition: lex.hxx:59
sal_uInt64 nColumn
Definition: lex.hxx:38
bool IsChar() const
Definition: lex.hxx:73
bool IsComment() const
Definition: lex.hxx:62
SvToken()
Definition: lex.hxx:92
OString GetTokenAsString() const
Definition: lex.cxx:27
bool IsIdentifierHash() const
Definition: lex.hxx:66
void SetLine(sal_uInt64 nLineP)
Definition: lex.hxx:56
sal_uInt64 nLine
Definition: lex.hxx:38
bool IsString() const
Definition: lex.hxx:64
sal_uInt64 GetNumber() const
Definition: lex.hxx:82
bool bBool
Definition: lex.hxx:44
bool GetBool() const
Definition: lex.hxx:83
bool Is(SvStringHashEntry const *pEntry) const
Definition: lex.hxx:88
bool IsEof() const
Definition: lex.hxx:74
char GetChar() const
Definition: lex.hxx:84
void SetHash(SvStringHashEntry *pHashP)
Definition: lex.hxx:86
bool IsIdentifier() const
Definition: lex.hxx:68
OString aString
Definition: lex.hxx:40
SVTOKENTYPE nType
Definition: lex.hxx:39
sal_uInt64 nLong
Definition: lex.hxx:43
SvToken & operator=(const SvToken &rObj)
Definition: lex.cxx:60
bool IsInteger() const
Definition: lex.hxx:63
const OString & GetString() const
Definition: lex.hxx:76
SvStringHashEntry * pHash
Definition: lex.hxx:46
SvToken(const SvToken &rObj)=delete
sal_Int64 n
SVTOKENTYPE
Definition: lex.hxx:29
sal_uInt16 nPos
Empty
QPRO_FUNC_TYPE nType