X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/a253471d7f8e4d91bf6ebabab00155c3b387d3d0..93a3786624b2768d89bfa27e46598dc64e2fb70a:/parser/SourceProvider.h diff --git a/parser/SourceProvider.h b/parser/SourceProvider.h index 946792b..4ced9d9 100644 --- a/parser/SourceProvider.h +++ b/parser/SourceProvider.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009 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 @@ -29,12 +29,10 @@ #ifndef SourceProvider_h #define SourceProvider_h -#include "SourceProviderCache.h" -#include "UString.h" #include #include -#include #include +#include namespace JSC { @@ -42,73 +40,62 @@ namespace JSC { public: static const intptr_t nullID = 1; - SourceProvider(const UString& url, const TextPosition& startPosition, SourceProviderCache* cache = 0) - : m_url(url) - , m_startPosition(startPosition) - , m_validated(false) - , m_cache(cache ? cache : new SourceProviderCache) - , m_cacheOwned(!cache) - { - turnOffVerifier(); - } - virtual ~SourceProvider() + 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 { - if (m_cacheOwned) - delete m_cache; + return source().substringSharingImpl(start, end - start); } - virtual UString getRange(int start, int end) const = 0; - virtual const StringImpl* data() const = 0; - virtual int length() const = 0; - - const UString& url() { return m_url; } + 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; - return reinterpret_cast(this); + if (!m_id) + getID(); + return m_id; } bool isValid() const { return m_validated; } void setValid() { m_validated = true; } - SourceProviderCache* cache() const { return m_cache; } - void notifyCacheSizeChanged(int delta) { if (!m_cacheOwned) cacheSizeChanged(delta); } - private: - virtual void cacheSizeChanged(int delta) { UNUSED_PARAM(delta); } - UString m_url; + JS_EXPORT_PRIVATE void getID(); + Vector& lineStarts(); + + String m_url; TextPosition m_startPosition; - bool m_validated; - SourceProviderCache* m_cache; - bool m_cacheOwned; + 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, const TextPosition& startPosition = TextPosition::minimumPosition()) + static PassRefPtr create(const String& source, const String& url, const TextPosition& startPosition = TextPosition::minimumPosition()) { - return adoptRef(new UStringSourceProvider(source, url, startPosition)); + return adoptRef(new StringSourceProvider(source, url, startPosition)); } - virtual UString getRange(int start, int end) const OVERRIDE + virtual const String& source() const OVERRIDE { - return m_source.substringSharingImpl(start, end - start); + return m_source; } - const StringImpl* data() const { return m_source.impl(); } - int length() const { return m_source.length(); } private: - UStringSourceProvider(const UString& source, const UString& url, const TextPosition& startPosition) + StringSourceProvider(const String& source, const String& url, const TextPosition& startPosition) : SourceProvider(url, startPosition) , m_source(source) { } - UString m_source; + String m_source; }; } // namespace JSC