summaryrefslogtreecommitdiffstats
path: root/languages/ada/ada_utils.cpp
blob: d7b8bbf7d8bbf482afa2a21b6cb05296a066443d (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
/*
 */
#include <stdlib.h>
#include <unistd.h>
#include <iostream>

#include <tqstring.h>
#include <tqstringlist.h>
#include <tqfile.h>
#include <tqregexp.h>

#include <kdebug.h>

#include "ada_utils.hpp"
#include "adasupport.hpp"

TQString qtext (const RefAdaAST& n)
{
  return TQString::fromLatin1 (text (n).c_str ());
}

TQStringList qnamelist (const RefAdaAST& n)
{
  TQString txt = qtext (n);
  // kdDebug() << "qnamelist: input is " << txt << endl;
  return TQStringList::split ('.', txt);
}

TQString ada_spec_filename (const TQString& comp_unit_name)
{
   TQString fn (comp_unit_name.lower ());

   fn.replace (TQRegExp("."), "-");
   fn += ".ads";
   return fn;
}

TQString fq_specfilename (const TQString& comp_unit_name)
{
    TQString fname = ada_spec_filename (comp_unit_name);

    if (TQFile::exists (fname))
        return fname;

    TQString adaincpath = getenv ("ADA_INCLUDE_PATH");
    if (adaincpath.isNull ())
        return TQString();

    TQStringList dirs = TQStringList::split (':', adaincpath);
    TQString fq_filename;
    for (TQStringList::Iterator it = dirs.begin (); it != dirs.end (); it++) {
        fq_filename = *it;
        if (! fq_filename.endsWith ("/"))
            fq_filename += "/";
        fq_filename += fname;
        if (TQFile::exists (fq_filename))
            return fq_filename;
    }
    if (fname.startsWith ("ada-") ||
        fname.startsWith ("text_io") ||
        fname.startsWith ("system") ||
        fname.startsWith ("unchecked_")) {
        kdDebug () << "resolution of Ada predefined library is TBD" << endl;
    } else {
        kdDebug () << "Cannot find file " << fname << endl;
    }
    return TQString();
}