Commit 865e3676 authored by weinig@apple.com's avatar weinig@apple.com

2008-07-07 Sam Weinig <sam@webkit.org>

        Reviewed by Cameron Zwarich.

        Third step in broad cleanup effort.

        [ File list elided ]



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35037 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0789a8fe
2008-07-07 Sam Weinig <sam@webkit.org>
Reviewed by Cameron Zwarich.
Third step in broad cleanup effort.
[ File list elided ]
2008-07-06 Sam Weinig <sam@webkit.org>
Reviewed by Cameron Zwarich.
......@@ -208,7 +208,7 @@ CodeGenerator::CodeGenerator(ProgramNode* programNode, const Debugger* debugger,
RegisterFile* registerFile = &exec->globalData().machine->registerFile();
// Shift register indexes in generated code to elide registers allocated by intermediate stack frames.
m_globalVarStorageOffset = -1 - RegisterFile::CallFrameHeaderSize - registerFile->size();
m_globalVarStorageOffset = -1 - RegisterFile::CallFrameHeaderSize - registerFile->size();
// Add previously defined symbols to bookkeeping.
m_locals.resize(symbolTable->size());
......@@ -385,7 +385,6 @@ RegisterID* CodeGenerator::newTemporary()
return &m_temporaries.last();
}
RegisterID* CodeGenerator::highestUsedRegister()
{
while (m_temporaries.size() < static_cast<unsigned>(m_codeBlock->numTemporaries))
......@@ -448,9 +447,9 @@ PassRefPtr<LabelID> CodeGenerator::emitJumpIfTrue(RegisterID* cond, LabelID* tar
int dstIndex;
int src1Index;
int src2Index;
retrieveLastBinaryOp(dstIndex, src1Index, src2Index);
if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) {
rewindBinaryOp();
emitOpcode(target->isForwardLabel() ? op_jless : op_loop_if_less);
......@@ -460,7 +459,7 @@ PassRefPtr<LabelID> CodeGenerator::emitJumpIfTrue(RegisterID* cond, LabelID* tar
return target;
}
}
emitOpcode(target->isForwardLabel() ? op_jtrue : op_loop_if_true);
instructions().append(cond->index());
instructions().append(target->offsetFrom(instructions().size()));
......@@ -470,14 +469,14 @@ PassRefPtr<LabelID> CodeGenerator::emitJumpIfTrue(RegisterID* cond, LabelID* tar
PassRefPtr<LabelID> CodeGenerator::emitJumpIfFalse(RegisterID* cond, LabelID* target)
{
ASSERT(target->isForwardLabel());
if (m_lastOpcodeID == op_less) {
int dstIndex;
int src1Index;
int src2Index;
retrieveLastBinaryOp(dstIndex, src1Index, src2Index);
if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) {
rewindBinaryOp();
emitOpcode(op_jnless);
......@@ -487,7 +486,7 @@ PassRefPtr<LabelID> CodeGenerator::emitJumpIfFalse(RegisterID* cond, LabelID* ta
return target;
}
}
emitOpcode(op_jfalse);
instructions().append(cond->index());
instructions().append(target->offsetFrom(instructions().size()));
......
......@@ -327,7 +327,6 @@ namespace KJS {
// Returns true if a new RegisterID was added, false if a pre-existing RegisterID was re-used.
bool addVar(const Identifier&, bool isConstant, RegisterID*&);
// Returns the RegisterID corresponding to ident.
RegisterID* addGlobalVar(const Identifier& ident, bool isConstant)
{
......
......@@ -93,6 +93,7 @@ namespace KJS {
grow(size);
ASSERT(size == m_size);
}
private:
void shrink(size_t size)
{
......@@ -161,6 +162,7 @@ namespace KJS {
Segment m_inlineSegment;
Vector<Segment*, 32> m_segments;
};
}
} // namespace KJS
#endif // SegmentedVector_h
......@@ -42,10 +42,10 @@ namespace KJS {
class DebuggerCallFrame {
public:
typedef enum {
enum Type {
ProgramType,
FunctionType
} Type;
};
DebuggerCallFrame(JSGlobalObject* dynamicGlobalObject, const CodeBlock* codeBlock, ScopeChainNode* scopeChain, Register* r, JSValue* exception)
: m_dynamicGlobalObject(dynamicGlobalObject)
......
// -*- c-basic-offset: 4 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2003, 2006, 2007 Apple Inc.
* Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -24,8 +22,8 @@
#include "config.h"
#include "Parser.h"
#include "debugger.h"
#include "debugger.h"
#include "lexer.h"
#include <wtf/HashSet.h>
#include <wtf/Vector.h>
......@@ -39,16 +37,15 @@ Parser::Parser()
{
}
void Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNumber,
PassRefPtr<SourceProvider> prpSource,
void Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> prpSource,
int* sourceId, int* errLine, UString* errMsg)
{
ASSERT(!m_sourceElements);
int defaultSourceId;
int defaultErrLine;
UString defaultErrMsg;
RefPtr<SourceProvider> source = prpSource;
if (!sourceId)
......@@ -60,7 +57,7 @@ void Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNu
*errLine = -1;
*errMsg = 0;
Lexer& lexer = *exec->lexer();
if (startingLineNumber <= 0)
......@@ -80,7 +77,7 @@ void Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNu
*errMsg = "Parse error";
m_sourceElements.clear();
}
if (Debugger* debugger = exec->dynamicGlobalObject()->debugger())
debugger->sourceParsed(exec, *sourceId, sourceURL, *source, startingLineNumber, *errLine, *errMsg);
}
......
// -*- c-basic-offset: 4 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2003, 2006, 2007 Apple Inc.
* Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -25,8 +23,8 @@
#ifndef Parser_h
#define Parser_h
#include "nodes.h"
#include "SourceProvider.h"
#include "nodes.h"
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/OwnPtr.h>
......@@ -38,7 +36,8 @@ namespace KJS {
class ProgramNode;
class UString;
template <typename T> struct ParserRefCountedData : ParserRefCounted {
template <typename T>
struct ParserRefCountedData : ParserRefCounted {
ParserRefCountedData(JSGlobalData* globalData)
: ParserRefCounted(globalData)
{
......@@ -50,8 +49,7 @@ namespace KJS {
class Parser : Noncopyable {
public:
template <class ParsedNode>
PassRefPtr<ParsedNode> parse(ExecState*, const UString& sourceURL, int startingLineNumber,
PassRefPtr<SourceProvider> source,
PassRefPtr<ParsedNode> parse(ExecState*, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source,
int* sourceId = 0, int* errLine = 0, UString* errMsg = 0);
UString sourceURL() const { return m_sourceURL; }
......@@ -78,8 +76,7 @@ namespace KJS {
};
template <class ParsedNode>
PassRefPtr<ParsedNode> Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNumber,
PassRefPtr<SourceProvider> source,
PassRefPtr<ParsedNode> Parser::parse(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source,
int* sourceId, int* errLine, UString* errMsg)
{
m_sourceURL = sourceURL;
......
// -*- c-basic-offset: 2 -*-
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
......
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -23,155 +22,43 @@
#ifndef Debugger_h
#define Debugger_h
#include <wtf/HashSet.h>
#include "protect.h"
#include <wtf/HashSet.h>
namespace KJS {
class DebuggerCallFrame;
class ExecState;
class JSGlobalObject;
class JSObject;
class JSValue;
class ArgList;
class SourceProvider;
class UString;
/**
* @internal
*
* Provides an interface which receives notification about various
* script-execution related events such as statement execution and function
* calls.
*/
class Debugger {
public:
/**
* Creates a new debugger
*/
Debugger();
/**
* Destroys the debugger. If the debugger is attached to any global objects,
* it is automatically detached.
*/
virtual ~Debugger();
/**
* Attaches the debugger to specified global object. This will cause this
* object to receive notification of events during execution.
*
* If the global object is deleted, it will detach the debugger.
*
* Note: only one debugger can be attached to a global object at a time.
* Attaching another debugger to the same global object will cause the
* original debugger to be detached.
*
* @param The global object to attach to.
*/
void attach(JSGlobalObject*);
/**
* Detach the debugger from a global object.
*
* @param The global object to detach from.
*/
void detach(JSGlobalObject*);
/**
* Called to notify the debugger that some javascript source code has
* been parsed. For calls to Interpreter::evaluate(), this will be called
* with the supplied source code before any other code is parsed.
* Other situations in which this may be called include creation of a
* function using the Function() constructor, or the eval() function.
*
* The default implementation does nothing. Override this method if
* you want to process this event.
*
* @param exec The current execution state
* @param sourceId The ID of the source code (corresponds to the
* sourceId supplied in other functions such as atStatement()
* @param sourceURL Where the source code that was parsed came from
* @param source The source code that was parsed
* @param startingLineNumber The line number at which parsing started
* @param errorLine The line number at which parsing encountered an
* error, or -1 if the source code was valid and parsed successfully
* @param errorMsg The error description, or null if the source code
was valid and parsed successfully
*/
virtual void sourceParsed(ExecState*, int sourceId, const UString& sourceURL,
const SourceProvider& source, int startingLineNumber, int errorLine, const UString& errorMsg) = 0;
/**
* Called when an exception is thrown during script execution.
*
* The default implementation does nothing. Override this method if
* you want to process this event.
*
* @param exec The current execution state
* @param sourceId The ID of the source code being executed
* @param lineno The line at which the error occurred
* @param exceptionObj The exception object
*/
virtual void exception(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
/**
* Called when a line of the script is reached (before it is executed)
*
* The default implementation does nothing. Override this method if
* you want to process this event.
*
* @param exec The current execution state
* @param sourceId The ID of the source code being executed
* @param firstLine The starting line of the statement that is about to be
* executed
* @param lastLine The ending line of the statement that is about to be
* executed (usually the same as firstLine)
*/
virtual void atStatement(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
/**
* Called on each function call. Use together with @ref #returnEvent
* if you want to keep track of the call stack.
*
* Note: This only gets called for functions that are declared in ECMAScript
* source code or passed to eval(), not for internal KJS or
* application-supplied functions.
*
* The default implementation does nothing. Override this method if
* you want to process this event.
*
* @param exec The current execution state
* @param sourceId The ID of the source code being executed
* @param lineno The line that is about to be executed
*/
virtual void callEvent(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
/**
* Called on each function exit. The function being returned from is that
* which was supplied in the last callEvent().
*
* Note: This only gets called for functions that are declared in ECMAScript
* source code or passed to eval(), not for internal KJS or
* application-supplied functions.
*
* The default implementation does nothing. Override this method if
* you want to process this event.
*
* @param exec The current execution state
* @param sourceId The ID of the source code being executed
* @param lineno The line that is about to be executed
*/
virtual void returnEvent(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
virtual void willExecuteProgram(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
virtual void didExecuteProgram(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
virtual void didReachBreakpoint(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
private:
HashSet<JSGlobalObject*> m_globalObjects;
};
class ArgList;
class DebuggerCallFrame;
class ExecState;
class JSGlobalObject;
class JSObject;
class JSValue;
class SourceProvider;
class UString;
class Debugger {
public:
Debugger();
virtual ~Debugger();
void attach(JSGlobalObject*);
void detach(JSGlobalObject*);
virtual void sourceParsed(ExecState*, int sourceId, const UString& sourceURL,
const SourceProvider& source, int startingLineNumber, int errorLine, const UString& errorMsg) = 0;
virtual void exception(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
virtual void atStatement(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
virtual void callEvent(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
virtual void returnEvent(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
virtual void willExecuteProgram(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
virtual void didExecuteProgram(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
virtual void didReachBreakpoint(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
private:
HashSet<JSGlobalObject*> m_globalObjects;
};
} // namespace KJS
#endif
#endif // Debugger_h
This diff is collapsed.
......@@ -31,125 +31,131 @@
namespace KJS {
class Identifier;
class RegExp;
class Lexer : Noncopyable {
public:
void setCode(int startingLineNumber, PassRefPtr<SourceProvider> source);
int lex(void* lvalp, void* llocp);
int lineNo() const { return yylineno; }
bool prevTerminator() const { return terminator; }
enum State { Start,
IdentifierOrKeyword,
Identifier,
InIdentifierOrKeyword,
InIdentifier,
InIdentifierStartUnicodeEscapeStart,
InIdentifierStartUnicodeEscape,
InIdentifierPartUnicodeEscapeStart,
InIdentifierPartUnicodeEscape,
InSingleLineComment,
InMultiLineComment,
InNum,
InNum0,
InHex,
InOctal,
InDecimal,
InExponentIndicator,
InExponent,
Hex,
Octal,
Number,
String,
Eof,
InString,
InEscapeSequence,
InHexEscape,
InUnicodeEscape,
Other,
Bad };
bool scanRegExp();
const UString& pattern() const { return m_pattern; }
const UString& flags() const { return m_flags; }
static unsigned char convertHex(int);
static unsigned char convertHex(int c1, int c2);
static UChar convertUnicode(int c1, int c2, int c3, int c4);
static bool isIdentStart(int);
static bool isIdentPart(int);
static bool isHexDigit(int);
bool sawError() const { return error; }
void clear();
SourceRange sourceRange(int openBrace, int closeBrace) { return SourceRange(m_source, openBrace + 1, closeBrace); }
private:
friend struct JSGlobalData;
Lexer(JSGlobalData*);
~Lexer();
int yylineno;
bool done;
Vector<char> m_buffer8;
Vector<UChar> m_buffer16;
bool terminator;
bool restrKeyword;
// encountered delimiter like "'" and "}" on last run
bool delimited;
bool skipLF;
bool skipCR;
bool eatNextIdentifier;
int stackToken;
int lastToken;
State state;
void setDone(State);
unsigned int pos;
void shift(unsigned int p);
void nextLine();
int lookupKeyword(const char *);
bool isWhiteSpace() const;
bool isLineTerminator();
static bool isOctalDigit(int);
int matchPunctuator(int& charPos, int c1, int c2, int c3, int c4);
static unsigned short singleEscape(unsigned short);
static unsigned short convertOctal(int c1, int c2, int c3);
void record8(int);
void record16(int);
void record16(UChar);
KJS::Identifier* makeIdentifier(const Vector<UChar>& buffer);
UString* makeUString(const Vector<UChar>& buffer);
RefPtr<SourceProvider> m_source;
const UChar* code;
unsigned int length;
int yycolumn;
int atLineStart;
bool error;
// current and following unicode characters (int to allow for -1 for end-of-file marker)
int current, next1, next2, next3;
Vector<UString*> m_strings;
Vector<KJS::Identifier*> m_identifiers;
JSGlobalData* m_globalData;
UString m_pattern;
UString m_flags;
const HashTable mainTable;
};
class Identifier;
class RegExp;
class Lexer : Noncopyable {
public:
void setCode(int startingLineNumber, PassRefPtr<SourceProvider> source);
int lex(void* lvalp, void* llocp);
int lineNo() const { return yylineno; }
bool prevTerminator() const { return m_terminator; }
enum State {
Start,
IdentifierOrKeyword,
Identifier,
InIdentifierOrKeyword,
InIdentifier,
InIdentifierStartUnicodeEscapeStart,
InIdentifierStartUnicodeEscape,
InIdentifierPartUnicodeEscapeStart,
InIdentifierPartUnicodeEscape,
InSingleLineComment,
InMultiLineComment,
InNum,
InNum0,
InHex,
InOctal,
InDecimal,
InExponentIndicator,
InExponent,
Hex,
Octal,
Number,
String,
Eof,
InString,
InEscapeSequence,
InHexEscape,
InUnicodeEscape,
Other,
Bad
};
bool scanRegExp();
const UString& pattern() const { return m_pattern; }
const UString& flags() const { return m_flags; }
static unsigned char convertHex(int);
static unsigned char convertHex(int c1, int c2);
static UChar convertUnicode(int c1, int c2, int c3, int c4);
static bool isIdentStart(int);
static bool isIdentPart(int);
static bool isHexDigit(int);
bool sawError() const { return m_error; }
void clear();
SourceRange sourceRange(int openBrace, int closeBrace) { return SourceRange(m_source, openBrace + 1, closeBrace); }
private:
friend struct JSGlobalData;
Lexer(JSGlobalData*);
~Lexer();
void setDone(State);
void shift(unsigned int p);
void nextLine();
int lookupKeyword(const char *);
bool isWhiteSpace() const;
bool isLineTerminator();
static bool isOctalDigit(int);
int matchPunctuator(int& charPos, int c1, int c2, int c3, int c4);
static unsigned short singleEscape(unsigned short);
static unsigned short convertOctal(int c1, int c2, int c3);
void record8(int);
void record16(int);
void record16(UChar);
KJS::Identifier* makeIdentifier(const Vector<UChar>& buffer);
UString* makeUString(const Vector<UChar>& buffer);
int yylineno;
int yycolumn;
bool m_done;
Vector<char> m_buffer8;
Vector<UChar> m_buffer16;
bool m_terminator;
bool m_restrKeyword;
bool m_delimited; // encountered delimiter like "'" and "}" on last run
bool m_skipLF;
bool m_skipCR;
bool m_eatNextIdentifier;
int m_stackToken;
int m_lastToken;
State m_state;
unsigned int m_position;
RefPtr<SourceProvider> m_source;
const UChar* m_code;
unsigned int m_length;
int m_atLineStart;
bool m_error;
// current and following unicode characters (int to allow for -1 for end-of-file marker)
int m_current;
int m_next1;
int m_next2;
int m_next3;
Vector<UString*> m_strings;
Vector<KJS::Identifier*> m_identifiers;
JSGlobalData* m_globalData;
UString m_pattern;
UString m_flags;
const HashTable m_mainTable;
};
} // namespace KJS
......
......@@ -54,7 +54,7 @@ namespace KJS {
inline bool operator!=(const CallIdentifier& ci) const { return !(*this == ci); }
#ifndef NDEBUG
operator const char* () const { return c_str(); }
operator const char*() const { return c_str(); }
const char* c_str() const { return m_name.UTF8String().c_str(); }