bool QSEngine::checkSyntax(const QString &code, int checkMode, bool deleteNodes) { return rep->evaluate(code, 0, true, checkMode); #if 0 Q_UNUSED(checkMode); Q_ASSERT(QSLexer::lexer()); #if defined (QT_THREAD_SUPPORT) && QT_VERSION >= 0x030300 QMutexLocker locker(qt_global_mutexpool ? qt_global_mutexpool->get(QSLexer::lexer()) : 0); #endif rep->errType = 0; rep->errLines.clear(); rep->errMsgs.clear(); QSLexer::lexer()->setCode(code, #ifdef QSDEBUGGER rep->sourceId() #else 0 #endif ); int parseError = qsyyparse(); QSNode *lastNode = QSProgramNode::last(); bool success = true; if (parseError) { rep->errType = QSErrParseError; int l = QSLexer::lexer()->lineNo(); rep->errLines.append(l); rep->errMsgs.append(QString::fromLatin1("Parse Error: ") + qs_format_error(QSLexer::lexer()->errorMessage())); success = false; } if (deleteNodes && lastNode && lastNode->deref()) delete lastNode; return success; #endif }
// eval() static QSObject qsEval( QSEnv *env ) { QSObject x = env->arg( 0 ); if ( !x.isString() ) { return x; } else { QSEngineImp *eimp = env->engine()->imp(); QString s = x.toString(); QSNode *progNode = 0; { // begin mutext locker QMutexLocker locker(qsa_lexer_mutex()); QSLexer::lexer()->setCode( s, #ifdef QSDEBUGGER eimp->sourceId() #else 0 #endif ); int yp = qsyyparse(); progNode = QSProgramNode::last(); if ( yp || QSLexer::lexer()->lexerState() == QSLexer::Bad ) { if (!progNode && progNode->deref()) delete progNode; return env->throwError( SyntaxError ); } } // end mutext locker QSCheckData data( env ); QSObject scopeTop = env->currentScope(); postfixAdd( scopeTop.objectType(), &data ); QSEvalScopeClass *cl = new QSEvalScopeClass( env->objectClass() ); data.enterEval( cl ); progNode->check( &data ); if ( data.hasError() ) { if (!progNode->deref()) delete progNode; return env->throwError( EvalError, data.errorMessages().first(), data.errorLines().first() ); } QSList empty; env->pushScope( cl->construct( empty ) ); // ### delete tmp scope class QSObject res = ((QSProgramNode*)progNode)->execute( env ); if (!progNode->deref()) delete progNode; env->popScope(); if ( env->isReturnValueMode() ) return res; else if ( env->isNormalMode() ) { if ( res.isValid() ) return res; else return env->createUndefined(); } else return res; } }