ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

slang_compile_struct.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_mem.h"
00033 #include "slang_compile.h"
00034 
00035 
00036 GLvoid
00037 _slang_struct_scope_ctr(slang_struct_scope * self)
00038 {
00039    self->structs = NULL;
00040    self->num_structs = 0;
00041    self->outer_scope = NULL;
00042 }
00043 
00044 void
00045 slang_struct_scope_destruct(slang_struct_scope * scope)
00046 {
00047    GLuint i;
00048 
00049    for (i = 0; i < scope->num_structs; i++)
00050       slang_struct_destruct(scope->structs + i);
00051    _slang_free(scope->structs);
00052    /* do not free scope->outer_scope */
00053 }
00054 
00055 int
00056 slang_struct_scope_copy(slang_struct_scope * x, const slang_struct_scope * y)
00057 {
00058    slang_struct_scope z;
00059    GLuint i;
00060 
00061    _slang_struct_scope_ctr(&z);
00062    z.structs = (slang_struct *)
00063       _slang_alloc(y->num_structs * sizeof(slang_struct));
00064    if (z.structs == NULL) {
00065       slang_struct_scope_destruct(&z);
00066       return 0;
00067    }
00068    for (z.num_structs = 0; z.num_structs < y->num_structs; z.num_structs++)
00069       if (!slang_struct_construct(&z.structs[z.num_structs])) {
00070          slang_struct_scope_destruct(&z);
00071          return 0;
00072       }
00073    for (i = 0; i < z.num_structs; i++)
00074       if (!slang_struct_copy(&z.structs[i], &y->structs[i])) {
00075          slang_struct_scope_destruct(&z);
00076          return 0;
00077       }
00078    z.outer_scope = y->outer_scope;
00079    slang_struct_scope_destruct(x);
00080    *x = z;
00081    return 1;
00082 }
00083 
00084 slang_struct *
00085 slang_struct_scope_find(slang_struct_scope * stru, slang_atom a_name,
00086                         int all_scopes)
00087 {
00088    GLuint i;
00089 
00090    for (i = 0; i < stru->num_structs; i++)
00091       if (a_name == stru->structs[i].a_name)
00092          return &stru->structs[i];
00093    if (all_scopes && stru->outer_scope != NULL)
00094       return slang_struct_scope_find(stru->outer_scope, a_name, 1);
00095    return NULL;
00096 }
00097 
00098 /* slang_struct */
00099 
00100 int
00101 slang_struct_construct(slang_struct * stru)
00102 {
00103    stru->a_name = SLANG_ATOM_NULL;
00104    stru->fields = (slang_variable_scope *)
00105       _slang_alloc(sizeof(slang_variable_scope));
00106    if (stru->fields == NULL)
00107       return 0;
00108    _slang_variable_scope_ctr(stru->fields);
00109 
00110    stru->structs =
00111       (slang_struct_scope *) _slang_alloc(sizeof(slang_struct_scope));
00112    if (stru->structs == NULL) {
00113       slang_variable_scope_destruct(stru->fields);
00114       _slang_free(stru->fields);
00115       return 0;
00116    }
00117    _slang_struct_scope_ctr(stru->structs);
00118    stru->constructor = NULL;
00119    return 1;
00120 }
00121 
00122 void
00123 slang_struct_destruct(slang_struct * stru)
00124 {
00125    slang_variable_scope_destruct(stru->fields);
00126    _slang_free(stru->fields);
00127    slang_struct_scope_destruct(stru->structs);
00128    _slang_free(stru->structs);
00129 }
00130 
00131 int
00132 slang_struct_copy(slang_struct * x, const slang_struct * y)
00133 {
00134    slang_struct z;
00135 
00136    if (!slang_struct_construct(&z))
00137       return 0;
00138    z.a_name = y->a_name;
00139    if (!slang_variable_scope_copy(z.fields, y->fields)) {
00140       slang_struct_destruct(&z);
00141       return 0;
00142    }
00143    if (!slang_struct_scope_copy(z.structs, y->structs)) {
00144       slang_struct_destruct(&z);
00145       return 0;
00146    }
00147    slang_struct_destruct(x);
00148    *x = z;
00149    return 1;
00150 }
00151 
00152 int
00153 slang_struct_equal(const slang_struct * x, const slang_struct * y)
00154 {
00155    GLuint i;
00156 
00157    if (x->fields->num_variables != y->fields->num_variables)
00158       return 0;
00159 
00160    for (i = 0; i < x->fields->num_variables; i++) {
00161       const slang_variable *varx = x->fields->variables[i];
00162       const slang_variable *vary = y->fields->variables[i];
00163 
00164       if (varx->a_name != vary->a_name)
00165          return 0;
00166       if (!slang_type_specifier_equal(&varx->type.specifier,
00167                                       &vary->type.specifier))
00168          return 0;
00169       if (varx->type.specifier.type == SLANG_SPEC_ARRAY)
00170          if (varx->array_len != vary->array_len)
00171             return GL_FALSE;
00172    }
00173    return 1;
00174 }

Generated on Sun May 27 2012 04:20:40 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.