summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/parser/parser.patch
blob: 4c56a5e2d59cb5498dcf1619b0d70c6e0bf2bb95 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
diff --git a/src/libs/qmljs/parser/qmljsengine_p.cpp b/src/libs/qmljs/parser/qmljsengine_p.cpp
index 73850bb..d7d2189 100644
--- a/src/libs/qmljs/parser/qmljsengine_p.cpp
+++ b/src/libs/qmljs/parser/qmljsengine_p.cpp
@@ -110,7 +110,7 @@ double integerFromString(const QString &str, int radix)
 
 
 Engine::Engine()
-    : _lexer(0)
+    : _lexer(0), _directives(0)
 { }
 
 Engine::~Engine()
@@ -131,6 +131,12 @@ Lexer *Engine::lexer() const
 void Engine::setLexer(Lexer *lexer)
 { _lexer = lexer; }
 
+void Engine::setDirectives(Directives *directives)
+{ _directives = directives; }
+
+Directives *Engine::directives() const
+{ return _directives; }
+
 MemoryPool *Engine::pool()
 { return &_pool; }
 
diff --git a/src/libs/qmljs/parser/qmljsengine_p.h b/src/libs/qmljs/parser/qmljsengine_p.h
index d4ed4b37..4908e02 100644
--- a/src/libs/qmljs/parser/qmljsengine_p.h
+++ b/src/libs/qmljs/parser/qmljsengine_p.h
@@ -53,6 +53,7 @@ QT_QML_BEGIN_NAMESPACE
 namespace QmlJS {
 
 class Lexer;
+class Directives;
 class MemoryPool;
 
 class QML_PARSER_EXPORT DiagnosticMessage
@@ -80,6 +81,7 @@ public:
 class QML_PARSER_EXPORT Engine
 {
     Lexer *_lexer;
+    Directives *_directives;
     MemoryPool _pool;
     QList<AST::SourceLocation> _comments;
     QString _extraCode;
@@ -97,6 +99,9 @@ public:
     Lexer *lexer() const;
     void setLexer(Lexer *lexer);
 
+    void setDirectives(Directives *directives);
+    Directives *directives() const;
+
     MemoryPool *pool();
 
     inline QStringRef midRef(int position, int size) { return _code.midRef(position, size); }
diff --git a/src/libs/qmljs/parser/qmljsparser.cpp b/src/libs/qmljs/parser/qmljsparser.cpp
index d53960b..71e994f 100644
--- a/src/libs/qmljs/parser/qmljsparser.cpp
+++ b/src/libs/qmljs/parser/qmljsparser.cpp
@@ -143,7 +143,20 @@ bool Parser::parse(int startToken)
 
     token_buffer[0].token = startToken;
     first_token = &token_buffer[0];
-    last_token = &token_buffer[1];
+    if (startToken == T_FEED_JS_PROGRAM) {
+        Directives ignoreDirectives;
+        Directives *directives = driver->directives();
+        if (!directives)
+            directives = &ignoreDirectives;
+        lexer->scanDirectives(directives);
+        token_buffer[1].token = lexer->tokenKind();
+        token_buffer[1].dval = lexer->tokenValue();
+        token_buffer[1].loc = location(lexer);
+        token_buffer[1].spell = lexer->tokenSpell();
+        last_token = &token_buffer[2];
+    } else {
+        last_token = &token_buffer[1];
+    }
 
     tos = -1;
     program = 0;
diff --git a/src/libs/qmljs/parser/qmlerror.cpp b/src/libs/qmljs/parser/qmlerror.cpp
index a244235..e334ae9 100644
--- a/src/libs/qmljs/parser/qmlerror.cpp
+++ b/src/libs/qmljs/parser/qmlerror.cpp
@@ -63,6 +63,12 @@ QT_BEGIN_NAMESPACE
 
     \sa QQuickView::errors(), QmlComponent::errors()
 */
+
+static quint16 qmlSourceCoordinate(int n)
+{
+    return (n > 0 && n <= static_cast<int>(USHRT_MAX)) ? static_cast<quint16>(n) : 0;
+}
+
 class QmlErrorPrivate
 {
 public:
diff --git a/src/libs/qmljs/parser/qmljskeywords_p.h b/src/libs/qmljs/parser/qmljskeywords_p.h
index 3c827da..e981040 100644
--- a/src/libs/qmljs/parser/qmljskeywords_p.h
+++ b/src/libs/qmljs/parser/qmljskeywords_p.h
@@ -41,6 +41,12 @@
 // We mean it.
 //
 
+// Note on the int() casts in the following code:
+// they casts values from Lexer's anonymous enum (aliasing some of the inherited
+// QmlJSGrammar::VariousConstants) to int when used with inherited values of the
+// enum QmlJSGrammar::VariousConstants in a ?: expression to suppress gcc
+// "enumeral mismatch" warning
+
 static inline int classify2(const QChar *s, bool qmlMode) {
   if (s[0].unicode() == 'a') {
     if (s[1].unicode() == 's') {
@@ -79,7 +85,7 @@ static inline int classify3(const QChar *s, bool qmlMode) {
   else if (s[0].unicode() == 'i') {
     if (s[1].unicode() == 'n') {
       if (s[2].unicode() == 't') {
-        return qmlMode ? Lexer::T_INT : Lexer::T_IDENTIFIER;
+        return qmlMode ? int(Lexer::T_INT) : Lexer::T_IDENTIFIER;
       }
     }
   }
@@ -112,7 +118,7 @@ static inline int classify4(const QChar *s, bool qmlMode) {
     if (s[1].unicode() == 'y') {
       if (s[2].unicode() == 't') {
         if (s[3].unicode() == 'e') {
-          return qmlMode ? Lexer::T_BYTE : Lexer::T_IDENTIFIER;
+          return qmlMode ? int(Lexer::T_BYTE) : Lexer::T_IDENTIFIER;
         }
       }
     }
@@ -128,7 +134,7 @@ static inline int classify4(const QChar *s, bool qmlMode) {
     else if (s[1].unicode() == 'h') {
       if (s[2].unicode() == 'a') {
         if (s[3].unicode() == 'r') {
-          return qmlMode ? Lexer::T_CHAR : Lexer::T_IDENTIFIER;
+          return qmlMode ? int(Lexer::T_CHAR) : Lexer::T_IDENTIFIER;
         }
       }
     }
@@ -153,7 +159,7 @@ static inline int classify4(const QChar *s, bool qmlMode) {
     if (s[1].unicode() == 'o') {
       if (s[2].unicode() == 't') {
         if (s[3].unicode() == 'o') {
-          return qmlMode ? Lexer::T_GOTO : Lexer::T_IDENTIFIER;
+          return qmlMode ? int(Lexer::T_GOTO) : Lexer::T_IDENTIFIER;
         }
       }
     }
@@ -162,7 +168,7 @@ static inline int classify4(const QChar *s, bool qmlMode) {
     if (s[1].unicode() == 'o') {
       if (s[2].unicode() == 'n') {
         if (s[3].unicode() == 'g') {
-          return qmlMode ? Lexer::T_LONG : Lexer::T_IDENTIFIER;
+          return qmlMode ? int(Lexer::T_LONG) : Lexer::T_IDENTIFIER;
         }
       }
     }
@@ -268,7 +274,7 @@ static inline int classify5(const QChar *s, bool qmlMode) {
       if (s[2].unicode() == 'n') {
         if (s[3].unicode() == 'a') {
           if (s[4].unicode() == 'l') {
-            return qmlMode ? Lexer::T_FINAL : Lexer::T_IDENTIFIER;
+            return qmlMode ? int(Lexer::T_FINAL) : Lexer::T_IDENTIFIER;
           }
         }
       }
@@ -277,7 +283,7 @@ static inline int classify5(const QChar *s, bool qmlMode) {
       if (s[2].unicode() == 'o') {
         if (s[3].unicode() == 'a') {
           if (s[4].unicode() == 't') {
-            return qmlMode ? Lexer::T_FLOAT : Lexer::T_IDENTIFIER;
+            return qmlMode ? int(Lexer::T_FLOAT) : Lexer::T_IDENTIFIER;
           }
         }
       }
@@ -288,7 +294,7 @@ static inline int classify5(const QChar *s, bool qmlMode) {
       if (s[2].unicode() == 'o') {
         if (s[3].unicode() == 'r') {
           if (s[4].unicode() == 't') {
-            return qmlMode ? Lexer::T_SHORT : Lexer::T_IDENTIFIER;
+            return qmlMode ? int(Lexer::T_SHORT) : Lexer::T_IDENTIFIER;
           }
         }
       }
@@ -297,7 +303,7 @@ static inline int classify5(const QChar *s, bool qmlMode) {
       if (s[2].unicode() == 'p') {
         if (s[3].unicode() == 'e') {
           if (s[4].unicode() == 'r') {
-            return qmlMode ? Lexer::T_SUPER : Lexer::T_IDENTIFIER;
+            return qmlMode ? int(Lexer::T_SUPER) : Lexer::T_IDENTIFIER;
           }
         }
       }
@@ -346,7 +352,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
         if (s[3].unicode() == 'b') {
           if (s[4].unicode() == 'l') {
             if (s[5].unicode() == 'e') {
-              return qmlMode ? Lexer::T_DOUBLE : Lexer::T_IDENTIFIER;
+              return qmlMode ? int(Lexer::T_DOUBLE) : Lexer::T_IDENTIFIER;
             }
           }
         }
@@ -385,7 +391,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
         if (s[3].unicode() == 'i') {
           if (s[4].unicode() == 'v') {
             if (s[5].unicode() == 'e') {
-              return qmlMode ? Lexer::T_NATIVE : Lexer::T_IDENTIFIER;
+              return qmlMode ? int(Lexer::T_NATIVE) : Lexer::T_IDENTIFIER;
             }
           }
         }
@@ -435,7 +441,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
         if (s[3].unicode() == 't') {
           if (s[4].unicode() == 'i') {
             if (s[5].unicode() == 'c') {
-              return qmlMode ? Lexer::T_STATIC : Lexer::T_IDENTIFIER;
+              return qmlMode ? int(Lexer::T_STATIC) : Lexer::T_IDENTIFIER;
             }
           }
         }
@@ -459,7 +465,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
         if (s[3].unicode() == 'o') {
           if (s[4].unicode() == 'w') {
             if (s[5].unicode() == 's') {
-              return qmlMode ? Lexer::T_THROWS : Lexer::T_IDENTIFIER;
+              return qmlMode ? int(Lexer::T_THROWS) : Lexer::T_IDENTIFIER;
             }
           }
         }
@@ -488,7 +494,7 @@ static inline int classify7(const QChar *s, bool qmlMode) {
           if (s[4].unicode() == 'e') {
             if (s[5].unicode() == 'a') {
               if (s[6].unicode() == 'n') {
-                return qmlMode ? Lexer::T_BOOLEAN : Lexer::T_IDENTIFIER;
+                return qmlMode ? int(Lexer::T_BOOLEAN) : Lexer::T_IDENTIFIER;
               }
             }
           }
@@ -548,7 +554,7 @@ static inline int classify7(const QChar *s, bool qmlMode) {
           if (s[4].unicode() == 'a') {
             if (s[5].unicode() == 'g') {
               if (s[6].unicode() == 'e') {
-                return qmlMode ? Lexer::T_PACKAGE : Lexer::T_IDENTIFIER;
+                return qmlMode ? int(Lexer::T_PACKAGE) : Lexer::T_IDENTIFIER;
               }
             }
           }
@@ -561,7 +567,7 @@ static inline int classify7(const QChar *s, bool qmlMode) {
           if (s[4].unicode() == 'a') {
             if (s[5].unicode() == 't') {
               if (s[6].unicode() == 'e') {
-                return qmlMode ? Lexer::T_PRIVATE : Lexer::T_IDENTIFIER;
+                return qmlMode ? int(Lexer::T_PRIVATE) : Lexer::T_IDENTIFIER;
               }
             }
           }
@@ -581,7 +587,7 @@ static inline int classify8(const QChar *s, bool qmlMode) {
             if (s[5].unicode() == 'a') {
               if (s[6].unicode() == 'c') {
                 if (s[7].unicode() == 't') {
-                  return qmlMode ? Lexer::T_ABSTRACT : Lexer::T_IDENTIFIER;
+                    return qmlMode ? int(Lexer::T_ABSTRACT) : Lexer::T_IDENTIFIER;
                 }
               }
             }
@@ -683,7 +689,7 @@ static inline int classify8(const QChar *s, bool qmlMode) {
             if (s[5].unicode() == 'i') {
               if (s[6].unicode() == 'l') {
                 if (s[7].unicode() == 'e') {
-                  return qmlMode ? Lexer::T_VOLATILE : Lexer::T_IDENTIFIER;
+                  return qmlMode ? int(Lexer::T_VOLATILE) : Lexer::T_IDENTIFIER;
                 }
               }
             }
@@ -705,7 +711,7 @@ static inline int classify9(const QChar *s, bool qmlMode) {
               if (s[6].unicode() == 'a') {
                 if (s[7].unicode() == 'c') {
                   if (s[8].unicode() == 'e') {
-                    return qmlMode ? Lexer::T_INTERFACE : Lexer::T_IDENTIFIER;
+                    return qmlMode ? int(Lexer::T_INTERFACE) : Lexer::T_IDENTIFIER;
                   }
                 }
               }
@@ -724,7 +730,7 @@ static inline int classify9(const QChar *s, bool qmlMode) {
               if (s[6].unicode() == 't') {
                 if (s[7].unicode() == 'e') {
                   if (s[8].unicode() == 'd') {
-                    return qmlMode ? Lexer::T_PROTECTED : Lexer::T_IDENTIFIER;
+                    return qmlMode ? int(Lexer::T_PROTECTED) : Lexer::T_IDENTIFIER;
                   }
                 }
               }
@@ -743,7 +749,7 @@ static inline int classify9(const QChar *s, bool qmlMode) {
               if (s[6].unicode() == 'e') {
                 if (s[7].unicode() == 'n') {
                   if (s[8].unicode() == 't') {
-                    return qmlMode ? Lexer::T_TRANSIENT : Lexer::T_IDENTIFIER;
+                    return qmlMode ? int(Lexer::T_TRANSIENT) : Lexer::T_IDENTIFIER;
                   }
                 }
               }
@@ -767,7 +773,7 @@ static inline int classify10(const QChar *s, bool qmlMode) {
                 if (s[7].unicode() == 'n') {
                   if (s[8].unicode() == 't') {
                     if (s[9].unicode() == 's') {
-                      return qmlMode ? Lexer::T_IMPLEMENTS : Lexer::T_IDENTIFIER;
+                      return qmlMode ? int(Lexer::T_IMPLEMENTS) : Lexer::T_IDENTIFIER;
                     }
                   }
                 }
@@ -813,7 +819,7 @@ static inline int classify12(const QChar *s, bool qmlMode) {
                     if (s[9].unicode() == 'z') {
                       if (s[10].unicode() == 'e') {
                         if (s[11].unicode() == 'd') {
-                          return qmlMode ? Lexer::T_SYNCHRONIZED : Lexer::T_IDENTIFIER;
+                          return qmlMode ? int(Lexer::T_SYNCHRONIZED) : Lexer::T_IDENTIFIER;
                         }
                       }
                     }