qmljscheck.cpp 9.62 KB
Newer Older
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
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#include "qmljscheck.h"
31
32
#include "qmljsinterpreter.h"
#include "parser/qmljsparser_p.h"
33
#include "parser/qmljsast_p.h"
34
#include <QtCore/QDebug>
35
36

using namespace QmlJS;
37
using namespace QmlJS::Interpreter;
38

39
40
41
42
Check::Check(Interpreter::Engine *engine)
    : _engine(engine),
      _scope(engine->globalObject()),
      _result(0)
43
44
45
46
47
48
49
{
}

Check::~Check()
{
}

50
const Interpreter::Value *Check::operator()(AST::ExpressionNode *ast, const Interpreter::ObjectValue *scope)
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
    const Interpreter::ObjectValue *previousScope = switchScope(scope);
    const Interpreter::Value *result = check(ast);
    (void) switchScope(previousScope);
    return result;
}

const Interpreter::Value *Check::check(AST::ExpressionNode *ast)
{
    const Value *previousResult = switchResult(0);
    accept(ast);
    const Value *result = switchResult(previousResult);
    if (! result)
        result = _engine->undefinedValue();
    return result;
}

Interpreter::Engine *Check::switchEngine(Interpreter::Engine *engine)
{
    Interpreter::Engine *previousEngine = _engine;
    _engine = engine;
    return previousEngine;
}

const Interpreter::Value *Check::switchResult(const Interpreter::Value *result)
{
    const Interpreter::Value *previousResult = _result;
    _result = result;
    return previousResult;
}

const Interpreter::ObjectValue *Check::switchScope(const Interpreter::ObjectValue *scope)
{
    const Interpreter::ObjectValue *previousScope = _scope;
    _scope = scope;
    return previousScope;
87
88
89
90
91
92
93
94
95
}

void Check::accept(AST::Node *node)
{
    AST::Node::accept(node, this);
}

bool Check::visit(AST::UiProgram *)
{
96
    return false;
97
98
99
100
}

bool Check::visit(AST::UiImportList *)
{
101
    return false;
102
103
104
105
}

bool Check::visit(AST::UiImport *)
{
106
    return false;
107
108
109
110
}

bool Check::visit(AST::UiPublicMember *)
{
111
    return false;
112
113
114
115
}

bool Check::visit(AST::UiSourceElement *)
{
116
    return false;
117
118
119
120
}

bool Check::visit(AST::UiObjectDefinition *)
{
121
    return false;
122
123
124
125
}

bool Check::visit(AST::UiObjectInitializer *)
{
126
    return false;
127
128
129
130
}

bool Check::visit(AST::UiObjectBinding *)
{
131
    return false;
132
133
134
135
}

bool Check::visit(AST::UiScriptBinding *)
{
136
    return false;
137
138
139
140
}

bool Check::visit(AST::UiArrayBinding *)
{
141
    return false;
142
143
144
145
}

bool Check::visit(AST::UiObjectMemberList *)
{
146
    return false;
147
148
149
150
}

bool Check::visit(AST::UiArrayMemberList *)
{
151
    return false;
152
153
154
155
}

bool Check::visit(AST::UiQualifiedId *)
{
156
    return false;
157
158
159
160
}

bool Check::visit(AST::UiSignature *)
{
161
    return false;
162
163
164
165
}

bool Check::visit(AST::UiFormalList *)
{
166
    return false;
167
168
169
170
}

bool Check::visit(AST::UiFormal *)
{
171
    return false;
172
173
174
175
}

bool Check::visit(AST::ThisExpression *)
{
176
    return false;
177
178
}

179
bool Check::visit(AST::IdentifierExpression *ast)
180
{
181
182
183
184
185
    if (! ast->name)
        return false;

    _result = _scope->lookup(ast->name->asString());
    return false;
186
187
188
189
}

bool Check::visit(AST::NullExpression *)
{
190
191
    _result = _engine->nullValue();
    return false;
192
193
194
195
}

bool Check::visit(AST::TrueLiteral *)
{
196
197
    _result = _engine->booleanValue();
    return false;
198
199
200
201
}

