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_function.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  6.5
00004  *
00005  * Copyright (C) 2005-2006  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 int
00037 slang_function_construct(slang_function * func)
00038 {
00039    func->kind = SLANG_FUNC_ORDINARY;
00040    if (!slang_variable_construct(&func->header))
00041       return 0;
00042 
00043    func->parameters = (slang_variable_scope *)
00044       _slang_alloc(sizeof(slang_variable_scope));
00045    if (func->parameters == NULL) {
00046       slang_variable_destruct(&func->header);
00047       return 0;
00048    }
00049 
00050    _slang_variable_scope_ctr(func->parameters);
00051    func->param_count = 0;
00052    func->body = NULL;
00053    return 1;
00054 }
00055 
00056 void
00057 slang_function_destruct(slang_function * func)
00058 {
00059    slang_variable_destruct(&func->header);
00060    slang_variable_scope_destruct(func->parameters);
00061    _slang_free(func->parameters);
00062    if (func->body != NULL) {
00063       slang_operation_destruct(func->body);
00064       _slang_free(func->body);
00065    }
00066 }
00067 
00068 
00069 slang_function *
00070 slang_function_new(slang_function_kind kind)
00071 {
00072    slang_function *fun = (slang_function *)
00073       _slang_alloc(sizeof(slang_function));
00074    if (fun) {
00075       slang_function_construct(fun);
00076       fun->kind = kind;
00077    }
00078    return fun;
00079 }
00080 
00081 
00082 /*
00083  * slang_function_scope
00084  */
00085 
00086 GLvoid
00087 _slang_function_scope_ctr(slang_function_scope * self)
00088 {
00089    self->functions = NULL;
00090    self->num_functions = 0;
00091    self->outer_scope = NULL;
00092 }
00093 
00094 void
00095 slang_function_scope_destruct(slang_function_scope * scope)
00096 {
00097    unsigned int i;
00098 
00099    for (i = 0; i < scope->num_functions; i++)
00100       slang_function_destruct(scope->functions + i);
00101    _slang_free(scope->functions);
00102 }
00103 
00104 
00108 GLboolean
00109 _slang_function_has_return_value(const slang_function *fun)
00110 {
00111    return fun->header.type.specifier.type != SLANG_SPEC_VOID;
00112 }
00113 
00114 
00122 int
00123 slang_function_scope_find_by_name(slang_function_scope * funcs,
00124                                   slang_atom a_name, int all_scopes)
00125 {
00126    unsigned int i;
00127 
00128    for (i = 0; i < funcs->num_functions; i++)
00129       if (a_name == funcs->functions[i].header.a_name)
00130          return 1;
00131    if (all_scopes && funcs->outer_scope != NULL)
00132       return slang_function_scope_find_by_name(funcs->outer_scope, a_name, 1);
00133    return 0;
00134 }
00135 
00136 
00147 slang_function *
00148 slang_function_scope_find(slang_function_scope * funcs, slang_function * fun,
00149                           int all_scopes)
00150 {
00151    unsigned int i;
00152 
00153    for (i = 0; i < funcs->num_functions; i++) {
00154       slang_function *f = &funcs->functions[i];
00155       const GLuint haveRetValue = 0;
00156 #if 0
00157          = (f->header.type.specifier.type != SLANG_SPEC_VOID);
00158 #endif
00159       unsigned int j;
00160 
00161       /*
00162       printf("Compare name %s to %s  (ret %u, %d, %d)\n",
00163              (char *) fun->header.a_name, (char *) f->header.a_name,
00164              haveRetValue,
00165              fun->param_count, f->param_count);
00166       */
00167 
00168       if (fun->header.a_name != f->header.a_name)
00169          continue;
00170       if (fun->param_count != f->param_count)
00171          continue;
00172       for (j = haveRetValue; j < fun->param_count; j++) {
00173          if (!slang_type_specifier_equal
00174              (&fun->parameters->variables[j]->type.specifier,
00175               &f->parameters->variables[j]->type.specifier))
00176             break;
00177       }
00178       if (j == fun->param_count) {
00179          /*
00180          printf("Found match\n");
00181          */
00182          return f;
00183       }
00184    }
00185    /*
00186    printf("Not found\n");
00187    */
00188    if (all_scopes && funcs->outer_scope != NULL)
00189       return slang_function_scope_find(funcs->outer_scope, fun, 1);
00190    return NULL;
00191 }
00192 
00193 
00197 slang_function *
00198 _slang_function_locate(const slang_function_scope * funcs, slang_atom a_name,
00199                        slang_operation * args, GLuint num_args,
00200                        const slang_name_space * space, slang_atom_pool * atoms,
00201                        slang_info_log *log, GLboolean *error)
00202 {
00203    slang_typeinfo arg_ti[100];
00204    GLuint i;
00205 
00206    *error = GL_FALSE;
00207 
00208    /* determine type of each argument */
00209    assert(num_args < 100);
00210    for (i = 0; i < num_args; i++) {
00211       if (!slang_typeinfo_construct(&arg_ti[i]))
00212          return NULL;
00213       if (!_slang_typeof_operation(&args[i], space, &arg_ti[i], atoms, log)) {
00214          return NULL;
00215       }
00216    }
00217 
00218    /* loop over function scopes */
00219    while (funcs) {
00220 
00221       /* look for function with matching name and argument/param types */
00222       for (i = 0; i < funcs->num_functions; i++) {
00223          slang_function *f = &funcs->functions[i];
00224          const GLuint haveRetValue = _slang_function_has_return_value(f);
00225          GLuint j;
00226 
00227          if (a_name != f->header.a_name)
00228             continue;
00229          if (f->param_count - haveRetValue != num_args)
00230             continue;
00231 
00232          /* compare parameter / argument types */
00233          for (j = 0; j < num_args; j++) {
00234             if (!slang_type_specifier_compatible(&arg_ti[j].spec,
00235                               &f->parameters->variables[j]->type.specifier)) {
00236                /* param/arg types don't match */
00237                break;
00238             }
00239 
00240             /* "out" and "inout" formal parameter requires the actual
00241              * argument to be an l-value.
00242              */
00243             if (!arg_ti[j].can_be_referenced &&
00244                 (f->parameters->variables[j]->type.qualifier == SLANG_QUAL_OUT ||
00245                  f->parameters->variables[j]->type.qualifier == SLANG_QUAL_INOUT)) {
00246                /* param is not an lvalue! */
00247                *error = GL_TRUE;
00248                return NULL;
00249             }
00250          }
00251 
00252          if (j == num_args) {
00253             /* name and args match! */
00254             return f;
00255          }
00256       }
00257 
00258       funcs = funcs->outer_scope;
00259    }
00260 
00261    return NULL;
00262 }

Generated on Fri May 25 2012 04:18:48 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.