X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/1df5f87f1309a8daa30dabdee855f48ae40d14ab..6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174:/parser/SourceCode.h diff --git a/parser/SourceCode.h b/parser/SourceCode.h index 9ba4da3..11a0033 100644 --- a/parser/SourceCode.h +++ b/parser/SourceCode.h @@ -67,13 +67,21 @@ namespace JSC { return m_provider->getRange(m_startChar, m_endChar); } + 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 startOffset() const { return m_startChar; } int endOffset() const { return m_endChar; } - const UChar* data() const { return m_provider->data() + m_startChar; } int length() const { return m_endChar - m_startChar; } + + SourceCode subExpression(unsigned openBrace, unsigned closeBrace, int firstLine); private: RefPtr m_provider; @@ -82,9 +90,16 @@ namespace JSC { int m_firstLine; }; - inline SourceCode makeSource(const UString& source, const UString& url = UString(), int firstLine = 1) + inline SourceCode makeSource(const UString& source, const UString& url = UString(), const TextPosition& startPosition = TextPosition::minimumPosition()) + { + return SourceCode(UStringSourceProvider::create(source, url, startPosition), startPosition.m_line.oneBasedInt()); + } + + inline SourceCode SourceCode::subExpression(unsigned openBrace, unsigned closeBrace, int firstLine) { - return SourceCode(UStringSourceProvider::create(source, url), firstLine); + ASSERT((*provider()->data())[openBrace] == '{'); + ASSERT((*provider()->data())[closeBrace] == '}'); + return SourceCode(provider(), openBrace, closeBrace + 1, firstLine); } } // namespace JSC