X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..40a37d088818fc2fbeba2ef850dbcaaf294befbf:/parser/SourceProvider.h diff --git a/parser/SourceProvider.h b/parser/SourceProvider.h index 07da9e0..91c1c68 100644 --- a/parser/SourceProvider.h +++ b/parser/SourceProvider.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008, 2009, 2012, 2013 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -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. * @@ -29,49 +29,73 @@ #ifndef SourceProvider_h #define SourceProvider_h -#include "UString.h" +#include #include +#include +#include namespace JSC { class SourceProvider : public RefCounted { public: - SourceProvider(const UString& url) - : m_url(url) + static const intptr_t nullID = 1; + + JS_EXPORT_PRIVATE SourceProvider(const String& url, const TextPosition& startPosition); + + JS_EXPORT_PRIVATE virtual ~SourceProvider(); + + virtual const String& source() const = 0; + String getRange(int start, int end) const { + return source().substringSharingImpl(start, end - start); } - virtual ~SourceProvider() { } - virtual UString getRange(int start, int end) const = 0; - virtual const UChar* data() const = 0; - virtual int length() const = 0; - - const UString& url() { return m_url; } - intptr_t asID() { return reinterpret_cast(this); } + const String& url() { return m_url; } + TextPosition startPosition() const { return m_startPosition; } + intptr_t asID() + { + ASSERT(this); + if (!this) // Be defensive in release mode. + return nullID; + if (!m_id) + getID(); + return m_id; + } + + bool isValid() const { return m_validated; } + void setValid() { m_validated = true; } private: - UString m_url; + + JS_EXPORT_PRIVATE void getID(); + Vector& lineStarts(); + + String m_url; + TextPosition m_startPosition; + bool m_validated : 1; + uintptr_t m_id : sizeof(uintptr_t) * 8 - 1; }; - class UStringSourceProvider : public SourceProvider { + class StringSourceProvider : public SourceProvider { public: - static PassRefPtr create(const UString& source, const UString& url) + static PassRefPtr create(const String& source, const String& url, const TextPosition& startPosition = TextPosition::minimumPosition()) { - return adoptRef(new UStringSourceProvider(source, url)); + return adoptRef(new StringSourceProvider(source, url, startPosition)); } - UString getRange(int start, int end) const { return m_source.substr(start, end - start); } - const UChar* data() const { return m_source.data(); } - int length() const { return m_source.size(); } + virtual const String& source() const override + { + return m_source; + } private: - UStringSourceProvider(const UString& source, const UString& url) - : SourceProvider(url) + StringSourceProvider(const String& source, const String& url, const TextPosition& startPosition) + : SourceProvider(url, startPosition) , m_source(source) { } - UString m_source; + String m_source; }; } // namespace JSC