File indexing completed on 2024-05-12 04:39:26
0001 /* 0002 SPDX-FileCopyrightText: 2006 Matt Rogers <mattr@kde.org> 0003 SPDX-FileCopyrightText: 2007 Aleix Pol Gonzalez <aleixpol@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef CMAKELISTSPARSER_H 0009 #define CMAKELISTSPARSER_H 0010 0011 #include <QMetaType> 0012 #include <QString> 0013 #include <QVector> 0014 0015 #include "cmListFileLexer.h" 0016 #include <cmakecommonexport.h> 0017 #include <language/editor/rangeinrevision.h> 0018 0019 class QStringList; 0020 0021 struct CMakeFunctionArgument 0022 { 0023 CMakeFunctionArgument() {} 0024 explicit CMakeFunctionArgument(const QString& v); 0025 CMakeFunctionArgument(const QString& v, bool q, quint32 l = 0, quint32 c=0); 0026 inline bool operator == (const CMakeFunctionArgument& r) const 0027 { 0028 return (this->value == r.value) && (this->quoted == r.quoted); 0029 } 0030 0031 inline bool operator != (const CMakeFunctionArgument& r) const 0032 { 0033 return (this->value != r.value) || (this->quoted != r.quoted); 0034 } 0035 0036 bool operator==( const QString& rhs ) 0037 { 0038 return ( this->value == rhs ); 0039 } 0040 0041 bool isCorrect() const { return column>0; } 0042 0043 static QString unescapeValue(const QString& value); 0044 0045 KDevelop::RangeInRevision range() const 0046 { return KDevelop::RangeInRevision(line-1, column-1, line-1, column+value.length()-1); } 0047 0048 bool isValid() const { return quoted || !value.isEmpty(); } 0049 0050 QString value; 0051 bool quoted = false; 0052 quint32 line = 0; 0053 quint32 column = 0; 0054 static const QMap<QChar, QChar> scapings; 0055 }; 0056 Q_DECLARE_METATYPE( CMakeFunctionArgument ) 0057 0058 0059 class KDEVCMAKECOMMON_EXPORT CMakeFunctionDesc 0060 { 0061 public: 0062 CMakeFunctionDesc(); 0063 0064 ///useful when writing unit tests mostly 0065 CMakeFunctionDesc(const QString& name, const QStringList& args); 0066 0067 QString name; 0068 QVector<CMakeFunctionArgument> arguments; 0069 QString filePath; 0070 quint32 line = 0; 0071 quint32 column = 0; 0072 quint32 endLine = 0; 0073 quint32 endColumn = 0; 0074 0075 KDevelop::RangeInRevision nameRange() const 0076 { return KDevelop::RangeInRevision(line-1, column-1, line-1, column-1+name.length()); } 0077 0078 KDevelop::RangeInRevision range() const 0079 { return KDevelop::RangeInRevision(line-1, column-1, endLine-1, endColumn); } 0080 0081 KDevelop::RangeInRevision argRange() const 0082 { 0083 if( !arguments.isEmpty() ) 0084 { 0085 return KDevelop::RangeInRevision(arguments.first().range().start, 0086 arguments.last().range().end); 0087 } else 0088 { 0089 return KDevelop::RangeInRevision( line-1, column-1, endLine-1, endColumn); 0090 } 0091 } 0092 0093 bool operator==(const CMakeFunctionDesc &other) const; 0094 void addArguments( const QStringList&, bool addEvenIfEmpty=true ); 0095 QString writeBack() const; 0096 }; 0097 Q_DECLARE_METATYPE( CMakeFunctionDesc ) 0098 0099 /** 0100 * CMake files function descriptor collector 0101 * @author Matt Rogers <mattr@kde.org> 0102 * @author Aleix Pol <aleixpol@gmail.com> 0103 */ 0104 0105 using CMakeFileContent = QVector<CMakeFunctionDesc>; 0106 0107 namespace CMakeListsParser 0108 { 0109 KDEVCMAKECOMMON_EXPORT CMakeFileContent readCMakeFile(const QString& fileName); 0110 } 0111 0112 #endif