[go: up one dir, main page]

File: pre_analyzer.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 (79 lines) | stat: -rw-r--r-- 1,745 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
#include <string>
#include "pre_analyzer.h"
#include "functions.h"
#include "parser.hpp"
//
// if start of s ==
// #\s*if
// or
// #\s*elif
// or
// #\s*else
// or
// #\s*endif
//
// then the function returns
// IF:  an #if is found
// ELIF:  an #elif is found
// ELSE:  an #else is found
// ENDIF:  an #endif is found, without preceding #else
// ENDIFE:  an #endif is found, with preceding #else
//
// if start of s ==
// ??\s*if
// or
// ??\s*else if
// or
// ??\s*else
// or
// ??\s*endif
//
// (all case and space independent)
//
// then the function returns
// IF:     '??if'  found
// ELIF:   '??else if'  found
// ELSE:   '??else'  found
// ENDIF:  '??endif'  found, without preceding '#else' or '??else'
// ENDIFE: '??endif'  found, with preceding '#else' or '??else'
//
// The funcion returns NONE if none of above is found.
//
int Pre_analyzer::analyze(const std::string s, const int pretype)
{
   switch(pretype)
   {
      case CPP_IF:  case CPP_ENDIF:  case CPP_ELSE:  case CPP_ELIF:
      case COCO_IF: case COCO_ENDIF: case COCO_ELSE: case COCO_ELIF: 
      case INCLUDE_CPP: case INCLUDE_COCO: break;
      default: return this->PRE_NONE;
   }

   int r;
   switch(pretype)
   {
      case CPP_IF: case COCO_IF:
	 this->ifelse_stack.push(0);
	 return this->PRE_IF;
      case CPP_ELIF: case COCO_ELIF:
	 return this->PRE_ELIF;
      case CPP_ELSE: case COCO_ELSE:
	 if (!this->ifelse_stack.empty())
	 {
	    ifelse_stack.pop();
	    ifelse_stack.push(1);
	 }
	 return this->PRE_ELSE;
      case CPP_ENDIF: case COCO_ENDIF:
	 r = this->PRE_ENDIF; 
	 if (!ifelse_stack.empty())
	 {
	    if (ifelse_stack.top())
	       r = this->PRE_ENDIFE;
	    ifelse_stack.pop();
	 }
	 return r;
    default:
      return this->PRE_NONE;
   }
}