]> git.saurik.com Git - cycript.git/blob - Driver.hpp
Clean up dependencies now that they are tracked.
[cycript.git] / Driver.hpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2013 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cycript is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cycript is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cycript. 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.hh"
32
33 #include "Parser.hpp"
34
35 enum CYState {
36 CYClear,
37 CYRestricted,
38 CYNewLine
39 };
40
41 class CYDriver {
42 public:
43 void *scanner_;
44
45 CYState state_;
46 std::stack<bool> in_;
47
48 struct {
49 bool AtImplementation;
50 bool Function;
51 bool OpenBrace;
52 } no_;
53
54 std::istream &data_;
55
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 cy::location 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 Condition GetCondition();
114 void SetCondition(Condition condition);
115
116 void PushCondition(Condition condition);
117 void PopCondition();
118
119 void Warning(const cy::location &location, const char *message);
120 };
121
122 #endif/*CYCRIPT_DRIVER_HPP*/