~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/fortran/fixedformparser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2001 by Bernd Gehrmann                                  *
 
3
 *   bernd@kdevelop.org                                                    *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 ***************************************************************************/
 
11
 
 
12
#include "fixedformparser.h"
 
13
 
 
14
#include <qfile.h>
 
15
#include <qtextstream.h>
 
16
#include <kdebug.h>
 
17
#include <codemodel.h>
 
18
 
 
19
 
 
20
FixedFormParser::FixedFormParser(CodeModel* model)
 
21
{
 
22
    m_model = model;
 
23
 
 
24
    functionre.setPattern("(integer|real|logical|complex|character|"
 
25
                       "double(precision)?)function([^(]+).*");
 
26
    subroutinere.setPattern("subroutine([^(]+).*");
 
27
 
 
28
    functionre.setCaseSensitive( false );
 
29
    subroutinere.setCaseSensitive( false );
 
30
}
 
31
 
 
32
 
 
33
void FixedFormParser::process(const QCString &line, const QString &fileName, int lineNum)
 
34
{
 
35
    QCString simplified;
 
36
    int l = line.length();
 
37
    for (int i=0; i < l; ++i)
 
38
        if (line[i] != ' ')
 
39
            simplified += line[i];
 
40
 
 
41
    if ( simplified.isEmpty() ) return;
 
42
 
 
43
    QString name;
 
44
    if (functionre.search(simplified) != -1)
 
45
        name = functionre.cap(3);
 
46
    else if (subroutinere.search(simplified) != -1) 
 
47
        name = subroutinere.cap(1);
 
48
    else
 
49
        return;
 
50
 
 
51
    FunctionDom method = m_model->create<FunctionModel>();
 
52
    method->setName(name);
 
53
    method->setFileName(fileName);
 
54
    method->setStartPosition(lineNum, 0);
 
55
 
 
56
    if( !m_file->hasFunction(method->name()) )
 
57
        m_file->addFunction(method);
 
58
}
 
59
 
 
60
 
 
61
void FixedFormParser::parse(const QString &fileName)
 
62
{
 
63
    QFile f(QFile::encodeName(fileName));
 
64
    if (!f.open(IO_ReadOnly))
 
65
        return;
 
66
    QTextStream stream(&f);
 
67
 
 
68
    m_file = m_model->create<FileModel>();
 
69
    m_file->setName( fileName );
 
70
 
 
71
    QCString line;
 
72
    int lineNum=0, startLineNum=0;
 
73
    while (!stream.atEnd()) {
 
74
        ++lineNum;
 
75
        QCString str = stream.readLine().local8Bit();
 
76
        if (!str.isEmpty() && QCString("*Cc#!").find(str[0]) != -1)
 
77
            continue;
 
78
        // Continuation line
 
79
        if (str.length() > 6 && str.left(5) == "     " && str[5] != ' ') {
 
80
            line += str.right(str.length()-6);
 
81
            continue;
 
82
        }
 
83
        // An initial or invalid line. We don't care
 
84
        // about validity
 
85
        process(line, fileName, startLineNum);
 
86
        line = str.right(str.length()-6);
 
87
        startLineNum = lineNum-1;
 
88
    }
 
89
    process(line, fileName, startLineNum);
 
90
 
 
91
    f.close();
 
92
 
 
93
    m_model->addFile( m_file );
 
94
}