]> git.saurik.com Git - cycript.git/blob - Driver.hpp
634177aaeb3a7b4154bda9c33c57c96c434c91b7
[cycript.git] / Driver.hpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
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
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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/>.
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
31 #include "Location.hpp"
32 #include "Parser.hpp"
33
34 class _visible CYDriver {
35 public:
36 CYPool &pool_;
37 void *scanner_;
38
39 std::vector<char> buffer_;
40 bool tail_;
41
42 std::stack<bool> in_;
43 std::stack<bool> template_;
44
45 bool newline_;
46 bool last_;
47
48 struct {
49 bool Class;
50 bool Function;
51 bool OpenBrace;
52 bool NewLine;
53 } no_;
54
55 std::istream &data_;
56
57 int debug_;
58 bool strict_;
59 bool highlight_;
60
61 enum Condition {
62 RegExpCondition,
63 XMLContentCondition,
64 XMLTagCondition,
65 };
66
67 std::string filename_;
68
69 struct Error {
70 bool warning_;
71 CYLocation location_;
72 std::string message_;
73 };
74
75 typedef std::vector<Error> Errors;
76
77 CYScript *script_;
78 Errors errors_;
79
80 bool auto_;
81
82 struct Context {
83 CYExpression *context_;
84
85 Context(CYExpression *context) :
86 context_(context)
87 {
88 }
89
90 typedef std::vector<CYWord *> Words;
91 Words words_;
92 };
93
94 typedef std::vector<Context> Contexts;
95 Contexts contexts_;
96
97 CYExpression *context_;
98
99 enum Mode {
100 AutoNone,
101 AutoPrimary,
102 AutoDirect,
103 AutoIndirect,
104 AutoMessage
105 } mode_;
106
107 private:
108 void ScannerInit();
109 void ScannerDestroy();
110
111 public:
112 CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
113 ~CYDriver();
114
115 bool Parse();
116 void Replace(CYOptions &options);
117
118 void SetCondition(Condition condition);
119
120 void PushCondition(Condition condition);
121 void PopCondition();
122
123 void Warning(const CYLocation &location, const char *message);
124 };
125
126 #endif/*CYCRIPT_DRIVER_HPP*/