| 90 | static bool readCMakeFunction( cmListFileLexer* lexer, CMakeFunctionDesc& func); |
| 91 | |
| 92 | CMakeFileContent readCMakeFile(const QString & _fileName) |
| 93 | { |
| 94 | cmListFileLexer* lexer = cmListFileLexer_New(); |
| 95 | if ( !lexer ) |
| 96 | return CMakeFileContent(); |
| 97 | if ( !cmListFileLexer_SetFileName( lexer, qPrintable( _fileName ), nullptr ) ) { |
| 98 | qCDebug(CMAKE) << "cmake read error. could not read " << _fileName; |
| 99 | cmListFileLexer_Delete(lexer); |
| 100 | return CMakeFileContent(); |
| 101 | } |
| 102 | |
| 103 | CMakeFileContent ret; |
| 104 | QString fileName = QDir::cleanPath(_fileName); |
| 105 | |
| 106 | bool readError = false, haveNewline = true; |
| 107 | cmListFileLexer_Token* token; |
| 108 | |
| 109 | while(!readError && (token = cmListFileLexer_Scan(lexer))) |
| 110 | { |
| 111 | readError=false; |
| 112 | if(token->type == cmListFileLexer_Token_Newline) |
| 113 | { |
| 114 | readError=false; |
| 115 | haveNewline = true; |
| 116 | } |
| 117 | else if(token->type == cmListFileLexer_Token_Identifier) |
| 118 | { |
| 119 | if(haveNewline) |
| 120 | { |
| 121 | haveNewline = false; |
| 122 | CMakeFunctionDesc function; |
| 123 | function.name = QString::fromLocal8Bit(token->text, token->length).toLower(); |
| 124 | function.filePath = fileName; |
| 125 | function.line = token->line; |
| 126 | function.column = token->column; |
| 127 | |
| 128 | readError = !readCMakeFunction( lexer, function); |
| 129 | ret.append(function); |
| 130 | |
| 131 | if(readError) |
| 132 | { |
| 133 | qCDebug(CMAKE) << "Error while parsing:" << function.name << "at" << function.line; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | cmListFileLexer_Delete(lexer); |
| 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | } |
| 144 | |