Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenslang_compile_variable.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 6.5.3 00004 * 00005 * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a 00008 * copy of this software and associated documentation files (the "Software"), 00009 * to deal in the Software without restriction, including without limitation 00010 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 * and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00018 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00021 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00031 #include "main/imports.h" 00032 #include "slang_compile.h" 00033 #include "slang_mem.h" 00034 00035 00036 static slang_variable * 00037 slang_variable_new(void) 00038 { 00039 slang_variable *v = (slang_variable *) _slang_alloc(sizeof(slang_variable)); 00040 if (v) { 00041 if (!slang_variable_construct(v)) { 00042 _slang_free(v); 00043 v = NULL; 00044 } 00045 } 00046 return v; 00047 } 00048 00049 00050 static void 00051 slang_variable_delete(slang_variable * var) 00052 { 00053 slang_variable_destruct(var); 00054 _slang_free(var); 00055 } 00056 00057 00058 /* 00059 * slang_variable_scope 00060 */ 00061 00062 slang_variable_scope * 00063 _slang_variable_scope_new(slang_variable_scope *parent) 00064 { 00065 slang_variable_scope *s; 00066 s = (slang_variable_scope *) _slang_alloc(sizeof(slang_variable_scope)); 00067 if (s) 00068 s->outer_scope = parent; 00069 return s; 00070 } 00071 00072 00073 GLvoid 00074 _slang_variable_scope_ctr(slang_variable_scope * self) 00075 { 00076 self->variables = NULL; 00077 self->num_variables = 0; 00078 self->outer_scope = NULL; 00079 } 00080 00081 void 00082 slang_variable_scope_destruct(slang_variable_scope * scope) 00083 { 00084 unsigned int i; 00085 00086 if (!scope) 00087 return; 00088 for (i = 0; i < scope->num_variables; i++) { 00089 if (scope->variables[i]) 00090 slang_variable_delete(scope->variables[i]); 00091 } 00092 _slang_free(scope->variables); 00093 /* do not free scope->outer_scope */ 00094 } 00095 00096 int 00097 slang_variable_scope_copy(slang_variable_scope * x, 00098 const slang_variable_scope * y) 00099 { 00100 slang_variable_scope z; 00101 unsigned int i; 00102 00103 _slang_variable_scope_ctr(&z); 00104 z.variables = (slang_variable **) 00105 _slang_alloc(y->num_variables * sizeof(slang_variable *)); 00106 if (z.variables == NULL) { 00107 slang_variable_scope_destruct(&z); 00108 return 0; 00109 } 00110 for (z.num_variables = 0; z.num_variables < y->num_variables; 00111 z.num_variables++) { 00112 z.variables[z.num_variables] = slang_variable_new(); 00113 if (!z.variables[z.num_variables]) { 00114 slang_variable_scope_destruct(&z); 00115 return 0; 00116 } 00117 } 00118 for (i = 0; i < z.num_variables; i++) { 00119 if (!slang_variable_copy(z.variables[i], y->variables[i])) { 00120 slang_variable_scope_destruct(&z); 00121 return 0; 00122 } 00123 } 00124 z.outer_scope = y->outer_scope; 00125 slang_variable_scope_destruct(x); 00126 *x = z; 00127 return 1; 00128 } 00129 00130 00135 slang_variable * 00136 slang_variable_scope_grow(slang_variable_scope *scope) 00137 { 00138 const int n = scope->num_variables; 00139 scope->variables = (slang_variable **) 00140 _slang_realloc(scope->variables, 00141 n * sizeof(slang_variable *), 00142 (n + 1) * sizeof(slang_variable *)); 00143 if (!scope->variables) 00144 return NULL; 00145 00146 scope->num_variables++; 00147 00148 scope->variables[n] = slang_variable_new(); 00149 if (!scope->variables[n]) 00150 return NULL; 00151 00152 return scope->variables[n]; 00153 } 00154 00155 00156 00157 /* slang_variable */ 00158 00159 int 00160 slang_variable_construct(slang_variable * var) 00161 { 00162 if (!slang_fully_specified_type_construct(&var->type)) 00163 return 0; 00164 var->a_name = SLANG_ATOM_NULL; 00165 var->array_len = 0; 00166 var->initializer = NULL; 00167 var->size = 0; 00168 var->isTemp = GL_FALSE; 00169 var->store = NULL; 00170 var->declared = 0; 00171 return 1; 00172 } 00173 00174 00175 void 00176 slang_variable_destruct(slang_variable * var) 00177 { 00178 slang_fully_specified_type_destruct(&var->type); 00179 if (var->initializer != NULL) { 00180 slang_operation_destruct(var->initializer); 00181 _slang_free(var->initializer); 00182 } 00183 #if 0 00184 if (var->aux) { 00185 _mesa_free(var->aux); 00186 } 00187 #endif 00188 } 00189 00190 00191 int 00192 slang_variable_copy(slang_variable * x, const slang_variable * y) 00193 { 00194 slang_variable z; 00195 00196 if (!slang_variable_construct(&z)) 00197 return 0; 00198 if (!slang_fully_specified_type_copy(&z.type, &y->type)) { 00199 slang_variable_destruct(&z); 00200 return 0; 00201 } 00202 z.a_name = y->a_name; 00203 z.array_len = y->array_len; 00204 if (y->initializer != NULL) { 00205 z.initializer 00206 = (slang_operation *) _slang_alloc(sizeof(slang_operation)); 00207 if (z.initializer == NULL) { 00208 slang_variable_destruct(&z); 00209 return 0; 00210 } 00211 if (!slang_operation_construct(z.initializer)) { 00212 _slang_free(z.initializer); 00213 slang_variable_destruct(&z); 00214 return 0; 00215 } 00216 if (!slang_operation_copy(z.initializer, y->initializer)) { 00217 slang_variable_destruct(&z); 00218 return 0; 00219 } 00220 } 00221 z.size = y->size; 00222 slang_variable_destruct(x); 00223 *x = z; 00224 return 1; 00225 } 00226 00227 00232 slang_variable * 00233 _slang_variable_locate(const slang_variable_scope * scope, 00234 const slang_atom a_name, GLboolean all) 00235 { 00236 while (scope) { 00237 GLuint i; 00238 for (i = 0; i < scope->num_variables; i++) 00239 if (a_name == scope->variables[i]->a_name) 00240 return scope->variables[i]; 00241 if (all) 00242 scope = scope->outer_scope; 00243 else 00244 scope = NULL; 00245 } 00246 return NULL; 00247 } Generated on Mon May 28 2012 04:20:20 for ReactOS by
1.7.6.1
|