[go: up one dir, main page]

Menu

[r369]: / trunk / VTS3 / ScriptBase.h  Maximize  Restore  History

Download this file

292 lines (218 with data), 8.7 kB

  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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// ScriptBase.h: interface for the ScriptBase class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SCRIPTBASE_H__18DBD511_B069_11D4_BEEA_00A0C95A9812__INCLUDED_)
#define AFX_SCRIPTBASE_H__18DBD511_B069_11D4_BEEA_00A0C95A9812__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxtempl.h>
#include "BACnet.hpp"
//
// ScriptBase
//
// All of the script elements are derived from this base class that
// provides basic container functionality and information to display
// the heirarchy in the tree view.
//
class ScriptBase;
typedef ScriptBase *ScriptBasePtr;
class ScriptScanner;
class ScriptBase : public CList<ScriptBasePtr,ScriptBasePtr> {
public:
enum ScriptBaseType
{ scriptNull
, scriptSection
, scriptTest
, scriptDependency
, scriptReference
, scriptPacket
, scriptCase
, scriptCheck
, scriptMake
};
ScriptBase();
virtual ~ScriptBase();
ScriptBaseType baseType; // runtime type info
CString baseLabel; // label for tree view
int baseLineStart, baseLineCount; // where in source
HTREEITEM baseItem; // item handle when bound
int baseImage, baseStatus; // index and offset of status
ScriptBasePtr baseParent; // pointer to parent
CString m_strFile; // full path to file element resides ("" if base)
// list operations
void Append( ScriptBasePtr sbp, ScriptScanner * pscan = NULL ); // add a child at the end
void Remove( int indx ); // remove a child
int Length( void ); // number of children
ScriptBasePtr Child( int indx ); // specific child
};
const int kScriptBaseSize = sizeof( ScriptBase );
//
// ScriptSection
//
class ScriptSection : public ScriptBase {
public:
ScriptSection( const CString& title );
};
typedef ScriptSection *ScriptSectionPtr;
const int kScriptSectionSize = sizeof( ScriptSection );
//
// ScriptDependency
//
class ScriptDependency : public ScriptBase {
public:
ScriptDependency( const CString& number );
};
typedef ScriptDependency *ScriptDependencyPtr;
const int kScriptDependencySize = sizeof( ScriptDependency );
//
// ScriptReference
//
class ScriptReference : public ScriptBase {
public:
ScriptReference( const CString& clause );
};
typedef ScriptReference *ScriptReferencePtr;
const int kScriptReferenceSize = sizeof( ScriptReference );
//
// ScriptCase
//
class ScriptCase : public ScriptBase {
public:
ScriptCase *caseGroup;
ScriptCase *caseSubgroup;
ScriptCase( const CString& number );
};
typedef ScriptCase *ScriptCasePtr;
const int kScriptCaseSize = sizeof( ScriptCase );
//
// ScriptTest
//
//class ScriptPacket;
class ScriptCommand;
class ScriptTest : public ScriptCase {
public:
ScriptTest( const CString& number );
ScriptTest *testNext; // next test
// ScriptPacket *testFirstPacket; // first packet in test
ScriptCommand *testFirstCommand; // first packet in test
};
typedef ScriptTest *ScriptTestPtr;
const int kScriptTestSize = sizeof( ScriptTest );
//
// ScriptToken
//
enum ScriptTokenType
{ scriptError // invalid character
, scriptKeyword // word
, scriptTitle // title string
, scriptSymbol // operator or symbol
, scriptValue // some kind of value, see encoding
, scriptReference // EPICS reference name
, scriptEOL // end of line
, scriptEOF // end of file
};
enum ScriptEncodingType
{ scriptIntegerEnc // [+|-](0..9)*
, scriptFloatEnc // [+|-]N[.N][e[-]N]
, scriptDecimalEnc // D'nnn'
, scriptHexEnc // 0xFF, X'FF', &xFF
, scriptOctalEnc // 0o377, O'377', &O377
, scriptBinaryEnc // 0b11111111, B'11111111', &B11111111
, scriptASCIIEnc // A'hi', "hi", 'hi'
, scriptIPEnc // n.n.n.n[/n][:n]
, scriptComplex // Complex hunk o' data, enclosed in brackets [] to parse
// madanner 11/6/02, should be text like a string
// without quotes. Each complex data type decodes.
};
struct ScriptTranslateTable {
int scriptKeyword;
int scriptValue;
};
typedef ScriptTranslateTable *ScriptTranslateTablePtr;
const int kScriptTranslateTableSize = sizeof( ScriptTranslateTable );
//
// ScriptToken
//
class ScriptParmList;
typedef ScriptParmList *ScriptParmListPtr;
const int kTokenBufferSize = 8192;
class ScriptToken {
private:
void KillIndex(); // madanner 10/24/02
public:
ScriptToken( void ); // initialize
virtual ~ScriptToken( void ); // madanner 10/24/02, added virtual
ScriptToken( const ScriptToken &cpy ); // copy constructor allowed
operator =( const ScriptToken &ref ); // assignment allowed
ScriptTokenType tokenType; // token type
ScriptEncodingType tokenEnc; // value encoding
int tokenSymbol; // character code or keyword hash code
int tokenLine; // line number
int tokenOffset, tokenLength; // char offset and length
int m_nIndex; // index into value when resolved (-1=all, 0=size, 1>= index)
CString tokenValue; // token value
bool m_fIgnoreEscape; // madanner 6/03, true if quotes should ignore '\'
ScriptToken * pTokenIndex; // madanner 10/24/02, pointer to token for possible index
void SetIndex( ScriptToken * ptoken ); // madanner 10/24/02, index token chain helper
void ResolveIndex(ScriptParmListPtr parms); // madanner 10/24/02, index token chain built, time to resolve to number
bool IsInteger( int &valu, ScriptParmListPtr parms = 0 ) const; // acceptable integer form with parm lookup
bool IsInteger( int &valu, ScriptTranslateTablePtr tp ) const; // with keyword lookup
bool IsPropertyReference( int &prop ) const; // with keyword lookup
bool IsEncodeable( BACnetEncodeable &enc ) const; // can this be interpreted?
bool IsDontCare(void) const; // madanner 11/4/02, is this the '?' value?
CString RemoveQuotes( void ) const; // remove quotes from strings
static int HashCode( const char *key ); // return a hash code
static int Lookup( int code, ScriptTranslateTablePtr tp ); // find keyword in a table, -1 if not found
};
typedef ScriptToken *ScriptTokenPtr;
const int kScriptTokenSize = sizeof( ScriptToken );
//
// ScriptTokenList
//
class ScriptTokenList : public CList<ScriptTokenPtr,ScriptTokenPtr> {
public:
ScriptTokenList( void );
~ScriptTokenList( void );
void Append( const ScriptToken& tok ); // add a token (makes a copy)
int Length( void ); // number of tokens
//madanner 10/24/02, const removed
ScriptToken& operator []( int i ); // index operator
};
typedef ScriptTokenList *ScriptTokenListPtr;
const int kScriptTokenListSize = sizeof( ScriptTokenList );
//
// ScriptScanner
//
class ScriptDocument;
class ScriptScanner {
protected:
//madanner 6/03 for #include support
// CEdit* scanSource; // where this token came from (?)
int scanLine; // line number of source
int m_nLineOffset; // # of chars in file to current line start
char scanLineBuffer[kTokenBufferSize]; // current line being parsed
char scanValueBuffer[kTokenBufferSize]; // current token being built
void FormatError( ScriptToken &tok, char *msg ); // sets up the token and throws the message
void Deblank(void); // madanner 10/24/02, frequently called
void ScanIndexTokens( ScriptToken & tok ); // madanner 10/24/02, scan for [] tokens
void Initialize(void);
public:
const char *scanSrc; // ptr to current/next token
ScriptDocument * m_pdocSource; // token comes from VTS document
CStdioFile * m_fileSource; // from include files
ScriptScanner( ScriptDocument * pdoc ); // source of parsing
ScriptScanner( CStdioFile * fileSource ); // source of parsing for include files
ScriptScanner( const char *src ); // source of parsing
~ScriptScanner( void );
void Next( ScriptToken& tok ); // put the next token in here
void Peek( ScriptToken& tok ); // non-destructive look into stream
void NextTitle( ScriptToken& tok ); // the rest of the line is a title
void NextLine( ScriptToken& tok ); // move to the next line in the source
void ReportSyntaxError( ScriptToken * ptok, LPCSTR lpszErrorMsg );
CString GetPathName(void);
};
typedef ScriptScanner *ScriptScannerPtr;
const int kScriptScannerSize = sizeof( ScriptScanner );
typedef CTypedPtrArray<CPtrArray, ScriptScanner *> ScriptScanners;
#endif // !defined(AFX_SCRIPTBASE_H__18DBD511_B069_11D4_BEEA_00A0C95A9812__INCLUDED_)