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
#include <f77crash/cursor.h>
#include <f77crash/crossrefs.h>


#include <iostream>

namespace CrossRefs {

std::string                         currentRoutine;

std::map<std::string, std::vector<std::string> >  call;

std::map<std::string, int>          external;
std::map<std::string, int>          intrinsic;
std::map<std::string, int>          variable;
std::map<std::string, Cursor>       declaration;

std::map<Cursor, std::string>       name;
std::map<Cursor, std::string>       defs;
std::map<std::string, Cursor>       args;

void
dump(const char *srcFile)
{
    typedef std::map<Cursor, std::string>  NameMap;
    typedef std::map<Cursor, std::string>  DefsMap;

    for (NameMap::const_iterator it = name.begin(); it != name.end(); ++it) {
        Cursor cursor = it->first;

        if (external.find(it->second) != external.end()) {
            std::cout << "EXTERNAL,"
                      << cursor.fromLine-1 << "." << cursor.fromCol+6 << ":"
                      << cursor.toLine-1 << "." << cursor.toCol+6 << ","
                      << it->second
                      << std::endl;
        } else if (intrinsic.find(it->second) != intrinsic.end()) {
            std::cout << "INTRINSIC,"
                      << cursor.fromLine-1 << "." << cursor.fromCol+6 << ":"
                      << cursor.toLine-1 << "." << cursor.toCol+6 << ","
                      << it->second
                      << std::endl;
        } else if (variable.find(it->second) != variable.end()) {
            if ((declaration.find(it->second) != declaration.end())
             && (cursor == declaration[it->second]))
            {
                if (args.find(it->second)!=args.end()) {
                    std::cout << "ARGDEF,";
                } else {
                    std::cout << "DEFINITION,";
                }
                std::cout << cursor.fromLine-1 << "." << cursor.fromCol+6 << ":"
                          << cursor.toLine-1 << "." << cursor.toCol+6 << ","
                          << variable[it->second] << ","
                          << it->second
                          << std::endl;
            } else {
                std::cout << "VARIABLE,"
                          << cursor.fromLine-1 << "." << cursor.fromCol+6 << ":"
                          << cursor.toLine-1 << "." << cursor.toCol+6 << ","
                          << variable[it->second] << ","
                          << it->second
                          << std::endl;
            }
         }

    }

    for (DefsMap::const_iterator it = defs.begin(); it != defs.end(); ++it) {
        Cursor      cursor = it->first;
        std::string type   = it->second;

        std::cerr << cursor.content << "," << type << ","
                  << cursor.fromLine << "," << srcFile
                  << std::endl;
        std::cout << type << ","
                  << cursor.fromLine-1 << "." << cursor.fromCol+6 << ":"
                  << cursor.toLine-1 << "." << cursor.toCol+6 << ","
                  << cursor.content
                  << std::endl;
     }

    typedef std::map<std::string, std::vector<std::string> >  CallMap;
    for (CallMap::const_iterator it = call.begin(); it != call.end(); ++it) {
        for (size_t k=0; k < (it->second).size(); ++k) {
            std::cerr << it->first << ",CALLS,"
                      << (it->second)[k]
                      << "," << srcFile
                      << std::endl;
        }
    }
}

// namespace CrossRefs