1 /* 2 * Copyright (C) 1999-2001 Harri Porten (porten (at) kde.org) 3 * Copyright (C) 2001 Peter Kelly (pmk (at) post.com) 4 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #include "config.h" 24 #include "Parser.h" 25 26 #include "Debugger.h" 27 #include "Lexer.h" 28 #include <wtf/HashSet.h> 29 #include <wtf/Vector.h> 30 #include <memory> 31 32 using std::auto_ptr; 33 34 #ifndef yyparse 35 extern int jscyyparse(void*); 36 #endif 37 38 #ifdef ANDROID_INSTRUMENT 39 #include "TimeCounter.h" 40 #endif 41 42 namespace JSC { 43 44 void Parser::parse(JSGlobalData* globalData, int* errLine, UString* errMsg) 45 { 46 #ifdef ANDROID_INSTRUMENT 47 android::TimeCounter::start(android::TimeCounter::JavaScriptParseTimeCounter); 48 #endif 49 m_sourceElements = 0; 50 51 int defaultErrLine; 52 UString defaultErrMsg; 53 54 if (!errLine) 55 errLine = &defaultErrLine; 56 if (!errMsg) 57 errMsg = &defaultErrMsg; 58 59 *errLine = -1; 60 *errMsg = UString(); 61 62 Lexer& lexer = *globalData->lexer; 63 lexer.setCode(*m_source, m_arena); 64 65 int parseError = jscyyparse(globalData); 66 bool lexError = lexer.sawError(); 67 int lineNumber = lexer.lineNumber(); 68 lexer.clear(); 69 70 if (parseError || lexError) { 71 *errLine = lineNumber; 72 *errMsg = "Parse error"; 73 m_sourceElements = 0; 74 } 75 #ifdef ANDROID_INSTRUMENT 76 android::TimeCounter::record(android::TimeCounter::JavaScriptParseTimeCounter, __FUNCTION__); 77 #endif 78 } 79 80 void Parser::didFinishParsing(SourceElements* sourceElements, ParserArenaData<DeclarationStacks::VarStack>* varStack, 81 ParserArenaData<DeclarationStacks::FunctionStack>* funcStack, CodeFeatures features, int lastLine, int numConstants) 82 { 83 m_sourceElements = sourceElements; 84 m_varDeclarations = varStack; 85 m_funcDeclarations = funcStack; 86 m_features = features; 87 m_lastLine = lastLine; 88 m_numConstants = numConstants; 89 } 90 91 } // namespace JSC 92