]> git.saurik.com Git - cycript.git/blob - Driver.hpp
CYPool::str*dup was leaking memory via global new.
[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 enum CYState {
35 CYClear,
36 CYRestricted,
37 CYNewLine
38 };
39
40 class _visible CYDriver {
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
55 int debug_;
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_;
69 CYLocation location_;
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
113 bool Parse(CYPool &pool);
114 void Replace(CYPool &pool, CYOptions &options);
115
116 Condition GetCondition();
117 void SetCondition(Condition condition);
118
119 void PushCondition(Condition condition);
120 void PopCondition();
121
122 void Warning(const CYLocation &location, const char *message);
123 };
124
125 #endif/*CYCRIPT_DRIVER_HPP*/