source: trunk/idl-compiler/c/util.c@ 389

Last change on this file since 389 was 326, checked in by cinc, 17 years ago

Portability patches for Windows, Linux, Darwin by Bird.

File size: 5.1 KB
Line 
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
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
46extern GScanner *gScanner;
47
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 */
58PINTERFACE 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
85/**
86 Helper function which scans the array of parent interfaces and returns the info structure of the
87 given method.
88
89 \Param pif Pointer to an interface which parents should be scanned.
90 \PARAM chrName Name of the method.
91
92 \Returns If no info structure for a method with that name can be found NULL is returned otherwise a
93 pointer to the METHOD structure..
94 */
95PMETHOD findMethodInfoFromMethodName(PINTERFACE pif, gchar* chrName)
96{
97 PMETHOD pm;
98 PINTERFACE pifParent=pif;
99 PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;
100
101 if(!pParseInfo|| !pifParent)
102 return NULL;
103
104 while((pifParent=getParentInterface(pifParent))!=NULL)
105 {
106 int a;
107 GPtrArray *pArray=pifParent->pMethodArray;
108 gboolean fFound;
109
110 fFound=FALSE;
111 for(a=0;a<pArray->len && !fFound; a++){
112 pm=(PMETHOD)g_ptr_array_index(pArray, a);
113
114 if(!strcmp(pm->chrName, chrName))
115 fFound=TRUE;
116 }/* for() */
117
118 if(fFound)
119 break;
120
121 pm=NULL;
122 }/* while() */
123 return pm;
124}
125
126/**
127 Helper function which scans the array of known interfaces and returns the interface
128 structure for the given name.
129
130 \PARAM chrName Name of the interface.
131 \Returns If no interface with that name can be found NULL is returned otherwise a
132 pointer to the interface structure..
133 */
134PINTERFACE findInterfaceFromName(gchar* chrName)
135{
136 int a;
137 PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;
138
139 for(a=0;a<pParseInfo->pInterfaceArray->len;a++)
140 {
141 PINTERFACE pif=g_ptr_array_index(pParseInfo->pInterfaceArray, a);
142 if(!strcmp(chrName, pif->chrName))
143 return pif;
144 }
145
146 return NULL;
147}
148
149
150/**
151 Returns the interface structure (holding all the interface information) of the
152 parent of an interface.
153
154 \Param pif Pointer to an interface structure.
155 \Returns The interface data structure of the parent interface or NULL if the
156 interface has no parent.
157
158 */
159PINTERFACE getParentInterface(PINTERFACE pif)
160{
161 if(pif->chrParent==NULL)
162 return NULL;
163
164 return findInterfaceFromName(pif->chrParent);
165}
166
167gboolean queryMessageReturnsAValue(PMETHOD pm)
168{
169 if(pm->mpReturn.uiStar)
170 return TRUE;
171
172 if(!strcmp(pm->mpReturn.chrType, "void"))
173 return FALSE;
174
175 return TRUE;
176}
177
Note: See TracBrowser for help on using the repository browser.