File indexing completed on 2024-04-14 14:47:48

0001 /*
0002     SPDX-FileCopyrightText: 2007 Piyush verma <piyush.verma@gmail.com>
0003     SPDX-FileCopyrightText: 2008 Niko Sams <niko.sams@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef PHP_PARSESESSION_H
0009 #define PHP_PARSESESSION_H
0010 
0011 #include <QString>
0012 #include "phpparser.h"
0013 #include "parserexport.h"
0014 
0015 namespace KDevPG
0016 {
0017 class MemoryPool;
0018 }
0019 namespace Php
0020 {
0021 class TokenStream;
0022 struct StartAst;
0023 
0024 typedef QPair<KDevelop::DUContextPointer, KDevelop::RangeInRevision> SimpleUse;
0025 
0026 class KDEVPHPPARSER_EXPORT ParseSession
0027 {
0028 public:
0029     ParseSession();
0030     ~ParseSession();
0031 
0032     void setContents(const QString& contents);
0033     void setCurrentDocument(const KDevelop::IndexedString& filename);
0034     KDevelop::IndexedString currentDocument() const;
0035     bool readFile(const QString& filename, const char* charset = nullptr);
0036     void setDebug(bool);
0037     TokenStream* tokenStream() const;
0038     QString contents() const;
0039 
0040     bool parse(Php::StartAst**);
0041     Parser* createParser(int initialState = Parser::HtmlState);
0042 
0043     QString symbol(qint64 token) const;
0044     QString symbol(AstNode* node) const;
0045 
0046     /**
0047      * Return the DocBlock before this token, if any
0048      */
0049     QString docComment(qint64 token) const;
0050 
0051     /**
0052      * Return the position (\a line%, \a column%) of the \a offset in the file.
0053      *
0054      * \note the line starts from 0.
0055      */
0056     KDevelop::CursorInRevision positionAt(qint64 offset) const;
0057 
0058     QList<KDevelop::ProblemPointer> problems();
0059 
0060     /// @TODO implement this
0061     void mapAstUse(AstNode* node, const SimpleUse& use)
0062     {
0063         Q_UNUSED(node);
0064         Q_UNUSED(use);
0065     }
0066 
0067 private:
0068     QString m_contents;
0069     bool m_debug;
0070     KDevelop::IndexedString m_currentDocument;
0071     KDevPG::MemoryPool* m_pool;
0072     TokenStream* m_tokenStream;
0073     QList<KDevelop::ProblemPointer> m_problems;
0074 };
0075 
0076 }
0077 
0078 #endif
0079 
0080 // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on; auto-insert-doxygen on