summaryrefslogtreecommitdiffstats
path: root/languages/fortran/compiler/pgioptions/pgioptionsplugin.cpp
blob: 113b5abd53dcdf7f3fc2d507f02333a32a222a29 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/***************************************************************************
 *   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 <tqapplication.h>
#include <tqheader.h>
#include <tqlayout.h>
#include <tqlistview.h>
#include <tqradiobutton.h>
#include <tqvbox.h>
#include <tqvbuttongroup.h>
#include <kdebug.h>
#include <klocale.h>

#include "pgioptionsplugin.h"


const char * const optimization_flags[] = {
    "-Mautopar",
    "-Mextract",
    "-Minline",
    "-Mipa",
    0
};


const char * const hpf_flags[] = {
    "-Mbackslash",
    "-Mcmf",
    "-Mdclchk",
    "-Mextend",
    "-Mf90",
    "-Mnofree",
    "-Mstandard",
    "-Mupcase",
    "-Mbyteswapio",
    "-Mdepchk",
    "-Mdlines",
    "-Mg",
    "-Mftn",
    "-Minfo",
    "-Minform",
    "-Mkeepft",
    "-Mkeepstaticn",
    "-Mmpi",
    "-Mmpl",
    "-Mlist",
    "-Mnohpfc",
    "-Mnoindependent",
    "-Mnoprelink",
    "-Moverlap",
    "-Mpreprocess",
    "-Mprof",
    "-Mpvm",
    "-Mr8",
    "-Mrecursive",
    "-Mreplicate",
    "-Mrpm",
    "-Mrpm1",
    "-M[no]sequence",
    "-Msmp",
    "-Mstats",
    0
};



class GeneralTab : public TQWidget
{
public:
    GeneralTab( TQWidget *tqparent=0, const char *name=0 );
    ~GeneralTab();

    void readFlags(TQStringList *str);
    void writeFlags(TQStringList *str);
};


class OptimizationTab : public TQWidget
{
public:
    OptimizationTab( PgiOptionsPlugin::Type type, TQWidget *tqparent=0, const char *name=0 );
    ~OptimizationTab();

    void readFlags(TQStringList *str);
    void writeFlags(TQStringList *str);

private:
    TQRadioButton *Odefault, *O0, *O1, *O2;
    TQListView *optBox;
};


class HpfTab : public TQWidget
{
public:
    HpfTab( TQWidget *tqparent=0, const char *name=0 );
    ~HpfTab();

    void readFlags(TQStringList *str);
    void writeFlags(TQStringList *str);

private:
    TQListView *hpfBox;
};


OptimizationTab::OptimizationTab(PgiOptionsPlugin::Type type, TQWidget *tqparent, const char *name)
    : TQWidget(tqparent, name)
{
    TQBoxLayout *tqlayout = new TQVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
    tqlayout->setAutoAdd(true);

    TQVButtonGroup *group = new TQVButtonGroup(i18n("Optimization Level"), this);
    Odefault = new TQRadioButton(i18n("Default"), group);
    Odefault->setChecked(true);
    O0 = new TQRadioButton(i18n("No optimization"), group);
    O1 = new TQRadioButton(i18n("Level 1"), group);
    O2 = new TQRadioButton(i18n("Level 2"), group);

    if (type == PgiOptionsPlugin::PGHPF) {
        optBox = new TQListView(this);
        optBox->addColumn(TQString());
        optBox->header()->hide();
        for (const char * const *p = optimization_flags; *p; ++p) {
            new TQCheckListItem(optBox, *p, TQCheckListItem::CheckBox);
            kdDebug() << (*p) << endl;
        }
    } else
        optBox = 0;

    TQApplication::sendPostedEvents(this, TQEvent::ChildInserted);
    tqlayout->addStretch();
}


OptimizationTab::~OptimizationTab()
{}


void OptimizationTab::readFlags(TQStringList *list)
{
    if (optBox) {
        TQListViewItem *item = optBox->firstChild();
        for (; item; item = item->nextSibling()) {
            TQStringList::Iterator sli = list->find(item->text(0));
            if (sli != list->end()) {
                static_cast<TQCheckListItem*>(item)->setOn(true);
                list->remove(sli);
            }
        }
    }
    
    TQStringList::Iterator sli;
    sli = list->find("-O0");
    if (sli != list->end()) {
        O0->setChecked(true);
        list->remove(sli);
    }
    sli = list->find("-O1");
    if (sli != list->end()) {
        O1->setChecked(true);
        list->remove(sli);
    }
    sli = list->find("-O2");
    if (sli != list->end()) {
        O2->setChecked(true);
        list->remove(sli);
    }
}


void OptimizationTab::writeFlags(TQStringList *list)
{
    if (optBox) {
        TQListViewItem *item = optBox->firstChild();
        for (; item; item = item->nextSibling())
            if (static_cast<TQCheckListItem*>(item)->isOn())
                (*list) << item->text(0);
    }
    
    if (O0->isChecked())
        (*list) << "-O0";
    else if (O1->isChecked())
        (*list) << "-O1";
    else if (O2->isChecked())
        (*list) << "-O2";
}


HpfTab::HpfTab(TQWidget *tqparent, const char *name)
    : TQWidget(tqparent, name)
{
    TQBoxLayout *tqlayout = new TQVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
    tqlayout->setAutoAdd(true);

    hpfBox = new TQListView(this);
    hpfBox->addColumn(TQString());
    hpfBox->header()->hide();
    for (const char * const *p = hpf_flags; *p; ++p)
        new TQCheckListItem(hpfBox, *p, TQCheckListItem::CheckBox);

    TQApplication::sendPostedEvents(this, TQEvent::ChildInserted);
    tqlayout->addStretch();
}


HpfTab::~HpfTab()
{}


void HpfTab::readFlags(TQStringList *list)
{
    TQListViewItem *item = hpfBox->firstChild();
    for (; item; item = item->nextSibling()) {
        TQStringList::Iterator sli = list->find(item->text(0));
        if (sli != list->end()) {
            static_cast<TQCheckListItem*>(item)->setOn(true);
            list->remove(sli);
        }
    }
}


void HpfTab::writeFlags(TQStringList *list)
{
    TQListViewItem *item = hpfBox->firstChild();
    for (; item; item = item->nextSibling()) {
        if (static_cast<TQCheckListItem*>(item)->isOn())
            (*list) << item->text(0);
    }
}


PgiOptionsDialog::PgiOptionsDialog(PgiOptionsPlugin::Type type, TQWidget *tqparent, const char *name)
    : KDialogBase(Tabbed, (type == PgiOptionsPlugin::PGHPF)? i18n("PGHPF Compiler Options") : i18n("PGF77 Compiler Options"),
                  Ok|Cancel, Ok, tqparent, name, true)
{
    TQVBox *vbox;

    //    vbox = addVBoxPage(i18n("General"));
    //    general = new GeneralTab(vbox, "general tab");

    vbox = addVBoxPage(i18n("Optimization"));
    optimization = new OptimizationTab(type, vbox, "optimization tab");

    if (type == PgiOptionsPlugin::PGHPF) {
        vbox = addVBoxPage(i18n("HPF"));
        hpf = new HpfTab(vbox, "optimization tab");
    } else
        hpf = 0;
        
}


PgiOptionsDialog::~PgiOptionsDialog()
{
}


void PgiOptionsDialog::setFlags(const TQString &flags)
{
    TQStringList flaglist = TQStringList::split(" ", flags);

    // Hand them to 'general' at last, so it can make a line edit
    // with the unprocessed items
    if (hpf)
        hpf->readFlags(&flaglist);
    optimization->readFlags(&flaglist);
    //    general->readFlags(&flaglist);
}


TQString PgiOptionsDialog::flags() const
{
    TQStringList flaglist;

    if (hpf)
        hpf->writeFlags(&flaglist);
    optimization->writeFlags(&flaglist);
    //    general->writeFlags(&flaglist);

    TQString flags;
    TQStringList::ConstIterator li;
    for (li = flaglist.begin(); li != flaglist.end(); ++li) {
        flags += (*li);
        flags += " ";
    }

    flags.truncate(flags.length()-1);
    return flags;
}


PgiOptionsPlugin::PgiOptionsPlugin(Type type, TQObject *tqparent, const char *name)
    : KDevCompilerOptions(tqparent, name)
{
    pgitype = type;
}


PgiOptionsPlugin::~PgiOptionsPlugin()
{}


TQString PgiOptionsPlugin::exec(TQWidget *tqparent, const TQString &flags)
{
    PgiOptionsDialog *dlg = new PgiOptionsDialog(pgitype, tqparent, "pgi options dialog");
    TQString newFlags = flags;
    dlg->setFlags(flags);
    if (dlg->exec() == TQDialog::Accepted)
        newFlags = dlg->flags();
    delete dlg;
    return newFlags;
}

#include "pgioptionsplugin.moc"