Debian Codegraph @

src/core/chuck_frame.cpp

raw symbols SCIP
1 /*----------------------------------------------------------------------------
2 ChucK Strongly-timed Audio Programming Language
3 Compiler, Virtual Machine, and Synthesis Engine
4
5 Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.stanford.edu/
7 http://chuck.cs.princeton.edu/
8
9 This program is free software; you can redistribute it and/or modify
10 it under the dual-license terms of EITHER the MIT License OR the GNU
11 General Public License (the latter as published by the Free Software
12 Foundation; either version 2 of the License or, at your option, any
13 later version).
14
15 This program is distributed in the hope that it will be useful and/or
16 interesting, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 MIT Licence and/or the GNU General Public License for details.
19
20 You should have received a copy of the MIT License and the GNU General
21 Public License (GPL) along with this program; a copy of the GPL can also
22 be obtained by writing to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 U.S.A.
24 -----------------------------------------------------------------------------*/
25
26 //-----------------------------------------------------------------------------
27 // file: chuck_frame.cpp
28 // desc: chuck scope frame
29 //
30 // author: Ge Wang ([email protected] | [email protected])
31 // date: Autumn 2002
32 //-----------------------------------------------------------------------------
33 #include "chuck_frame.h"
34 using namespace std;
35
36
37
38
39 //-----------------------------------------------------------------------------
40 // name: Chuck_Frame()
41 // desc: ...
42 //-----------------------------------------------------------------------------
43 Chuck_Frame::Chuck_Frame()
44 {
45 // name
46 name = "";
47 // ofset
48 curr_offset = 0;
49 // don't know
50 num_access = 0;
51 }
52
53
54
55
56 //-----------------------------------------------------------------------------
57 // name: alloc_local()
58 // desc: ...
59 //-----------------------------------------------------------------------------
60 Chuck_Local * Chuck_Frame::alloc_local( t_CKUINT size, const string & theName,
61 t_CKBOOL is_ref, t_CKBOOL is_obj, t_CKBOOL is_global )
62 {
63 // alloc
64 Chuck_Local * local = new Chuck_Local;
65 // size
66 local->size = size;
67 // the offset
68 local->offset = this->curr_offset;
69 // ref
70 local->is_ref = is_ref;
71 // is object type? (added ge: 2012 april | added 1.3.0.0)
72 local->is_obj = is_obj;
73 // REFACTOR-2017: is global?
74 local->is_global = is_global;
75 // the next offset
76 this->curr_offset += local->size;
77 // name
78 local->name = theName;
79 // push the local
80 this->stack.push_back( local );
81
82 return local;
83 }
84
85
86
87
88 //-----------------------------------------------------------------------------
89 // name: push_scope()
90 // desc: ...
91 //-----------------------------------------------------------------------------
92 void Chuck_Frame::push_scope( )
93 {
94 stack.push_back( NULL );
95 }
96
97
98
99
100 //-----------------------------------------------------------------------------
101 // name: get_scope()
102 // desc: get current scope (added 1.3.0.0)
103 //-----------------------------------------------------------------------------
104 void Chuck_Frame::get_scope( vector<Chuck_Local *> & out, bool localOnly ) const
105 {
106 // sanity
107 assert( this->stack.size() > 0 );
108
109 // the local
110 Chuck_Local * local = NULL;
111 // the index
112 t_CKINT index = this->stack.size() - 1;
113
114 // loop
115 while( index >= 0 )
116 {
117 // did we hit a stack boundary (delineated by NULL)
118 // localOnly option added 1.5.0.0 (ge) -- to get all scope in the frame
119 if( localOnly && this->stack[index] != NULL )
120 break;
121
122 // last thing
123 local = stack[index];
124 // move
125 index--;
126 // check if not null
127 if( local )
128 {
129 // copy out
130 out.push_back( local );
131 }
132 }
133 }
134
135
136
137
138 //-----------------------------------------------------------------------------
139 // name: pop_scope()
140 // desc: ....
141 //-----------------------------------------------------------------------------
142 void Chuck_Frame::pop_scope( vector<Chuck_Local *> & out )
143 {
144 // sanity
145 assert( this->stack.size() > 0 );
146
147 // the local
148 Chuck_Local * local = NULL;
149
150 // loop
151 while( this->stack.size() && this->stack.back() )
152 {
153 // last thing
154 local = stack.back();
155 // pop
156 stack.pop_back();
157 // check if not null
158 if( local )
159 {
160 // offset
161 curr_offset -= local->size;
162 // copy out (NOTE: these locals should be memory managed outside)
163 out.push_back( local );
164 }
165 }
166
167 // sanity (should be at least one left)
168 assert( this->stack.size() > 0 );
169 // get rid of null boundary character (added 1.3.0.0)
170 this->stack.pop_back();
171 }