]>
Commit | Line | Data |
---|---|---|
b12a9965 | 1 | /* Cycript - Optimizing JavaScript Compiler/Runtime |
c1d3e52e | 2 | * Copyright (C) 2009-2015 Jay Freeman (saurik) |
b12a9965 JF |
3 | */ |
4 | ||
f95d2598 | 5 | /* GNU Affero General Public License, Version 3 {{{ */ |
b12a9965 | 6 | /* |
f95d2598 JF |
7 | * This program is free software: you can redistribute it and/or modify |
8 | * it under the terms of the GNU Affero General Public License as published by | |
9 | * the Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | ||
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
b12a9965 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f95d2598 JF |
15 | * GNU Affero General Public License for more details. |
16 | ||
17 | * You should have received a copy of the GNU Affero General Public License | |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
b12a9965 JF |
19 | **/ |
20 | /* }}} */ | |
21 | ||
22 | #ifndef CYCRIPT_DRIVER_HPP | |
23 | #define CYCRIPT_DRIVER_HPP | |
24 | ||
25 | #include <iostream> | |
26 | ||
27 | #include <stack> | |
28 | #include <string> | |
29 | #include <vector> | |
30 | ||
58afc6aa | 31 | #include "Location.hpp" |
b12a9965 JF |
32 | #include "Parser.hpp" |
33 | ||
34 | enum CYState { | |
35 | CYClear, | |
36 | CYRestricted, | |
37 | CYNewLine | |
38 | }; | |
39 | ||
d9c91152 | 40 | class _visible CYDriver { |
b12a9965 JF |
41 | public: |
42 | void *scanner_; | |
43 | ||
44 | CYState state_; | |
45 | std::stack<bool> in_; | |
46 | ||
47 | struct { | |
48 | bool AtImplementation; | |
49 | bool Function; | |
50 | bool OpenBrace; | |
51 | } no_; | |
52 | ||
53 | std::istream &data_; | |
54 | ||
d9c91152 | 55 | int debug_; |
b12a9965 JF |
56 | bool strict_; |
57 | bool commented_; | |
58 | ||
59 | enum Condition { | |
60 | RegExpCondition, | |
61 | XMLContentCondition, | |
62 | XMLTagCondition, | |
63 | }; | |
64 | ||
65 | std::string filename_; | |
66 | ||
67 | struct Error { | |
68 | bool warning_; | |
58afc6aa | 69 | CYLocation location_; |
b12a9965 JF |
70 | std::string message_; |
71 | }; | |
72 | ||
73 | typedef std::vector<Error> Errors; | |
74 | ||
75 | CYProgram *program_; | |
76 | Errors errors_; | |
77 | ||
78 | bool auto_; | |
79 | ||
80 | struct Context { | |
81 | CYExpression *context_; | |
82 | ||
83 | Context(CYExpression *context) : | |
84 | context_(context) | |
85 | { | |
86 | } | |
87 | ||
88 | typedef std::vector<CYWord *> Words; | |
89 | Words words_; | |
90 | }; | |
91 | ||
92 | typedef std::vector<Context> Contexts; | |
93 | Contexts contexts_; | |
94 | ||
95 | CYExpression *context_; | |
96 | ||
97 | enum Mode { | |
98 | AutoNone, | |
99 | AutoPrimary, | |
100 | AutoDirect, | |
101 | AutoIndirect, | |
102 | AutoMessage | |
103 | } mode_; | |
104 | ||
105 | private: | |
106 | void ScannerInit(); | |
107 | void ScannerDestroy(); | |
108 | ||
109 | public: | |
110 | CYDriver(std::istream &data, const std::string &filename = ""); | |
111 | ~CYDriver(); | |
112 | ||
d9c91152 JF |
113 | bool Parse(CYPool &pool); |
114 | void Replace(CYPool &pool, CYOptions &options); | |
115 | ||
b12a9965 JF |
116 | Condition GetCondition(); |
117 | void SetCondition(Condition condition); | |
118 | ||
119 | void PushCondition(Condition condition); | |
120 | void PopCondition(); | |
121 | ||
58afc6aa | 122 | void Warning(const CYLocation &location, const char *message); |
b12a9965 JF |
123 | }; |
124 | ||
125 | #endif/*CYCRIPT_DRIVER_HPP*/ |