Changeset 27842 in webkit for trunk/JavaScriptCore
- Timestamp:
- Nov 15, 2007, 10:54:09 PM (18 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r27831 r27842 1 2007-11-15 Geoffrey Garen <[email protected]> 2 3 Reviewed by Eric Seidel. 4 5 Another round of grammar / parsing cleanup. 6 7 1. Created distinct parser calls for parsing function bodies vs 8 programs. This will help later with optimizing global variable access. 9 10 2. Turned Parser into a singleton. Cleaned up Lexer's singleton 11 interface. 12 13 3. Modified Lexer to free a little more memory when done lexing. (Added 14 FIXMEs for similar issues that I didn't fix.) 15 16 4. Changed Lexer::makeIdentifier and Lexer::makeUString to start 17 respecting the arguments passed to them. (No behavior change, but this 18 problem could have caused serious problems for an unsuspecting user of 19 these functions.) 20 21 5. Removed KJS_DEBUG_MEM because it was bit-rotted. 22 23 6. Removed Parser::prettyPrint because the same work was simpler to do 24 at the call site. 25 26 7. Some renames: 27 28 "Parser::accept" => "Parser::didFinishParsing" 29 "Parser::sid" => "Parser::m_sourceID" 30 "Lexer::doneParsing" => "Lexer::clear" 31 "sid" => "sourceId" 32 "lineno" => "lineNo" 33 34 * JavaScriptCore.exp: 35 * kjs/Parser.cpp: 36 (KJS::Parser::Parser): 37 (KJS::Parser::parseProgram): 38 (KJS::Parser::parseFunctionBody): 39 (KJS::Parser::parse): 40 (KJS::Parser::didFinishParsing): 41 (KJS::parser): 42 * kjs/Parser.h: 43 (KJS::Parser::sourceId): 44 * kjs/function.cpp: 45 (KJS::GlobalFuncImp::callAsFunction): 46 * kjs/function_object.cpp: 47 (FunctionObjectImp::construct): 48 * kjs/grammar.y: 49 * kjs/interpreter.cpp: 50 (KJS::Interpreter::checkSyntax): 51 (KJS::Interpreter::evaluate): 52 * kjs/interpreter.h: 53 * kjs/lexer.cpp: 54 (kjsyylex): 55 (KJS::lexer): 56 (KJS::Lexer::Lexer): 57 (KJS::Lexer::~Lexer): 58 (KJS::Lexer::scanRegExp): 59 (KJS::Lexer::doneParsing): 60 (KJS::Lexer::makeIdentifier): 61 (KJS::Lexer::makeUString): 62 * kjs/lexer.h: 63 (KJS::Lexer::pattern): 64 (KJS::Lexer::flags): 65 (KJS::Lexer::sawError): 66 * kjs/nodes.cpp: 67 (KJS::Node::Node): 68 (KJS::FunctionBodyNode::FunctionBodyNode): 69 * kjs/nodes.h: 70 * kjs/testkjs.cpp: 71 (prettyPrintScript): 72 (kjsmain): 73 * kjs/ustring.cpp: 74 * kjs/ustring.h: 75 1 76 2007-11-15 Oliver Hunt <[email protected]> 2 77 -
trunk/JavaScriptCore/JavaScriptCore.exp
r27746 r27842 164 164 __ZN3KJS4List15expandAndAppendEPNS_7JSValueE 165 165 __ZN3KJS4List7markSetEv 166 __ZN3KJS4Node5derefEv 166 167 __ZN3KJS6JSCell9getObjectEv 167 168 __ZN3KJS6JSCellnwEm … … 173 174 __ZN3KJS6JSLock9lockCountEv 174 175 __ZN3KJS6Lookup9findEntryEPKNS_9HashTableERKNS_10IdentifierE 175 __ZN3KJS6Parser11prettyPrintERKNS_7UStringEPiPS1_ 176 __ZN3KJS6Parser12parseProgramERKNS_7UStringEiPKNS_5UCharEjPiS7_PS1_ 177 __ZN3KJS6parserEv 176 178 __ZN3KJS7CStringD1Ev 177 179 __ZN3KJS7UString3Rep4nullE … … 207 209 __ZN3KJS8JSObject16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE 208 210 __ZN3KJS8JSObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE 211 __ZN3KJS8JSObject18getPrimitiveNumberEPNS_9ExecStateERdRPNS_7JSValueE 209 212 __ZN3KJS8JSObject22fillGetterPropertySlotERNS_12PropertySlotEPPNS_7JSValueE 210 213 __ZN3KJS8JSObject3putEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueEi … … 247 250 __ZNK3KJS19InternalFunctionImp21implementsHasInstanceEv 248 251 __ZNK3KJS4List8getSliceEiRS0_ 252 __ZNK3KJS4Node8toStringEv 249 253 __ZNK3KJS6JSCell17getTruncatedInt32ERi 250 254 __ZNK3KJS6JSCell17getTruncatedInt32ERi … … 271 275 __ZNK3KJS8JSObject12defaultValueEPNS_9ExecStateENS_6JSTypeE 272 276 __ZNK3KJS8JSObject14implementsCallEv 273 __ZN3KJS8JSObject18getPrimitiveNumberEPNS_9ExecStateERdRPNS_7JSValueE274 277 __ZNK3KJS8JSObject19implementsConstructEv 275 278 __ZNK3KJS8JSObject21implementsHasInstanceEv -
trunk/JavaScriptCore/kjs/Parser.cpp
r27215 r27842 4 4 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 5 5 * Copyright (C) 2001 Peter Kelly ([email protected]) 6 * Copyright (C) 2003, 2006 Apple Computer,Inc.6 * Copyright (C) 2003, 2006, 2007 Apple Inc. 7 7 * 8 8 * This library is free software; you can redistribute it and/or … … 31 31 #include <wtf/Vector.h> 32 32 33 extern int kjsyyparse();34 35 33 namespace KJS { 36 34 37 int Parser::sid = 0; 35 Parser::Parser() 36 : m_sourceId(0) 37 { 38 } 38 39 39 static RefPtr<ProgramNode>* progNode; 40 41 PassRefPtr<ProgramNode> Parser::parse(const UString& sourceURL, int startingLineNumber, 40 PassRefPtr<ProgramNode> Parser::parseProgram(const UString& sourceURL, int startingLineNumber, 42 41 const UChar* code, unsigned length, 43 42 int* sourceId, int* errLine, UString* errMsg) 44 43 { 44 parse(sourceURL, startingLineNumber, code, length, sourceId, errLine, errMsg); 45 return m_progNode.release(); 46 } 47 48 PassRefPtr<FunctionBodyNode> Parser::parseFunctionBody(const UString& sourceURL, int startingLineNumber, 49 const UChar* code, unsigned length, 50 int* sourceId, int* errLine, UString* errMsg) 51 { 52 parse(sourceURL, startingLineNumber, code, length, sourceId, errLine, errMsg); 53 return m_progNode.release(); 54 } 55 56 void Parser::parse(const UString& sourceURL, int startingLineNumber, 57 const UChar* code, unsigned length, 58 int* sourceId, int* errLine, UString* errMsg) 59 { 60 ASSERT(!m_progNode); 61 45 62 if (errLine) 46 63 *errLine = -1; 47 64 if (errMsg) 48 65 *errMsg = 0; 49 if (!progNode)50 progNode = new RefPtr<ProgramNode>;66 67 Lexer& lexer = KJS::lexer(); 51 68 52 Lexer::curr()->setCode(sourceURL, startingLineNumber, code, length); 53 *progNode = 0; 54 sid++; 69 lexer.setCode(sourceURL, startingLineNumber, code, length); 70 m_sourceId++; 55 71 if (sourceId) 56 *sourceId = sid; 57 58 // Enable this and the #define YYDEBUG in grammar.y to debug a parse error 59 //extern int kjsyydebug; 60 //kjsyydebug=1; 72 *sourceId = m_sourceId; 61 73 62 74 int parseError = kjsyyparse(); 63 bool lexError = Lexer::curr()->sawError(); 64 Lexer::curr()->doneParsing(); 65 PassRefPtr<ProgramNode> prog = progNode->release(); 66 *progNode = 0; 75 bool lexError = lexer.sawError(); 76 lexer.clear(); 67 77 68 78 Node::clearNewNodes(); 69 79 70 80 if (parseError || lexError) { 71 int eline = Lexer::curr()->lineNo();72 81 if (errLine) 73 *errLine = eline;82 *errLine = lexer.lineNo(); 74 83 if (errMsg) 75 84 *errMsg = "Parse error"; 76 return0;85 m_progNode = 0; 77 86 } 78 79 return prog;80 87 } 81 88 82 void Parser:: accept(PassRefPtr<ProgramNode> prog)89 void Parser::didFinishParsing(PassRefPtr<ProgramNode> progNode) 83 90 { 84 *progNode = prog;91 m_progNode = progNode; 85 92 } 86 93 87 UString Parser::prettyPrint(const UString& code, int* errLine, UString* errMsg)94 Parser& parser() 88 95 { 89 RefPtr<ProgramNode> progNode = parse(UString(), 0, code.data(), code.size(), 0, errLine, errMsg); 90 if (!progNode) 91 return 0; 92 93 return progNode->toString(); 96 ASSERT(JSLock::currentThreadIsHoldingLock()); 97 98 static Parser staticParser; 99 return staticParser; 94 100 } 95 101 96 } 102 } // namespace KJS -
trunk/JavaScriptCore/kjs/Parser.h
r27215 r27842 4 4 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 5 5 * Copyright (C) 2001 Peter Kelly ([email protected]) 6 * Copyright (C) 2003, 2006 Apple Computer,Inc.6 * Copyright (C) 2003, 2006, 2007 Apple Inc. 7 7 * 8 8 * This library is free software; you can redistribute it and/or … … 27 27 28 28 #include <wtf/Forward.h> 29 #include <wtf/RefPtr.h> 29 30 30 31 namespace KJS { 31 32 32 class Node;33 class FunctionBodyNode; 33 34 class ProgramNode; 34 35 class UString; … … 36 37 struct UChar; 37 38 38 /** 39 * @internal 40 * 41 * Parses ECMAScript source code and converts into ProgramNode objects, which 42 * represent the root of a parse tree. This class provides a convenient workaround 43 * for the problem of the bison parser working in a static context. 44 */ 45 class Parser { 39 class Parser : Noncopyable { 46 40 public: 47 static PassRefPtr<ProgramNode> parse(const UString& sourceURL, int startingLineNumber,41 PassRefPtr<ProgramNode> parseProgram(const UString& sourceURL, int startingLineNumber, 48 42 const UChar* code, unsigned length, 49 43 int* sourceId = 0, int* errLine = 0, UString* errMsg = 0); 50 44 51 static UString prettyPrint(const UString&, int* errLine = 0, UString* errMsg = 0); 45 PassRefPtr<FunctionBodyNode> parseFunctionBody(const UString& sourceURL, int startingLineNumber, 46 const UChar* code, unsigned length, 47 int* sourceId = 0, int* errLine = 0, UString* errMsg = 0); 48 49 int sourceId() { return m_sourceId; } 52 50 53 static void accept(PassRefPtr<ProgramNode>);51 void didFinishParsing(PassRefPtr<ProgramNode>); 54 52 55 static void saveNewNode(Node*); 53 private: 54 friend Parser& parser(); 56 55 57 static int sid; 56 Parser(); // Use parser() instead. 57 void parse(const UString& sourceURL, int startingLineNumber, 58 const UChar* code, unsigned length, 59 int* sourceId = 0, int* errLine = 0, UString* errMsg = 0); 60 61 int m_sourceId; 62 RefPtr<ProgramNode> m_progNode; 58 63 }; 64 65 Parser& parser(); // Returns the singleton JavaScript parser. 59 66 60 } // namespace 67 } // namespace KJS 61 68 62 #endif 69 #endif // Parser_h -
trunk/JavaScriptCore/kjs/function.cpp
r27746 r27842 78 78 79 79 Debugger* dbg = exec->dynamicInterpreter()->debugger(); 80 int s id = -1;81 int line no = -1;80 int sourceId = -1; 81 int lineNo = -1; 82 82 if (dbg) { 83 s id = body->sourceId();84 line no = body->firstLine();85 86 bool cont = dbg->callEvent(&newExec, sid,lineno,this,args);83 sourceId = body->sourceId(); 84 lineNo = body->firstLine(); 85 86 bool cont = dbg->callEvent(&newExec, sourceId, lineNo, this, args); 87 87 if (!cont) { 88 88 dbg->imp()->abort(); … … 103 103 104 104 if (dbg) { 105 line no = body->lastLine();105 lineNo = body->lastLine(); 106 106 107 107 if (comp.complType() == Throw) 108 108 newExec.setException(comp.value()); 109 109 110 int cont = dbg->returnEvent(&newExec, sid,lineno,this);110 int cont = dbg->returnEvent(&newExec, sourceId, lineNo, this); 111 111 if (!cont) { 112 112 dbg->imp()->abort(); … … 762 762 UString s = x->toString(exec); 763 763 764 int s id;764 int sourceId; 765 765 int errLine; 766 766 UString errMsg; 767 RefPtr<ProgramNode> progNode( Parser::parse(UString(), 0, s.data(),s.size(),&sid,&errLine,&errMsg));767 RefPtr<ProgramNode> progNode(parser().parseProgram(UString(), 0, s.data(), s.size(), &sourceId, &errLine, &errMsg)); 768 768 769 769 Debugger* dbg = exec->dynamicInterpreter()->debugger(); 770 770 if (dbg) { 771 bool cont = dbg->sourceParsed(exec, s id, UString(), s, 0, errLine, errMsg);771 bool cont = dbg->sourceParsed(exec, sourceId, UString(), s, 0, errLine, errMsg); 772 772 if (!cont) 773 773 return jsUndefined(); … … 776 776 // no program node means a syntax occurred 777 777 if (!progNode) 778 return throwError(exec, SyntaxError, errMsg, errLine, s id, NULL);778 return throwError(exec, SyntaxError, errMsg, errLine, sourceId, NULL); 779 779 780 780 bool switchGlobal = thisObj && thisObj != exec->dynamicInterpreter()->globalObject(); -
trunk/JavaScriptCore/kjs/function_object.cpp
r27448 r27842 186 186 187 187 // parse the source code 188 int s id;188 int sourceId; 189 189 int errLine; 190 190 UString errMsg; 191 RefPtr< ProgramNode> progNode = Parser::parse(sourceURL, lineNumber, body.data(),body.size(),&sid,&errLine,&errMsg);191 RefPtr<FunctionBodyNode> functionBody = parser().parseFunctionBody(sourceURL, lineNumber, body.data(), body.size(), &sourceId, &errLine, &errMsg); 192 192 193 193 // notify debugger that source has been parsed … … 195 195 if (dbg) { 196 196 // send empty sourceURL to indicate constructed code 197 bool cont = dbg->sourceParsed(exec, s id, UString(), body, lineNumber, errLine, errMsg);197 bool cont = dbg->sourceParsed(exec, sourceId, UString(), body, lineNumber, errLine, errMsg); 198 198 if (!cont) { 199 199 dbg->imp()->abort(); … … 203 203 204 204 // no program node == syntax error - throw a syntax error 205 if (! progNode)205 if (!functionBody) 206 206 // we can't return a Completion(Throw) here, so just set the exception 207 207 // and return it 208 return throwError(exec, SyntaxError, errMsg, errLine, s id, sourceURL);208 return throwError(exec, SyntaxError, errMsg, errLine, sourceId, sourceURL); 209 209 210 210 ScopeChain scopeChain; 211 211 scopeChain.push(exec->lexicalInterpreter()->globalObject()); 212 FunctionBodyNode *bodyNode = progNode.get(); 213 214 FunctionImp* fimp = new FunctionImp(exec, functionName, bodyNode, scopeChain); 212 213 FunctionImp* fimp = new FunctionImp(exec, functionName, functionBody.get(), scopeChain); 215 214 216 215 // parse parameter list. throw syntax error on illegal identifiers … … 232 231 c++, i++; 233 232 if (i == len) { 234 bodyNode->addParam(Identifier(param));233 functionBody->addParam(Identifier(param)); 235 234 params++; 236 235 break; 237 236 } else if (*c == ',') { 238 bodyNode->addParam(Identifier(param));237 functionBody->addParam(Identifier(param)); 239 238 params++; 240 239 c++, i++; -
trunk/JavaScriptCore/kjs/grammar.y
r27831 r27842 43 43 44 44 /* default values for bison */ 45 #define YYDEBUG 0 45 #define YYDEBUG 0 // Set to 1 to debug a parse error. 46 #define kjsyydebug 0 // Set to 1 to debug a parse error. 46 47 #if !PLATFORM(DARWIN) 47 48 // avoid triggering warnings in older bison … … 221 222 | STRING { $$ = new StringNode($1); } 222 223 | '/' /* regexp */ { 223 Lexer *l = Lexer::curr(); 224 if (!l->scanRegExp()) YYABORT; 225 $$ = new RegExpNode(l->pattern, l->flags); 224 Lexer& l = lexer(); 225 if (!l.scanRegExp()) 226 YYABORT; 227 $$ = new RegExpNode(l.pattern(), l.flags()); 226 228 } 227 229 | DIVEQUAL /* regexp with /= */ { 228 Lexer *l = Lexer::curr(); 229 if (!l->scanRegExp()) YYABORT; 230 $$ = new RegExpNode("=" + l->pattern, l->flags); 230 Lexer& l = lexer(); 231 if (!l.scanRegExp()) 232 YYABORT; 233 $$ = new RegExpNode("=" + l.pattern(), l.flags()); 231 234 } 232 235 ; … … 877 880 878 881 Program: 879 /* not in spec */ { Parser::accept(new ProgramNode(new SourceElements)); }880 | SourceElements { Parser::accept(new ProgramNode($1->release())); }882 /* not in spec */ { parser().didFinishParsing(new ProgramNode(new SourceElements)); } 883 | SourceElements { parser().didFinishParsing(new ProgramNode($1->release())); } 881 884 ; 882 885 … … 1091 1094 static bool allowAutomaticSemicolon() 1092 1095 { 1093 return yychar == '}' || yychar == 0 || Lexer::curr()->prevTerminator();1094 } 1096 return yychar == '}' || yychar == 0 || lexer().prevTerminator(); 1097 } -
trunk/JavaScriptCore/kjs/interpreter.cpp
r27763 r27842 309 309 int errLine; 310 310 UString errMsg; 311 RefPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code, codeLength, 0, &errLine, &errMsg);311 RefPtr<ProgramNode> progNode = parser().parseProgram(sourceURL, startingLineNumber, code, codeLength, 0, &errLine, &errMsg); 312 312 if (!progNode) 313 313 return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, 0, sourceURL)); … … 329 329 330 330 // parse the source code 331 int s id;331 int sourceId; 332 332 int errLine; 333 333 UString errMsg; 334 RefPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code, codeLength, &sid, &errLine, &errMsg);334 RefPtr<ProgramNode> progNode = parser().parseProgram(sourceURL, startingLineNumber, code, codeLength, &sourceId, &errLine, &errMsg); 335 335 336 336 // notify debugger that source has been parsed 337 337 if (m_debugger) { 338 bool cont = m_debugger->sourceParsed(&m_globalExec, s id, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg);338 bool cont = m_debugger->sourceParsed(&m_globalExec, sourceId, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg); 339 339 if (!cont) 340 340 return Completion(Break); … … 343 343 // no program node means a syntax error occurred 344 344 if (!progNode) 345 return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, s id, sourceURL));345 return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sourceId, sourceURL)); 346 346 347 347 m_globalExec.clearException(); … … 605 605 } 606 606 607 #ifdef KJS_DEBUG_MEM608 #include "lexer.h"609 void Interpreter::finalCheck()610 {611 fprintf(stderr,"Interpreter::finalCheck()\n");612 Collector::collect();613 614 Node::finalCheck();615 Collector::finalCheck();616 Lexer::globalClear();617 UString::globalClear();618 }619 #endif620 621 607 static bool printExceptions = false; 622 608 -
trunk/JavaScriptCore/kjs/interpreter.h
r27776 r27842 292 292 virtual void mark(); 293 293 294 #ifdef KJS_DEBUG_MEM295 /**296 * @internal297 */298 static void finalCheck();299 #endif300 301 294 static bool shouldPrintExceptions(); 302 295 static void setShouldPrintExceptions(bool); -
trunk/JavaScriptCore/kjs/lexer.cpp
r27695 r27842 52 52 int kjsyylex() 53 53 { 54 return Lexer::curr()->lex();54 return lexer().lex(); 55 55 } 56 56 57 57 namespace KJS { 58 58 59 static Lexer* currLexer = 0;60 61 59 static bool isDecimalDigit(int); 60 61 Lexer& lexer() 62 { 63 ASSERT(JSLock::currentThreadIsHoldingLock()); 64 65 // FIXME: We'd like to avoid calling new here, but we don't currently 66 // support tearing down the Lexer at app quit time, since that would involve 67 // tearing down its UString data members without holding the JSLock. 68 static Lexer* staticLexer = new Lexer; 69 return *staticLexer; 70 } 62 71 63 72 Lexer::Lexer() … … 76 85 buffer8 = new char[size8]; 77 86 buffer16 = new KJS::UChar[size16]; 78 currLexer = this;79 87 } 80 88 81 89 Lexer::~Lexer() 82 90 { 83 doneParsing();84 91 delete [] buffer8; 85 92 delete [] buffer16; 86 93 } 87 88 Lexer *Lexer::curr()89 {90 if (!currLexer) {91 // create singleton instance92 currLexer = new Lexer();93 }94 return currLexer;95 }96 97 #ifdef KJS_DEBUG_MEM98 void Lexer::globalClear()99 {100 delete currLexer;101 currLexer = 0L;102 }103 #endif104 94 105 95 void Lexer::setCode(const UString &sourceURL, int startingLineNumber, const KJS::UChar *c, unsigned int len) … … 786 776 KJS::UChar Lexer::convertUnicode(int c1, int c2, int c3, int c4) 787 777 { 778 // FIXME: This conversion is lossy. See http://bugs.webkit.org/show_bug.cgi?id=4920. 788 779 return KJS::UChar((convertHex(c1) << 4) + convertHex(c2), 789 780 (convertHex(c3) << 4) + convertHex(c4)); … … 851 842 } 852 843 else { // end of regexp 853 pattern = UString(buffer16, pos16);844 m_pattern = UString(buffer16, pos16); 854 845 pos16 = 0; 855 846 shift(1); … … 863 854 shift(1); 864 855 } 865 flags = UString(buffer16, pos16);856 m_flags = UString(buffer16, pos16); 866 857 867 858 return true; 868 859 } 869 860 870 871 void Lexer::doneParsing() 872 { 873 for (unsigned i = 0; i < numIdentifiers; i++) { 861 void Lexer::clear() 862 { 863 for (unsigned i = 0; i < numIdentifiers; i++) 874 864 delete identifiers[i]; 875 }876 865 fastFree(identifiers); 877 866 identifiers = 0; … … 879 868 identifiersCapacity = 0; 880 869 881 for (unsigned i = 0; i < numStrings; i++) {870 for (unsigned i = 0; i < numStrings; i++) 882 871 delete strings[i]; 883 }884 872 fastFree(strings); 885 873 strings = 0; 886 874 numStrings = 0; 887 875 stringsCapacity = 0; 876 877 m_pattern = 0; 878 m_flags = 0; 879 m_sourceURL = 0; 888 880 } 889 881 … … 891 883 const int growthFactor = 2; 892 884 893 // FIXME: this completely ignores its parameters, instead using buffer16 and pos16 - wtf? 894 Identifier *Lexer::makeIdentifier(KJS::UChar*, unsigned int) 885 Identifier* Lexer::makeIdentifier(KJS::UChar* buffer, unsigned int pos) 895 886 { 896 887 if (numIdentifiers == identifiersCapacity) { … … 899 890 } 900 891 901 KJS::Identifier *identifier = new KJS::Identifier(buffer 16, pos16);892 KJS::Identifier *identifier = new KJS::Identifier(buffer, pos); 902 893 identifiers[numIdentifiers++] = identifier; 903 894 return identifier; 904 895 } 905 896 906 // FIXME: this completely ignores its parameters, instead using buffer16 and pos16 - wtf? 907 UString *Lexer::makeUString(KJS::UChar*, unsigned int) 897 UString* Lexer::makeUString(KJS::UChar* buffer, unsigned int pos) 908 898 { 909 899 if (numStrings == stringsCapacity) { … … 912 902 } 913 903 914 UString *string = new UString(buffer 16, pos16);904 UString *string = new UString(buffer, pos); 915 905 strings[numStrings++] = string; 916 906 return string; 917 907 } 918 908 919 } 909 } // namespace KJS -
trunk/JavaScriptCore/kjs/lexer.h
r17862 r27842 3 3 * This file is part of the KDE libraries 4 4 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 5 * Copyright (C) 2007 Apple Inc. 5 6 * 6 7 * This library is free software; you can redistribute it and/or … … 21 22 */ 22 23 23 #ifndef _KJSLEXER_H_24 #define _KJSLEXER_H_24 #ifndef Lexer_h 25 #define Lexer_h 25 26 26 27 #include "ustring.h" 27 28 28 29 29 namespace KJS { 30 30 31 31 class Identifier; 32 33 32 class RegExp; 34 33 35 class Lexer {34 class Lexer : Noncopyable { 36 35 public: 37 Lexer();38 ~Lexer();39 static Lexer *curr();40 41 36 void setCode(const UString &sourceURL, int startingLineNumber, const UChar *c, unsigned int len); 42 37 int lex(); … … 76 71 77 72 bool scanRegExp(); 78 UString pattern, flags; 73 const UString& pattern() const { return m_pattern; } 74 const UString& flags() const { return m_flags; } 75 76 static unsigned char convertHex(int); 77 static unsigned char convertHex(int c1, int c2); 78 static UChar convertUnicode(int c1, int c2, int c3, int c4); 79 static bool isIdentStart(int); 80 static bool isIdentPart(int); 81 static bool isHexDigit(int); 82 83 bool sawError() const { return error; } 84 85 void clear(); 79 86 80 87 private: 88 friend Lexer& lexer(); 89 Lexer(); 90 ~Lexer(); 91 81 92 int yylineno; 82 93 UString m_sourceURL; 83 94 bool done; 84 char *buffer8; 85 UChar *buffer16; 95 char *buffer8; // FIXME: This buffer is never deallocated. 96 UChar *buffer16; // FIXME: This buffer is never deallocated. 86 97 unsigned int size8, size16; 87 98 unsigned int pos8, pos16; … … 110 121 static unsigned short singleEscape(unsigned short); 111 122 static unsigned short convertOctal(int c1, int c2, int c3); 112 public:113 static unsigned char convertHex(int);114 static unsigned char convertHex(int c1, int c2);115 static UChar convertUnicode(int c1, int c2, int c3, int c4);116 static bool isIdentStart(int);117 static bool isIdentPart(int);118 static bool isHexDigit(int);119 120 #ifdef KJS_DEBUG_MEM121 /**122 * Clear statically allocated resources123 */124 static void globalClear();125 #endif126 127 bool sawError() const { return error; }128 void doneParsing();129 130 private:131 123 132 124 void record8(int); … … 155 147 unsigned int numIdentifiers; 156 148 unsigned int identifiersCapacity; 149 150 UString m_pattern; 151 UString m_flags; 152 }; 153 154 Lexer& lexer(); // Returns the singletone JavaScript lexer. 157 155 158 // for future extensions 159 class LexerPrivate; 160 LexerPrivate *priv; 161 }; 156 } // namespace KJS 162 157 163 } // namespace 164 165 #endif 158 #endif // Lexer_h -
trunk/JavaScriptCore/kjs/nodes.cpp
r27799 r27842 133 133 ++NodeCounter::count; 134 134 #endif 135 m_line = Lexer::curr()->lineNo();135 m_line = lexer().lineNo(); 136 136 if (!newNodes) 137 137 newNodes = new HashSet<Node*>; … … 146 146 ++NodeCounter::count; 147 147 #endif 148 m_line = Lexer::curr()->lineNo();148 m_line = lexer().lineNo(); 149 149 if (!newNodes) 150 150 newNodes = new HashSet<Node*>; … … 4413 4413 FunctionBodyNode::FunctionBodyNode(SourceElements* children) 4414 4414 : BlockNode(children) 4415 , m_sourceURL( Lexer::curr()->sourceURL())4416 , m_sourceId( Parser::sid)4415 , m_sourceURL(lexer().sourceURL()) 4416 , m_sourceId(parser().sourceId()) 4417 4417 , m_initializedDeclarationStacks(false) 4418 4418 , m_initializedSymbolTable(false) -
trunk/JavaScriptCore/kjs/nodes.h
r27831 r27842 50 50 51 51 class FuncDeclNode; 52 class Node; 52 53 class PropertyListNode; 53 54 class SourceStream; -
trunk/JavaScriptCore/kjs/testkjs.cpp
r27031 r27842 24 24 #include "config.h" 25 25 26 #include "JSGlobalObject.h" 26 27 #include "JSLock.h" 27 28 #include "Parser.h" 28 29 #include "collector.h" 29 #include " JSGlobalObject.h"30 #include "nodes.h" 30 31 #include "object.h" 31 32 #include "protect.h" … … 246 247 int errLine = 0; 247 248 UString errMsg; 248 UString s = Parser::prettyPrint(script.data(), &errLine, &errMsg); 249 if (s.isNull()) { 249 UString scriptUString(script.data()); 250 RefPtr<ProgramNode> programNode = parser().parseProgram(fileName, 0, scriptUString.data(), scriptUString.size(), 0, &errLine, &errMsg); 251 if (!programNode) { 250 252 fprintf(stderr, "%s:%d: %s.\n", fileName.UTF8String().c_str(), errLine, errMsg.UTF8String().c_str()); 251 253 return false; 252 254 } 253 255 254 printf("%s\n", s.UTF8String().c_str());256 printf("%s\n", programNode->toString().UTF8String().c_str()); 255 257 return true; 256 258 } … … 314 316 #endif 315 317 316 #ifdef KJS_DEBUG_MEM317 Interpreter::finalCheck();318 #endif319 318 return success ? 0 : 3; 320 319 } -
trunk/JavaScriptCore/kjs/ustring.cpp
r27810 r27842 177 177 UString::Rep UString::Rep::empty = { 0, 0, 1, 0, 0, &UString::Rep::empty, reinterpret_cast<UChar*>(&almostUChar), 0, 0, 0, 0 }; 178 178 const int normalStatBufferSize = 4096; 179 static char *statBuffer = 0; 179 static char *statBuffer = 0; // FIXME: This buffer is never deallocated. 180 180 static int statBufferSize = 0; 181 181 … … 887 887 } 888 888 889 #ifdef KJS_DEBUG_MEM890 void UString::globalClear()891 {892 delete [] statBuffer;893 statBuffer = 0;894 statBufferSize = 0;895 }896 #endif897 898 889 UString &UString::operator=(const char *c) 899 890 { -
trunk/JavaScriptCore/kjs/ustring.h
r27746 r27842 383 383 */ 384 384 static const UString &null(); 385 #ifdef KJS_DEBUG_MEM386 /**387 * Clear statically allocated resources.388 */389 static void globalClear();390 #endif391 385 392 386 Rep* rep() const { return m_rep.get(); }
Note:
See TracChangeset
for help on using the changeset viewer.