Clause.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Kernel Clause.hpp */
40 /* */
41 /* Primitive Translator Clause Class Definitions */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxClause
45 #define Included_RexxClause
46 
47 #include "SourceLocation.hpp"
48 
49 #include "ArrayClass.hpp"
50 #include "Token.hpp"
51 
53  public:
54  void *operator new(size_t);
55  inline void *operator new(size_t size, void *ptr) {return ptr;};
56  inline void operator delete(void *) { ; }
57  inline void operator delete(void *, void *) { ; }
58 
59  RexxClause();
60  inline RexxClause(RESTORETYPE restoreType) { ; };
61 
62  void live(size_t);
63  void liveGeneral(int reason);
64  void flatten(RexxEnvelope *);
65  void setStart(size_t, size_t);
66  void setEnd(size_t, size_t);
67  void trim();
68  void newClause();
71  inline void firstToken() {this->current = this->first;};
72  inline const SourceLocation &getLocation() { return clauseLocation; }
73  inline void setLocation(SourceLocation &l) { clauseLocation = l; }
74  inline void previous() { this->current--; }
75  inline RexxToken *next() { return (RexxToken *)this->tokens->get(this->current++); }
76  inline size_t mark() { return current; }
77  inline void reset(size_t position) { current = position; }
78 
79  SourceLocation clauseLocation; /* position of the clause */
80  size_t current; /* index of current token of clause */
81  size_t first; /* first token of clause */
82  RexxArray *tokens; /* array of tokens in the clause */
83  size_t size; /* size of token array */
84  size_t free; /* location of first free token */
85 
86  // When two tokens are created at once by sourceNextToken, both tokens are put
87  // in the array of tokens, but only the first token is returned. The second is
88  // cached and returned at the next call of sourceNextToken. No need to protect
89  // this cached token from GC, it's proctected by the array of tokens.
90  // This cached token is cleared when returned by sourceNextToken, or when
91  // this->free is updated.
92  RexxToken *cachedToken; /* cached token */
93 };
94 #endif
RESTORETYPE
Definition: ObjectClass.hpp:82
RexxObject * get(size_t pos)
Definition: ArrayClass.hpp:203
RexxClause()
Definition: Clause.cpp:54
void newClause()
Definition: Clause.cpp:130
void setStart(size_t, size_t)
Definition: Clause.cpp:96
RexxClause(RESTORETYPE restoreType)
Definition: Clause.hpp:60
size_t current
Definition: Clause.hpp:80
void setEnd(size_t, size_t)
Definition: Clause.cpp:106
size_t mark()
Definition: Clause.hpp:76
void flatten(RexxEnvelope *)
Definition: Clause.cpp:84
void reset(size_t position)
Definition: Clause.hpp:77
void trim()
Definition: Clause.cpp:116
RexxToken * newToken(int, int, RexxString *, SourceLocation &)
Definition: Clause.cpp:143
void previous()
Definition: Clause.hpp:74
void liveGeneral(int reason)
Definition: Clause.cpp:76
size_t first
Definition: Clause.hpp:81
size_t free
Definition: Clause.hpp:84
RexxToken * nextRealToken()
Definition: Clause.cpp:177
SourceLocation clauseLocation
Definition: Clause.hpp:79
RexxArray * tokens
Definition: Clause.hpp:82
void live(size_t)
Definition: Clause.cpp:68
void firstToken()
Definition: Clause.hpp:71
RexxToken * cachedToken
Definition: Clause.hpp:92
const SourceLocation & getLocation()
Definition: Clause.hpp:72
size_t size
Definition: Clause.hpp:83
RexxToken * next()
Definition: Clause.hpp:75
void setLocation(SourceLocation &l)
Definition: Clause.hpp:73