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

Last change on this file since 292 was 292, checked in by cinc, 18 years ago

Created C file emitter. Some fixes.

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#include <os2.h>
35#include <stdlib.h>
36#include <string.h>
37
38#include <glib.h>
39#include <glib/gprintf.h>
40
41#define INCL_FILE
42#include "parser.h"
43
44extern GScanner *gScanner;
45
46/**
47 Helper function which scans the array of parent interfaces and returns the structure of the
48 interface which introduced the given method.
49
50 \Param pif Pointer to an interface which parents should be scanned.
51 \PARAM chrName Name of the method.
52
53 \Returns If no interface with a method with that name can be found NULL is returned otherwise a
54 pointer to the interface structure..
55 */
56PINTERFACE findInterfaceFromMethodName(PINTERFACE pif, gchar* chrName)
57{
58 PINTERFACE pifParent=pif;
59 PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;
60
61 if(!pParseInfo|| !pifParent)
62 return NULL;
63
64 while((pifParent=getParentInterface(pifParent))!=NULLHANDLE)
65 {
66 int a;
67 GPtrArray *pArray=pifParent->pMethodArray;
68 gboolean fFound=FALSE;
69
70 for(a=0;a<pArray->len && !fFound; a++){
71 PMETHOD pm=(PMETHOD)g_ptr_array_index(pArray, a);
72
73 if(!strcmp(pm->chrName, chrName))
74 fFound=TRUE;
75 }/* for() */
76
77 if(fFound)
78 break;
79 }/* while() */
80 return pifParent;
81}
82
83/**
84 Helper function which scans the array of parent interfaces and returns the info structure of the
85 given method.
86
87 \Param pif Pointer to an interface which parents should be scanned.
88 \PARAM chrName Name of the method.
89
90 \Returns If no info structure for a method with that name can be found NULL is returned otherwise a
91 pointer to the METHOD structure..
92 */
93PMETHOD findMethodInfoFromMethodName(PINTERFACE pif, gchar* chrName)
94{
95 PMETHOD pm;
96 PINTERFACE pifParent=pif;
97 PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;
98
99 if(!pParseInfo|| !pifParent)
100 return NULL;
101
102 while((pifParent=getParentInterface(pifParent))!=NULLHANDLE)
103 {
104 int a;
105 GPtrArray *pArray=pifParent->pMethodArray;
106 gboolean fFound;
107
108 fFound=FALSE;
109 for(a=0;a<pArray->len && !fFound; a++){
110 pm=(PMETHOD)g_ptr_array_index(pArray, a);
111
112 if(!strcmp(pm->chrName, chrName))
113 fFound=TRUE;
114 }/* for() */
115
116 if(fFound)
117 break;
118
119 pm=NULL;
120 }/* while() */
121 return pm;
122}
123
124/**
125 Helper function which scans the array of known interfaces and returns the interface
126 structure for the given name.
127
128 \PARAM chrName Name of the interface.
129 \Returns If no interface with that name can be found NULL is returned otherwise a
130 pointer to the interface structure..
131 */
132PINTERFACE findInterfaceFromName(gchar* chrName)
133{
134 int a;
135 PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;
136
137 for(a=0;a<pParseInfo->pInterfaceArray->len;a++)
138 {
139 PINTERFACE pif=g_ptr_array_index(pParseInfo->pInterfaceArray, a);
140 if(!strcmp(chrName, pif->chrName))
141 return pif;
142 }
143
144 return NULL;
145}
146
147
148/**
149 Returns the interface structure (holding all the interface information) of the
150 parent of an interface.
151
152 \Param pif Pointer to an interface structure.
153 \Returns The interface data structure of the parent interface or NULL if the
154 interface has no parent.
155
156 */
157PINTERFACE getParentInterface(PINTERFACE pif)
158{
159 if(pif->chrParent==NULL)
160 return NULL;
161
162 return findInterfaceFromName(pif->chrParent);
163}
164
165gboolean queryMessageReturnsAValue(PMETHOD pm)
166{
167 if(pm->mpReturn.uiStar)
168 return TRUE;
169
170 if(!strcmp(pm->mpReturn.chrType, "void"))
171 return FALSE;
172
173 return TRUE;
174}
175
Note: See TracBrowser for help on using the repository browser.