-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPPCodeUnitStream.h
More file actions
55 lines (47 loc) · 1.96 KB
/
PPCodeUnitStream.h
File metadata and controls
55 lines (47 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef PPCodeUnitStream_h
#define PPCodeUnitStream_h
#include "PPCodeUnit.h"
#include "UTF32StreamIfc.h"
#include "PPCodeUnitStreamIfc.h"
#include <queue>
#include <string>
// Stream UTF32 code points into stream of PPCodeUnit that is easy to tokenize.
//
// - Line splicing. i.e., occurrences of "\\\n" are replaced with
// PPCodeUnitType::WhitespaceCharacter so that we can revert it in raw strings.
//
// - Comments are streamed into PPCodeUnitType::Comment objects. Other tools
// can extract the comment strings for more processing
//
// - Digraphs and universal-character-names are also extracted out and can be
// reverted in raw strings.
class PPCodeUnitStream: public PPCodeUnitStreamIfc {
public:
PPCodeUnitStream(std::shared_ptr<UTF32StreamIfc>);
virtual bool isEmpty() const override;
virtual const std::shared_ptr<PPCodeUnit> getCodeUnit() const override;
virtual void toNext() override;
std::string getErrorMessage() const;
private:
std::shared_ptr<UTF32StreamIfc> _u32stream;
// Error reporting related stuff.
void _setError(const std::string&&);
void _clearError();
std::string _errorMessage;
// _pushCodeUnits() parses the input stream and pushes one or more PPCodeUnits
// to _queue, depending on the content being parsed. Used by toNext() in the
// following way: The toNext() function simply pops an element from _queue. If
// _queue is empty after poping an element, toNext() calls _pushCodeUnits() to
// try replenishing the _queue.
//
// Unless isEmpty() evaluates to true, the _queue always has at least one
// element outside of the scope of the toNext() function, so that a)
// getCodeUnit() has a super simple form, and b) the actual parsing of the
// input stream is delayed as much as possible.
//
// When isEmpty() evaluates to true iff. both the input stream and the
// _queue are empty.
void _pushCodeUnits();
std::queue<std::shared_ptr<PPCodeUnit>> _queue;
};
#endif /* end of include guard */