aboutsummaryrefslogtreecommitdiff
path: root/src/rules.cpp
blob: 0f7939ab2d3523fd032965ad1e7f1a0f12f2279b (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
/*
    Copyright (C) 2014 BARRATERO Laurent                                   

    AeroUp 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 3 of the License, or
    (at your option) any later version.

    Aeroup is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
*/

/*
 *       Filename:  rules.cpp
 *
 *    Description:  
 *
 *        Version:  0.3.2
 *        Created:  31/12/2013 18:33:14
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  BARATTERO Laurent, laurentba<at>larueluberlu.net
 *   Organization:  La rue Luberlu
 *
 */
#include "rules.hpp"

using namespace std;

/*
 *       Class:  Rules
 *      Method:  Rules
 * Description:  constructor
 */
Rules::Rules (string gloFileName):
  fileName(gloFileName)
{
}  /* -----  end of method Rules::Rules  (constructor)  ----- */

  bool 
Rules::isStandardCmdPossible(int nb_line, int fct)
{
  if(!end || defsub_cout )
    return true;
  else
  {
    string error = "invalid " + FctVectStr[fct] + " not in main sequence or sub-sequence"; 
    throw RulesError( error.c_str() , fileName, nb_line );
    return false;
  }
}
  bool
Rules::isDefsubCmdPossible()
{

  return true;
}
  bool
Rules::isEndPossible()
{

  return true;
}

  bool
Rules::isSeqOk()
{
  return true;

}


  void
Rules::setEnd(int nb_line)
{
  if(!end && !loop_count)
    end = true;
  else
  {
    if(end)
    {
      string error = "Attempt to define more than one 'END command'"; 
      throw RulesError(error.c_str(), fileName, nb_line );
    }
    else
    {
      string error = "Reached end of main sequence with unterminated loop"; 
      throw RulesError(error.c_str(), fileName, nb_line );
    }
  }
}

  void
Rules::setDefsub(int nb_line)
{
  if(!defsub_cout && end)
  {
    defsub_cout = nb_line;
  }
  else
  { 
    if(!end)
    {
      string error = "Attempt to define subsequence before the main sequence is complete "; 
      throw RulesError(error.c_str(), fileName, nb_line );
    }
    else
    {
      string error = "Attempting to define a subroutine inside another subroutine' "; 
      throw RulesError(error.c_str(), fileName, nb_line );
    }
  }
}

  void
Rules::unsetDefsub(int nb_line)
{
  if(defsub_cout && !loop_count)
  {
    defsub_cout = 0;
  }
  else 
  {
    if (!defsub_cout)
    {
      string error = "ENDSUB without corresponding DEFSUB command"; 
      throw RulesError(error.c_str(), fileName, nb_line );
    }
    else
    {
      string error = "'ENDSUB command' found with unterminated 'Loop command'"; 
      throw RulesError(error.c_str(), fileName, nb_line );
    }
  }
}

  void
Rules::endTestDefsub()
{
  if (defsub_cout)
  {
    string error = "Reached EOF with unterminated 'DEFSUB command'";
    throw RulesError(error.c_str(), fileName, defsub_cout);
  }
}



  void
Rules::setloop(int nb_line)
{
  isStandardCmdPossible(nb_line, L_FCT);
  loop_count +=1;
}

  void
Rules::unsetloop(int nb_line)
{
  isStandardCmdPossible(nb_line, E_FCT);
  if (loop_count > 0)
    loop_count -=1;
  else
  {
    string error = "End Loop command with no Loop Command"; 
    throw RulesError(error.c_str(), fileName, nb_line );
  }
}



/*
 *       Class:  Rules
 *      Method:  Rules :: twiceDefsubError
 * Description:  
 */
  void
Rules::twiceDefsubError(int nb_line)
{
    // to do : add class warning
    throw RulesError("Error, more than one definition for a sub function !", fileName, nb_line );

}		/* -----  end of method Rules::twiceDefsubError  ----- */

  void
Rules::noDefsubError(string sub_name)
{
    string error = "No definition for SUB," + sub_name ; 
    throw RulesError(error.c_str(), fileName);

}