From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- languages/fortran/fixedformparser.cpp | 94 +++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 languages/fortran/fixedformparser.cpp (limited to 'languages/fortran/fixedformparser.cpp') diff --git a/languages/fortran/fixedformparser.cpp b/languages/fortran/fixedformparser.cpp new file mode 100644 index 00000000..7084fbba --- /dev/null +++ b/languages/fortran/fixedformparser.cpp @@ -0,0 +1,94 @@ +/*************************************************************************** + * Copyright (C) 2001 by Bernd Gehrmann * + * bernd@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "fixedformparser.h" + +#include +#include +#include +#include + + +FixedFormParser::FixedFormParser(CodeModel* model) +{ + m_model = model; + + functionre.setPattern("(integer|real|logical|complex|character|" + "double(precision)?)function([^(]+).*"); + subroutinere.setPattern("subroutine([^(]+).*"); + + functionre.setCaseSensitive( false ); + subroutinere.setCaseSensitive( false ); +} + + +void FixedFormParser::process(const QCString &line, const QString &fileName, int lineNum) +{ + QCString simplified; + int l = line.length(); + for (int i=0; i < l; ++i) + if (line[i] != ' ') + simplified += line[i]; + + if ( simplified.isEmpty() ) return; + + QString name; + if (functionre.search(simplified) != -1) + name = functionre.cap(3); + else if (subroutinere.search(simplified) != -1) + name = subroutinere.cap(1); + else + return; + + FunctionDom method = m_model->create(); + method->setName(name); + method->setFileName(fileName); + method->setStartPosition(lineNum, 0); + + if( !m_file->hasFunction(method->name()) ) + m_file->addFunction(method); +} + + +void FixedFormParser::parse(const QString &fileName) +{ + QFile f(QFile::encodeName(fileName)); + if (!f.open(IO_ReadOnly)) + return; + QTextStream stream(&f); + + m_file = m_model->create(); + m_file->setName( fileName ); + + QCString line; + int lineNum=0, startLineNum=0; + while (!stream.atEnd()) { + ++lineNum; + QCString str = stream.readLine().local8Bit(); + if (!str.isEmpty() && QCString("*Cc#!").find(str[0]) != -1) + continue; + // Continuation line + if (str.length() > 6 && str.left(5) == " " && str[5] != ' ') { + line += str.right(str.length()-6); + continue; + } + // An initial or invalid line. We don't care + // about validity + process(line, fileName, startLineNum); + line = str.right(str.length()-6); + startLineNum = lineNum-1; + } + process(line, fileName, startLineNum); + + f.close(); + + m_model->addFile( m_file ); +} -- cgit v1.2.1