KDevelop API Documentation

fixedformparser.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Bernd Gehrmann                                  *
00003  *   bernd@kdevelop.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include "fixedformparser.h"
00013 
00014 #include <qfile.h>
00015 #include <qtextstream.h>
00016 #include <kdebug.h>
00017 #include <codemodel.h>
00018 
00019 
00020 FixedFormParser::FixedFormParser(CodeModel* model)
00021 {
00022     m_model = model;
00023 
00024     functionre.setPattern("(integer|real|logical|complex|character|"
00025                        "double(precision)?)function([^(]+).*");
00026     subroutinere.setPattern("subroutine([^(]+).*");
00027 
00028     functionre.setCaseSensitive( false );
00029     subroutinere.setCaseSensitive( false );
00030 }
00031 
00032 
00033 void FixedFormParser::process(const QCString &line, const QString &fileName, int lineNum)
00034 {
00035     QCString simplified;
00036     int l = line.length();
00037     for (int i=0; i < l; ++i)
00038         if (line[i] != ' ')
00039             simplified += line[i];
00040 
00041     if ( simplified.isEmpty() ) return;
00042 
00043     QString name;
00044     if (functionre.search(simplified) != -1)
00045         name = functionre.cap(3);
00046     else if (subroutinere.search(simplified) != -1) 
00047         name = subroutinere.cap(1);
00048     else
00049         return;
00050 
00051     FunctionDom method = m_model->create<FunctionModel>();
00052     method->setName(name);
00053     method->setFileName(fileName);
00054     method->setStartPosition(lineNum, 0);
00055 
00056     if( !m_file->hasFunction(method->name()) )
00057         m_file->addFunction(method);
00058 }
00059 
00060 
00061 void FixedFormParser::parse(const QString &fileName)
00062 {
00063     QFile f(QFile::encodeName(fileName));
00064     if (!f.open(IO_ReadOnly))
00065         return;
00066     QTextStream stream(&f);
00067 
00068     m_file = m_model->create<FileModel>();
00069     m_file->setName( fileName );
00070 
00071     QCString line;
00072     int lineNum=0, startLineNum=0;
00073     while (!stream.atEnd()) {
00074         ++lineNum;
00075         QCString str = stream.readLine().local8Bit();
00076         if (!str.isEmpty() && QCString("*Cc#!").find(str[0]) != -1)
00077             continue;
00078         // Continuation line
00079         if (str.length() > 6 && str.left(5) == "     " && str[5] != ' ') {
00080             line += str.right(str.length()-6);
00081             continue;
00082         }
00083         // An initial or invalid line. We don't care
00084         // about validity
00085         process(line, fileName, startLineNum);
00086         line = str.right(str.length()-6);
00087         startLineNum = lineNum-1;
00088     }
00089     process(line, fileName, startLineNum);
00090 
00091     f.close();
00092 
00093     m_model->addFile( m_file );
00094 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:30 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003