summaryrefslogtreecommitdiffstats
path: root/languages/java/driver.h
blob: 95b4957fbb62d32e0226369b76e54b892b5dd9f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* This file is part of TDevelop
    Copyright (C) 2002,2003 Roberto Raggi <roberto@tdevelop.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef DRIVER_H
#define DRIVER_H

#include "JavaAST.hpp"

#include <tqpair.h>
#include <tqvaluestack.h>
#include <tqstringlist.h>
#include <tqmap.h>

class JavaLexer;
class JavaRecognizer;

class Problem
{
public:
    enum
    {
	Level_Error = 0,
	Level_Warning,
	Level_Todo,
	Level_Fixme
    };

public:
    Problem() {}
    Problem( const Problem& source )
	: m_text( source.m_text ), m_line( source.m_line ),
	  m_column( source.m_column ), m_level( source.m_level ) {}
    Problem( const TQString& text, int line, int column, int level=Level_Error )
	: m_text( text ), m_line( line ), m_column( column ), m_level(level) {}

    Problem& operator = ( const Problem& source )
    {
	m_text = source.m_text;
	m_line = source.m_line;
	m_column = source.m_column;
	m_level = source.m_level;
	return( *this );
    }

    bool operator == ( const Problem& p ) const
    {
	return m_text == p.m_text && m_line == p.m_line && m_column == p.m_column && m_level == p.m_level;
    }

    TQString text() const { return m_text; }
    int line() const { return m_line; }
    int column() const { return m_column; }
    int level() const { return m_level; }

private:
    TQString m_text;
    int m_line;
    int m_column;
    int m_level;
};

class SourceProvider
{
public:
    SourceProvider() {}
    virtual ~SourceProvider() {}

    virtual TQString contents( const TQString& fileName ) = 0;
    virtual bool isModified( const TQString& fileName ) = 0;

private:
    SourceProvider( const SourceProvider& source );
    void operator = ( const SourceProvider& source );
};

class Driver
{
public:
    Driver();
    virtual ~Driver();

    SourceProvider* sourceProvider();
    void setSourceProvider( SourceProvider* sourceProvider );

    virtual void reset();

    virtual void parseFile( const TQString& fileName, bool onlyPreProcesss=false, bool force=false );
    virtual void fileParsed( const TQString& fileName );
    virtual void remove( const TQString& fileName );

    virtual void addProblem( const TQString& fileName, const Problem& problem );

    TQString currentFileName() const { return m_currentFileName; }
    RefJavaAST takeTranslationUnit( const TQString& fileName );
    RefJavaAST translationUnit( const TQString& fileName ) const;
    TQValueList<Problem> problems( const TQString& fileName ) const;

    TQStringList includePaths() const { return m_includePaths; }
    virtual void addIncludePath( const TQString &path );

    const TQMap<TQString, RefJavaAST> &parsedUnits() const { return m_parsedUnits; }

protected:
    virtual void setupLexer( JavaLexer* lexer );
    virtual void setupParser( JavaRecognizer* parser );

private:
    TQValueList<Problem>& findOrInsertProblemList( const TQString& fileName );

private:
    TQString m_currentFileName;
    TQMap< TQString, TQValueList<Problem> > m_problems;
    TQMap< TQString, RefJavaAST > m_parsedUnits;
    TQStringList m_includePaths;
    JavaLexer *lexer;
    SourceProvider* m_sourceProvider;

private:
    Driver( const Driver& source );
    void operator = ( const Driver& source );
};

#endif