bool Check::visit(AST::FalseLiteral *)
{
202
203
    _result = _engine->booleanValue();
    return false;
204
205
206
207
}

bool Check::visit(AST::StringLiteral *)
{
208
209
    _result = _engine->stringValue();
    return false;
210
211
212
213
}

bool Check::visit(AST::NumericLiteral *)
{
214
215
    _result = _engine->numberValue();
    return false;
216
217
218
219
}

bool Check::visit(AST::RegExpLiteral *)
{
220
221
    _result = _engine->regexpCtor()->construct();
    return false;
222
223
224
225
}

bool Check::visit(AST::ArrayLiteral *)
{
226
227
    _result = _engine->arrayCtor()->construct();
    return false;
228
229
230
231
}

bool Check::visit(AST::ObjectLiteral *)
{
232
    return false;
233
234
235
236
}

bool Check::visit(AST::ElementList *)
{
237
    return false;
238
239
240
241
}

bool Check::visit(AST::Elision *)
{
242
    return false;
243
244
245
246
}

bool Check::visit(AST::PropertyNameAndValueList *)
{
247
    return false;
248
249
250
251
}

bool Check::visit(AST::NestedExpression *)
{
252
    return true; // visit the child expression
253
254
255
256
}

bool Check::visit(AST::IdentifierPropertyName *)
{
257
    return false;
258
259
260
261
}

bool Check::visit(AST::StringLiteralPropertyName *)
{
262
    return false;
263
264
265
266
}

bool Check::visit(AST::NumericLiteralPropertyName *)
{
267
    return false;
268
269
270
271
}

bool Check::visit(AST::ArrayMemberExpression *)
{
272
    return false;
273
274
}

275
bool Check::visit(AST::FieldMemberExpression *ast)
276
{
277
278
279
280
281
282
283
284
285
286
    if (! ast->name)
        return false;

    if (const Interpreter::Value *base = _engine->convertToObject(check(ast->base))) {
        if (const Interpreter::ObjectValue *obj = base->asObjectValue()) {
            _result = obj->property(ast->name->asString());
        }
    }

    return false;
287
288
}

289
bool Check::visit(AST::NewMemberExpression *ast)
290
{
291
292
293
    if (const FunctionValue *ctor = value_cast<const FunctionValue *>(check(ast->base))) {
        _result = ctor->construct();
    }
294
    return false;
295
296
}

297
bool Check::visit(AST::NewExpression *ast)
298
{
299
300
301
    if (const FunctionValue *ctor = value_cast<const FunctionValue *>(check(ast->expression))) {
        _result = ctor->construct();
    }
302
    return false;
303
304
}

305
bool Check::visit(AST::CallExpression *ast)
306
{
307
308
309
310
311
312
    if (const Interpreter::Value *base = check(ast->base)) {
        if (const Interpreter::FunctionValue *obj = base->asFunctionValue()) {
            _result = obj->returnValue();
        }
    }
    return false;
313
314
315
316
}

bool Check::visit(AST::ArgumentList *)
{
317
    return false;
318
319
320
321
}

bool Check::visit(AST::PostIncrementExpression *)
{
322
    return false;
323
324
325
326
}

bool Check::visit(AST::PostDecrementExpression *)
{
327
    return false;
328
329
330
331
}

bool Check::visit(AST::DeleteExpression *)
{
332
    return false;
333
334
335
336
}

bool Check::visit(AST::VoidExpression *)
{
337
    return false;
338
339
340
341
}

bool Check::visit(AST::TypeOfExpression *)
{
342
    return false;
343
344
345
346
}

bool Check::visit(AST::PreIncrementExpression *)
{
347
    return false;
348
349
350
351
}

bool Check::visit(AST::PreDecrementExpression *)
{
352
    return false;
353
354
355
356
}

bool Check::visit(AST::UnaryPlusExpression *)
{
357
    return false;
358
359
360
361
}

bool Check::visit(AST::UnaryMinusExpression *)
{
362
    return false;
363
364
365
366
}

bool Check::visit(AST::TildeExpression *)
{
367
    return false;
368
369
370
371
}

