| 1 | /* ***** BEGIN LICENSE BLOCK *****
|
|---|
| 2 | * Version: CDDL 1.0/LGPL 2.1
|
|---|
| 3 | *
|
|---|
| 4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND
|
|---|
| 5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
|
|---|
| 6 | * this file except in compliance with the License. You may obtain a copy of
|
|---|
| 7 | * the License at http://www.sun.com/cddl/
|
|---|
| 8 | *
|
|---|
| 9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
|---|
| 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|---|
| 11 | * for the specific language governing rights and limitations under the
|
|---|
| 12 | * License.
|
|---|
| 13 | *
|
|---|
| 14 | * The Original Code is "NOM" Netlabs Object Model
|
|---|
| 15 | *
|
|---|
| 16 | * The Initial Developer of the Original Code is
|
|---|
| 17 | * netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
|
|---|
| 18 | * Portions created by the Initial Developer are Copyright (C) 2007-2008
|
|---|
| 19 | * the Initial Developer. All Rights Reserved.
|
|---|
| 20 | *
|
|---|
| 21 | * Contributor(s):
|
|---|
| 22 | *
|
|---|
| 23 | * Alternatively, the contents of this file may be used under the terms of
|
|---|
| 24 | * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
|
|---|
| 25 | * case the provisions of the LGPL are applicable instead of those above. If
|
|---|
| 26 | * you wish to allow use of your version of this file only under the terms of
|
|---|
| 27 | * the LGPL, and not to allow others to use your version of this file under
|
|---|
| 28 | * the terms of the CDDL, indicate your decision by deleting the provisions
|
|---|
| 29 | * above and replace them with the notice and other provisions required by the
|
|---|
| 30 | * LGPL. If you do not delete the provisions above, a recipient may use your
|
|---|
| 31 | * version of this file under the terms of any one of the CDDL or the LGPL.
|
|---|
| 32 | *
|
|---|
| 33 | * ***** END LICENSE BLOCK ***** */
|
|---|
| 34 | #ifdef __OS2__
|
|---|
| 35 | # include <os2.h>
|
|---|
| 36 | #endif
|
|---|
| 37 | #include <stdlib.h>
|
|---|
| 38 | #include <string.h>
|
|---|
| 39 |
|
|---|
| 40 | #include <glib.h>
|
|---|
| 41 | #include <glib/gprintf.h>
|
|---|
| 42 |
|
|---|
| 43 | #define INCL_FILE
|
|---|
| 44 | #include "parser.h"
|
|---|
| 45 |
|
|---|
| 46 | extern GScanner *gScanner;
|
|---|
| 47 | #if 0
|
|---|
| 48 | /**
|
|---|
| 49 | Helper function which scans the array of parent interfaces and returns the structure of the
|
|---|
| 50 | interface which introduced the given method.
|
|---|
| 51 |
|
|---|
| 52 | \Param pif Pointer to an interface which parents should be scanned.
|
|---|
| 53 | \PARAM chrName Name of the method.
|
|---|
| 54 |
|
|---|
| 55 | \Returns If no interface with a method with that name can be found NULL is returned otherwise a
|
|---|
| 56 | pointer to the interface structure..
|
|---|
| 57 | */
|
|---|
| 58 | PINTERFACE findInterfaceFromMethodName(PINTERFACE pif, gchar* chrName)
|
|---|
| 59 | {
|
|---|
| 60 | PINTERFACE pifParent=pif;
|
|---|
| 61 | PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;
|
|---|
| 62 |
|
|---|
| 63 | if(!pParseInfo|| !pifParent)
|
|---|
| 64 | return NULL;
|
|---|
| 65 |
|
|---|
| 66 | while((pifParent=getParentInterface(pifParent))!=NULL)
|
|---|
| 67 | {
|
|---|
| 68 | int a;
|
|---|
| 69 | GPtrArray *pArray=pifParent->pMethodArray;
|
|---|
| 70 | gboolean fFound=FALSE;
|
|---|
| 71 |
|
|---|
| 72 | for(a=0;a<pArray->len && !fFound; a++){
|
|---|
| 73 | PMETHOD pm=(PMETHOD)g_ptr_array_index(pArray, a);
|
|---|
| 74 |
|
|---|
| 75 | if(!strcmp(pm->chrName, chrName))
|
|---|
| 76 | fFound=TRUE;
|
|---|
| 77 | }/* for() */
|
|---|
| 78 |
|
|---|
| 79 | if(fFound)
|
|---|
| 80 | break;
|
|---|
| 81 | }/* while() */
|
|---|
| 82 | return pifParent;
|
|---|
| 83 | }
|
|---|
| 84 | #endif
|
|---|
| 85 |
|
|---|
| 86 | /**
|
|---|
| 87 | Helper function which scans the array of parent interfaces and returns the info structure of the
|
|---|
| 88 | given method.
|
|---|
| 89 |
|
|---|
| 90 | \Param pif Pointer to an interface which parents should be scanned.
|
|---|
| 91 | \PARAM chrName Name of the method.
|
|---|
| 92 |
|
|---|
| 93 | \Returns If no info structure for a method with that name can be found NULL is returned otherwise a
|
|---|
| 94 | pointer to the METHOD structure..
|
|---|
| 95 | */
|
|---|
| 96 | PMETHOD findMethodInfoFromMethodName(PINTERFACE pif, gchar* chrName)
|
|---|
| 97 | {
|
|---|
| 98 | PMETHOD pm;
|
|---|
| 99 | PINTERFACE pifParent=pif;
|
|---|
| 100 | PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;
|
|---|
| 101 |
|
|---|
| 102 | if(!pParseInfo|| !pifParent)
|
|---|
| 103 | return NULL;
|
|---|
| 104 |
|
|---|
| 105 | while((pifParent=getParentInterface(pifParent))!=NULL)
|
|---|
| 106 | {
|
|---|
| 107 | int a;
|
|---|
| 108 | GPtrArray *pArray=pifParent->pMethodArray;
|
|---|
| 109 | gboolean fFound;
|
|---|
| 110 |
|
|---|
| 111 | fFound=FALSE;
|
|---|
| 112 | for(a=0;a<pArray->len && !fFound; a++){
|
|---|
| 113 | pm=(PMETHOD)g_ptr_array_index(pArray, a);
|
|---|
| 114 |
|
|---|
| 115 | if(!strcmp(pm->chrName, chrName))
|
|---|
| 116 | fFound=TRUE;
|
|---|
| 117 | }/* for() */
|
|---|
| 118 |
|
|---|
| 119 | if(fFound)
|
|---|
| 120 | break;
|
|---|
| 121 |
|
|---|
| 122 | pm=NULL;
|
|---|
| 123 | }/* while() */
|
|---|
| 124 | return pm;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | /**
|
|---|
| 128 | Helper function which scans the current interface and the array of parent interfaces and returns
|
|---|
| 129 | the info structure of the given method.
|
|---|
| 130 |
|
|---|
| 131 | \Param pif Pointer to an interface which is the start of the search.
|
|---|
| 132 | \PARAM chrName Name of the method.
|
|---|
| 133 |
|
|---|
| 134 | \Returns If no info structure for a method with that name can be found NULL is returned otherwise a
|
|---|
| 135 | pointer to the METHOD structure..
|
|---|
| 136 |
|
|---|
| 137 | */
|
|---|
| 138 | PMETHOD findMethodInfoFromMethodNameWithCurrent(PINTERFACE pif, gchar* chrName)
|
|---|
| 139 | {
|
|---|
| 140 | int a;
|
|---|
| 141 | GPtrArray *pArray=pif->pMethodArray;
|
|---|
| 142 | gboolean fFound;
|
|---|
| 143 | PMETHOD pm;
|
|---|
| 144 |
|
|---|
| 145 | fFound=FALSE;
|
|---|
| 146 | for(a=0; a<pArray->len && !fFound; a++){
|
|---|
| 147 | pm=(PMETHOD)g_ptr_array_index(pArray, a);
|
|---|
| 148 | if(!strcmp(pm->chrName, chrName))
|
|---|
| 149 | {
|
|---|
| 150 | fFound=TRUE;
|
|---|
| 151 | break;
|
|---|
| 152 | }
|
|---|
| 153 | }/* for() */
|
|---|
| 154 |
|
|---|
| 155 | if(fFound)
|
|---|
| 156 | return pm;
|
|---|
| 157 | else
|
|---|
| 158 | return findMethodInfoFromMethodName(pif, chrName);
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | /**
|
|---|
| 162 | Helper function which scans the array of known interfaces and returns the interface
|
|---|
| 163 | structure for the given name.
|
|---|
| 164 |
|
|---|
| 165 | \PARAM chrName Name of the interface.
|
|---|
| 166 | \Returns If no interface with that name can be found NULL is returned otherwise a
|
|---|
| 167 | pointer to the interface structure..
|
|---|
| 168 | */
|
|---|
| 169 | PINTERFACE findInterfaceFromName(gchar* chrName)
|
|---|
| 170 | {
|
|---|
| 171 | int a;
|
|---|
| 172 | PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;
|
|---|
| 173 |
|
|---|
| 174 | for(a=0;a<pParseInfo->pInterfaceArray->len;a++)
|
|---|
| 175 | {
|
|---|
| 176 | PINTERFACE pif=g_ptr_array_index(pParseInfo->pInterfaceArray, a);
|
|---|
| 177 | if(!strcmp(chrName, pif->chrName))
|
|---|
| 178 | return pif;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | return NULL;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 | PINTERFACE findInterfaceForMethod(PINTERFACE pStartInterface, gchar* chrMethodName)
|
|---|
| 186 | {
|
|---|
| 187 | int a;
|
|---|
| 188 |
|
|---|
| 189 | while(pStartInterface)
|
|---|
| 190 | {
|
|---|
| 191 | for(a=0;a<pStartInterface->pMethodArray->len;a++)
|
|---|
| 192 | {
|
|---|
| 193 | PMETHOD pm=(PMETHOD)g_ptr_array_index(pStartInterface->pMethodArray, a);
|
|---|
| 194 | if(!strcmp(pm->chrName, chrMethodName))
|
|---|
| 195 | return pStartInterface;
|
|---|
| 196 | }
|
|---|
| 197 | if(pStartInterface->chrParent)
|
|---|
| 198 | pStartInterface=findInterfaceFromName(pStartInterface->chrParent);
|
|---|
| 199 | else
|
|---|
| 200 | pStartInterface=NULL;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | return NULL;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 | /**
|
|---|
| 208 | Returns the interface structure (holding all the interface information) of the
|
|---|
| 209 | parent of an interface.
|
|---|
| 210 |
|
|---|
| 211 | \Param pif Pointer to an interface structure.
|
|---|
| 212 | \Returns The interface data structure of the parent interface or NULL if the
|
|---|
| 213 | interface has no parent.
|
|---|
| 214 |
|
|---|
| 215 | */
|
|---|
| 216 | PINTERFACE getParentInterface(PINTERFACE pif)
|
|---|
| 217 | {
|
|---|
| 218 | if(pif->chrParent==NULL)
|
|---|
| 219 | return NULL;
|
|---|
| 220 |
|
|---|
| 221 | return findInterfaceFromName(pif->chrParent);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | #if 0
|
|---|
| 225 | gboolean queryMessageReturnsAValue(PMETHOD pm)
|
|---|
| 226 | {
|
|---|
| 227 | if(pm->mpReturn.uiStar)
|
|---|
| 228 | return TRUE;
|
|---|
| 229 |
|
|---|
| 230 | if(!strcmp(pm->mpReturn.chrType, "void"))
|
|---|
| 231 | return FALSE;
|
|---|
| 232 |
|
|---|
| 233 | return TRUE;
|
|---|
| 234 | }
|
|---|
| 235 | #endif
|
|---|
| 236 |
|
|---|
| 237 | void cleanupAndExit(int iExitCode)
|
|---|
| 238 | {
|
|---|
| 239 |
|
|---|
| 240 | exit(iExitCode);
|
|---|
| 241 |
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | void exitIfNotMatchNext(GTokenType token, gchar* msg)
|
|---|
| 245 | {
|
|---|
| 246 | if(!matchNext(token))
|
|---|
| 247 | {
|
|---|
| 248 | getNextToken(); /* Make sure error references the correct token */ \
|
|---|
| 249 | g_scanner_unexp_token(gScanner,
|
|---|
| 250 | token,
|
|---|
| 251 | NULL, NULL, NULL,
|
|---|
| 252 | msg,
|
|---|
| 253 | TRUE); /* is_error */
|
|---|
| 254 | cleanupAndExit(1);
|
|---|
| 255 | }
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|