[go: up one dir, main page]

File: fortranline.cpp

package info (click to toggle)
findent 3.1.7-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 2,176 kB
  • sloc: sh: 4,746; cpp: 4,049; fortran: 1,565; pascal: 1,204; lex: 533; yacc: 305; makefile: 179; python: 155; lisp: 52
file content (112 lines) | stat: -rw-r--r-- 3,177 bytes parent folder | download
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
#include <iostream>

#include "fortranline.h"

void Fortranline::print()
{
   std::cout << "orig_line: ["      << orig_line      << "]" << std::endl;
   std::cout << "trim: ["           << trim()         << "]" << std::endl;
   std::cout << "ltrim: ["          << ltrim()        << "]" << std::endl;
   std::cout << "rtrim: ["          << rtrim()        << "]" << std::endl;
   std::cout << "trimmed_line: ["   << trimmed_line() << "]" << std::endl;
   std::cout << "firstchar: ["      << firstchar()    << "]" << std::endl;
   std::cout << "lastchar: ["       << lastchar()     << "]" << std::endl;
   std::cout << "first2chars: ["    << first2chars()  << "]" << std::endl;
   std::cout << "scanfixpre: "      << scanfixpre()   <<        std::endl;
   std::cout << "rest: ["           << rest()         << "]" << std::endl;
   std::cout << "global_format:"    << g_format2txt() <<        std::endl;
}

std::ostream& operator <<(std::ostream &os,Fortranline &obj)
{
   os<<"["<<obj.str()<<"]";
   return os;
}

void Fortranline::do_clean()
{
   init();
   switch(format())
   {
      case FIXED:
	 if (line_length() == 0)
	    orig_line = ltab2sp(orig_line);
	 else
	    //
	    // With tabbed input there is a difference between
	    // gfortran and other compilers with respect to the line length.
	    // Other compilers simply count the number of characters.
	    // gfortran always assumes that the
	    // continuation character is in column 6,
	    // so this needs extra attention:
	    //
	    if(gnu_format())
	       orig_line = ltab2sp(orig_line).substr(0,line_length());
	    else
	       orig_line = ::rtrim(orig_line.substr(0,line_length()));
	 // code to create orig_without_omp
	 if (omp())
	 {
	    orig_without_omp = "  " + orig_line.substr(2);
	 }
	 else
	    orig_without_omp = orig_line;
	 break;
      case FREE:
      default:
	 if (line_length() == 0)
	    orig_line = ::rtrim(orig_line);
	 else
	    orig_line = ::rtrim(orig_line.substr(0,line_length()));
	 // code to create orig_without_omp
	 if (omp())
	 {
	    //
	    // this is a line starting with [ ]*!$
	    // there is a problem here: if this is the first
	    // line then a space must follow. If it is not the
	    // first line, then anything can follow.
	    // To simplify things, the lexer only says it is a
	    // omp conditional compilation line if blank space 
	    // follows !$, or the line ends at !$
	    //
	    // orig_line will start with '!$ '
	    // chop off
	    //
	    std::string sl = ::ltrim(orig_line);
	    switch(sl.length())
	    {
	       case 0:  // cannot happen
		  orig_without_omp = "";
		  break;
	       case 1:  // cannot happen
		  orig_without_omp = " ";
		  break;
	       case 2:
		  orig_without_omp = "  ";
		  break;
	       case 3:
		  orig_without_omp = "   ";
		  break;
	       default:
		  orig_without_omp = sl.substr(3);
	    }
	 }
	 else
	    orig_without_omp = orig_line;
	 break;
   }
   is_clean = 1;
}

bool Fortranline::do_omp()
{
      if (!gl->global_omp)
	 return 0;
      if (format() == FIXED)
	 lexer_set(orig_line,SCANOMPFIXED);
      else
	 lexer_set(orig_line,SCANOMPFREE);
      int rc = yylex();
      return rc == OMP;
}