From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/JavaScriptCore/parser/SourceCode.h | 93 +++++++++++-------------------- 1 file changed, 31 insertions(+), 62 deletions(-) (limited to 'Source/JavaScriptCore/parser/SourceCode.h') diff --git a/Source/JavaScriptCore/parser/SourceCode.h b/Source/JavaScriptCore/parser/SourceCode.h index cf1a4a3d9..90f547a20 100644 --- a/Source/JavaScriptCore/parser/SourceCode.h +++ b/Source/JavaScriptCore/parser/SourceCode.h @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -26,106 +26,75 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SourceCode_h -#define SourceCode_h +#pragma once -#include "SourceProvider.h" -#include +#include "UnlinkedSourceCode.h" namespace JSC { - class SourceCode { + class SourceCode : public UnlinkedSourceCode { public: SourceCode() - : m_provider(0) - , m_startChar(0) - , m_endChar(0) - , m_firstLine(0) - , m_startColumn(0) + : UnlinkedSourceCode() + , m_firstLine(OrdinalNumber::beforeFirst()) + , m_startColumn(OrdinalNumber::beforeFirst()) { } - SourceCode(WTF::HashTableDeletedValueType) - : m_provider(WTF::HashTableDeletedValue) + SourceCode(Ref&& provider) + : UnlinkedSourceCode(WTFMove(provider)) { } - SourceCode(PassRefPtr provider) - : m_provider(provider) - , m_startChar(0) - , m_endChar(m_provider->source().length()) - , m_firstLine(1) - , m_startColumn(1) + SourceCode(Ref&& provider, int firstLine, int startColumn) + : UnlinkedSourceCode(WTFMove(provider)) + , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1))) + , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1))) { } - SourceCode(PassRefPtr provider, int firstLine, int startColumn) - : m_provider(provider) - , m_startChar(0) - , m_endChar(m_provider->source().length()) - , m_firstLine(std::max(firstLine, 1)) - , m_startColumn(std::max(startColumn, 1)) + SourceCode(Ref&& provider, int startOffset, int endOffset, int firstLine, int startColumn) + : UnlinkedSourceCode(WTFMove(provider), startOffset, endOffset) + , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1))) + , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1))) { } - SourceCode(PassRefPtr provider, int start, int end, int firstLine, int startColumn) - : m_provider(provider) - , m_startChar(start) - , m_endChar(end) - , m_firstLine(std::max(firstLine, 1)) - , m_startColumn(std::max(startColumn, 1)) + SourceCode(RefPtr&& provider, int startOffset, int endOffset, int firstLine, int startColumn) + : UnlinkedSourceCode(WTFMove(provider), startOffset, endOffset) + , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1))) + , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1))) { } - bool isHashTableDeletedValue() const { return m_provider.isHashTableDeletedValue(); } + OrdinalNumber firstLine() const { return m_firstLine; } + OrdinalNumber startColumn() const { return m_startColumn; } - String toString() const - { - if (!m_provider) - return String(); - return m_provider->getRange(m_startChar, m_endChar); - } - - CString toUTF8() const; - intptr_t providerID() const { if (!m_provider) return SourceProvider::nullID; return m_provider->asID(); } - - bool isNull() const { return !m_provider; } + SourceProvider* provider() const { return m_provider.get(); } - int firstLine() const { return m_firstLine; } - int startColumn() const { return m_startColumn; } - int startOffset() const { return m_startChar; } - int endOffset() const { return m_endChar; } - int length() const { return m_endChar - m_startChar; } - + SourceCode subExpression(unsigned openBrace, unsigned closeBrace, int firstLine, int startColumn); private: - RefPtr m_provider; - int m_startChar; - int m_endChar; - int m_firstLine; - int m_startColumn; + OrdinalNumber m_firstLine; + OrdinalNumber m_startColumn; }; - inline SourceCode makeSource(const String& source, const String& url = String(), const TextPosition& startPosition = TextPosition::minimumPosition()) + inline SourceCode makeSource(const String& source, const SourceOrigin& sourceOrigin, const String& url = String(), const TextPosition& startPosition = TextPosition(), SourceProviderSourceType sourceType = SourceProviderSourceType::Program) { - return SourceCode(StringSourceProvider::create(source, url, startPosition), startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt()); + return SourceCode(StringSourceProvider::create(source, sourceOrigin, url, startPosition, sourceType), startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt()); } - + inline SourceCode SourceCode::subExpression(unsigned openBrace, unsigned closeBrace, int firstLine, int startColumn) { - ASSERT(provider()->source()[openBrace] == '{'); - ASSERT(provider()->source()[closeBrace] == '}'); startColumn += 1; // Convert to base 1. - return SourceCode(provider(), openBrace, closeBrace + 1, firstLine, startColumn); + return SourceCode(RefPtr { provider() }, openBrace, closeBrace + 1, firstLine, startColumn); } } // namespace JSC - -#endif // SourceCode_h -- cgit v1.2.1