Changeset 27842 in webkit for trunk/JavaScriptCore/kjs/lexer.cpp


Ignore:
Timestamp:
Nov 15, 2007, 10:54:09 PM (18 years ago)
Author:
[email protected]
Message:

Reviewed by Eric Seidel.

Another round of grammar / parsing cleanup.


  1. Created distinct parser calls for parsing function bodies vs programs. This will help later with optimizing global variable access.


  1. Turned Parser into a singleton. Cleaned up Lexer's singleton interface.


  1. Modified Lexer to free a little more memory when done lexing. (Added FIXMEs for similar issues that I didn't fix.)


  1. Changed Lexer::makeIdentifier and Lexer::makeUString to start respecting the arguments passed to them. (No behavior change, but this problem could have caused serious problems for an unsuspecting user of these functions.)


  1. Removed KJS_DEBUG_MEM because it was bit-rotted.


  1. Removed Parser::prettyPrint because the same work was simpler to do at the call site.


  1. Some renames:


"Parser::accept" => "Parser::didFinishParsing"
"Parser::sid" => "Parser::m_sourceID"
"Lexer::doneParsing" => "Lexer::clear"
"sid" => "sourceId"
"lineno" => "lineNo"


  • JavaScriptCore.exp:
  • kjs/Parser.cpp: (KJS::Parser::Parser): (KJS::Parser::parseProgram): (KJS::Parser::parseFunctionBody): (KJS::Parser::parse): (KJS::Parser::didFinishParsing): (KJS::parser):
  • kjs/Parser.h: (KJS::Parser::sourceId):
  • kjs/function.cpp: (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/grammar.y:
  • kjs/interpreter.cpp: (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate):
  • kjs/interpreter.h:
  • kjs/lexer.cpp: (kjsyylex): (KJS::lexer): (KJS::Lexer::Lexer): (KJS::Lexer::~Lexer): (KJS::Lexer::scanRegExp): (KJS::Lexer::doneParsing): (KJS::Lexer::makeIdentifier): (KJS::Lexer::makeUString):
  • kjs/lexer.h: (KJS::Lexer::pattern): (KJS::Lexer::flags): (KJS::Lexer::sawError):
  • kjs/nodes.cpp: (KJS::Node::Node): (KJS::FunctionBodyNode::FunctionBodyNode):
  • kjs/nodes.h:
  • kjs/testkjs.cpp: (prettyPrintScript): (kjsmain):
  • kjs/ustring.cpp:
  • kjs/ustring.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/lexer.cpp

    r27695 r27842  
    5252int kjsyylex()
    5353{
    54   return Lexer::curr()->lex();
     54  return lexer().lex();
    5555}
    5656
    5757namespace KJS {
    5858
    59 static Lexer* currLexer = 0;
    60 
    6159static bool isDecimalDigit(int);
     60
     61Lexer& 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}
    6271
    6372Lexer::Lexer()
     
    7685  buffer8 = new char[size8];
    7786  buffer16 = new KJS::UChar[size16];
    78   currLexer = this;
    7987}
    8088
    8189Lexer::~Lexer()
    8290{
    83   doneParsing();
    8491  delete [] buffer8;
    8592  delete [] buffer16;
    8693}
    87 
    88 Lexer *Lexer::curr()
    89 {
    90   if (!currLexer) {
    91     // create singleton instance
    92     currLexer = new Lexer();
    93   }
    94   return currLexer;
    95 }
    96 
    97 #ifdef KJS_DEBUG_MEM
    98 void Lexer::globalClear()
    99 {
    100   delete currLexer;
    101   currLexer = 0L;
    102 }
    103 #endif
    10494
    10595void Lexer::setCode(const UString &sourceURL, int startingLineNumber, const KJS::UChar *c, unsigned int len)
     
    786776KJS::UChar Lexer::convertUnicode(int c1, int c2, int c3, int c4)
    787777{
     778  // FIXME: This conversion is lossy. See http://bugs.webkit.org/show_bug.cgi?id=4920.
    788779  return KJS::UChar((convertHex(c1) << 4) + convertHex(c2),
    789780               (convertHex(c3) << 4) + convertHex(c4));
     
    851842    }
    852843    else { // end of regexp
    853       pattern = UString(buffer16, pos16);
     844      m_pattern = UString(buffer16, pos16);
    854845      pos16 = 0;
    855846      shift(1);
     
    863854    shift(1);
    864855  }
    865   flags = UString(buffer16, pos16);
     856  m_flags = UString(buffer16, pos16);
    866857
    867858  return true;
    868859}
    869860
    870 
    871 void Lexer::doneParsing()
    872 {
    873   for (unsigned i = 0; i < numIdentifiers; i++) {
     861void Lexer::clear()
     862{
     863  for (unsigned i = 0; i < numIdentifiers; i++)
    874864    delete identifiers[i];
    875   }
    876865  fastFree(identifiers);
    877866  identifiers = 0;
     
    879868  identifiersCapacity = 0;
    880869
    881   for (unsigned i = 0; i < numStrings; i++) {
     870  for (unsigned i = 0; i < numStrings; i++)
    882871    delete strings[i];
    883   }
    884872  fastFree(strings);
    885873  strings = 0;
    886874  numStrings = 0;
    887875  stringsCapacity = 0;
     876 
     877  m_pattern = 0;
     878  m_flags = 0;
     879  m_sourceURL = 0;
    888880}
    889881
     
    891883const int growthFactor = 2;
    892884
    893 // FIXME: this completely ignores its parameters, instead using buffer16 and pos16 - wtf?
    894 Identifier *Lexer::makeIdentifier(KJS::UChar*, unsigned int)
     885Identifier* Lexer::makeIdentifier(KJS::UChar* buffer, unsigned int pos)
    895886{
    896887  if (numIdentifiers == identifiersCapacity) {
     
    899890  }
    900891
    901   KJS::Identifier *identifier = new KJS::Identifier(buffer16, pos16);
     892  KJS::Identifier *identifier = new KJS::Identifier(buffer, pos);
    902893  identifiers[numIdentifiers++] = identifier;
    903894  return identifier;
    904895}
    905896 
    906 // FIXME: this completely ignores its parameters, instead using buffer16 and pos16 - wtf?
    907 UString *Lexer::makeUString(KJS::UChar*, unsigned int)
     897UString* Lexer::makeUString(KJS::UChar* buffer, unsigned int pos)
    908898{
    909899  if (numStrings == stringsCapacity) {
     
    912902  }
    913903
    914   UString *string = new UString(buffer16, pos16);
     904  UString *string = new UString(buffer, pos);
    915905  strings[numStrings++] = string;
    916906  return string;
    917907}
    918908
    919 }
     909} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.