@@ -36,6 +36,7 @@ void globalInstall(Tnode *root)
3636{
3737 struct Gsymbol * gnode ;
3838 ArgStruct * arg ;
39+ int typ ;
3940
4041 if (root == NULL )
4142 return ;
@@ -58,7 +59,7 @@ void globalInstall(Tnode *root)
5859
5960 if (gnode != NULL )
6061 {
61- if (root -> TYPE != gnode -> TYPE )
62+ if (decnode -> TYPE != gnode -> TYPE )
6263 printf ("\nSIL:%d: Error: conflicting types for '%s'" ,root -> LINE ,root -> NAME );
6364 else
6465 printf ("\nSIL:%d: Error: redeclaration of '%s'" ,root -> LINE ,root -> NAME );
@@ -69,7 +70,12 @@ void globalInstall(Tnode *root)
6970 globalInstall (root -> ArgList );
7071
7172 if (gnode == NULL )
73+ {
74+ if ((root -> NODETYPE == ARRAYDECL ) && (root -> VALUE == 0 ))
75+ printf ("\nSIL:%d: Warning: size of array '%s' is ZERO" ,root -> LINE ,root -> NAME );
76+
7277 Ginstall (root -> NAME ,decnode -> TYPE ,root -> VALUE ,Arghead );
78+ }
7379
7480 break ;
7581
@@ -78,13 +84,29 @@ void globalInstall(Tnode *root)
7884 globalInstall (root -> Ptr2 );
7985 break ;
8086
81- case IDALIASARG :
87+ case IDADDRARG : typ = returnAddrType (argnode -> TYPE );
88+
89+ arg = argLookup (root -> NAME ,Arghead );
90+
91+ if (arg != NULL )
92+ {
93+ if (typ != arg -> TYPE )
94+ printf ("\nSIL:%d: Error: conflicting types for '%s'" ,root -> LINE ,root -> NAME );
95+ else
96+ printf ("\nSIL:%d: Error: redefinition of parameter '%s'" ,root -> LINE ,root -> NAME );
97+
98+ error ++ ;
99+ }
100+
101+ else argInstall (root -> NAME ,typ );
102+
103+ break ;
82104
83105 case IDARG : arg = argLookup (root -> NAME ,Arghead );
84106
85107 if (arg != NULL )
86108 {
87- if (root -> TYPE != arg -> TYPE )
109+ if (argnode -> TYPE != arg -> TYPE )
88110 printf ("\nSIL:%d: Error: conflicting types for '%s'" ,root -> LINE ,root -> NAME );
89111 else
90112 printf ("\nSIL:%d: Error: redefinition of parameter '%s'" ,root -> LINE ,root -> NAME );
@@ -167,7 +189,7 @@ struct Gsymbol *Glookup(char *NAME)
167189/* Install an identifier in the global symbol table
168190 */
169191void Ginstall (char * NAME ,int TYPE ,int SIZE ,ArgStruct * ARGLIST )
170- {
192+ {
171193 int i ;
172194 struct Gsymbol * Gnode = malloc (sizeof (struct Gsymbol ));
173195
@@ -294,6 +316,74 @@ void Gallocate()
294316 }
295317}
296318
319+
320+ /* Returns appropriate type for identifier addresses
321+ */
322+ int returnAddrType (int TYPE )
323+ {
324+ if (TYPE == INTGR )
325+ return INTGRALIAS ;
326+
327+ else if (TYPE == BOOL )
328+ idtype = BOOLALIAS ;
329+
330+ else return ;
331+ }
332+
333+
334+ /* Lookup an AST function node in the function nodes list (having head *Funchead)
335+ */
336+ Tnode * funcLookup (char * NAME )
337+ {
338+ FuncStruct * ptr = Funchead ;
339+
340+ while (ptr )
341+ {
342+ if (!strcmp (ptr -> FUNCNODE -> NAME ,NAME ))
343+ return ptr -> FUNCNODE ;
344+
345+ ptr = ptr -> NEXT ;
346+ }
347+
348+ return NULL ;
349+ }
350+
351+
352+ /* Add an AST function node to the function nodes list (having head *Funclist)
353+ */
354+ void addToFuncList (Tnode * root )
355+ {
356+ Tnode * func ;
357+
358+ func = funcLookup (root -> NAME );
359+
360+ if (func != NULL )
361+ {
362+ if (func -> TYPE != root -> Ptr1 -> TYPE )
363+ printf ("\nSIL:%d: Error: conflicting types for function '%s'" ,root -> LINE ,root -> NAME );
364+ else
365+ printf ("\nSIL:%d: Error: redefinition of function '%s'" ,root -> LINE ,root -> NAME );
366+
367+ error ++ ;
368+ }
369+
370+ else funcInstall (root );
371+ }
372+
373+
374+ /* Install AST function node in function nodes list (having head *Funclist)
375+ */
376+ void funcInstall (Tnode * func )
377+ {
378+ FuncStruct * Node = malloc (sizeof (FuncStruct ));
379+
380+ Node -> FUNCNODE = func ;
381+
382+ Node -> NEXT = Funchead ;
383+ Funchead = Node ;
384+ }
385+
386+
297387int getPositiveLoc ()
298388{
299389 ++ locpos ;
0 commit comments