bool Check::visit(AST::NotExpression *)
{
372
    return false;
373
374
375
376
}

bool Check::visit(AST::BinaryExpression *)
{
377
    return false;
378
379
380
381
}

bool Check::visit(AST::ConditionalExpression *)
{
382
    return false;
383
384
385
386
}

bool Check::visit(AST::Expression *)
{
387
    return false;
388
389
390
391
}

bool Check::visit(AST::Block *)
{
392
    return false;
393
394
395
396
}

bool Check::visit(AST::StatementList *)
{
397
    return false;
398
399
400
401
}

bool Check::visit(AST::VariableStatement *)
{
402
    return false;
403
404
405
406
}

bool Check::visit(AST::VariableDeclarationList *)
{
407
    return false;
408
409
410
411
}

bool Check::visit(AST::VariableDeclaration *)
{
412
    return false;
413
414
415
416
}

bool Check::visit(AST::EmptyStatement *)
{
417
    return false;
418
419
420
421
}

bool Check::visit(AST::ExpressionStatement *)
{
422
    return false;
423
424
425
426
}

bool Check::visit(AST::IfStatement *)
{
427
    return false;
428
429
430
431
}

bool Check::visit(AST::DoWhileStatement *)
{
432
    return false;
433
434
435
436
}

bool Check::visit(AST::WhileStatement *)
{
437
    return false;
438
439
440
441
}

bool Check::visit(AST::ForStatement *)
{
442
    return false;
443
444
445
446
}

bool Check::visit(AST::LocalForStatement *)
{
447
    return false;
448
449
450
451
}

bool Check::visit(AST::ForEachStatement *)
{
452
    return false;
453
454
455
456
}

bool Check::visit(AST::LocalForEachStatement *)
{
457
    return false;
458
459
460
461
}

bool Check::visit(AST::ContinueStatement *)
{
462
    return false;
463
464
465
466
}

bool Check::visit(AST::BreakStatement *)
{
467
    return false;
468
469
470
471
}

bool Check::visit(AST::ReturnStatement *)
{
472
    return false;
473
474
475
476
}

bool Check::visit(AST::WithStatement *)
{
477
    return false;
478
479
480
481
}

bool Check::visit(AST::SwitchStatement *)
{
482
    return false;
483
484
485
486
}

bool Check::visit(AST::CaseBlock *)
{
487
    return false;
488
489
490
491
}

bool Check::visit(AST::CaseClauses *)
{
492
    return false;
493
494
495
496
}

bool Check::visit(AST::CaseClause *)
{
497
    return false;
498
499
500
501
}

bool Check::visit(AST::DefaultClause *)
{
502
    return false;
503
504
505
506
}

bool Check::visit(AST::LabelledStatement *)
{
507
    return false;
508
509
510
511
}

bool Check::visit(AST::ThrowStatement *)
{
512
    return false;
513
514
515
516
}

bool Check::visit(AST::TryStatement *)
{
517
    return false;
518
519
520
521
}

bool Check::visit(AST::Catch *)
{
522
    return false;
523
524
525
526
}

bool Check::visit(AST::Finally *)
{
527
    return false;
528
529
530
531
}

bool Check::visit(AST::FunctionDeclaration *)
{
532
    return false;
533
534
535
536
}

bool Check::visit(AST::FunctionExpression *)
{
537
    return false;
538
539
540
541
}

bool Check::visit(AST::FormalParameterList *)
{
542
    return false;
543
544
545
546
}

bool Check::visit(AST::FunctionBody *)
{
547
    return false;
548
549
550
551
}

bool Check::visit(AST::Program *)
{
552
    return false;
553
554
555
556
}

bool Check::visit(AST::SourceElements *)
{
557
    return false;
558
559
560
561
}

bool Check::visit(AST::FunctionSourceElement *)
{
562
    return false;
563
564
565
566
}

bool Check::visit(AST::StatementSourceElement *)
{
567
    return false;
568
569
570
571
}

bool Check::visit(AST::DebuggerStatement *)
{
572
    return false;
573
}