1 /***************************************
4 C Cross Referencing & Documentation tool. Version 1.5f.
6 Collects the variable definition stuff.
7 ******************/ /******************
8 Written by Andrew M. Bishop
10 This file Copyright 1995,96,97,99,2004 Andrew M. Bishop
11 It may be distributed under the GNU Public License, version 2, or
12 any higher version. See section COPYING of the GNU Public license
13 for conditions under which this file may be redistributed.
14 ***************************************/
16 /*+ Control the output of debugging information from this file. +*/
28 /*+ The file that is currently being documented. +*/
31 /*+ When in a header file make a note of which one for the included variables. +*/
34 /*+ A list of the variables found at each level of the scope. +*/
35 static StringList2
*variable
;
37 /*+ The number of levels of scope depth allocated. +*/
38 static int max_scope
=0;
40 /*+ The current scope depth. +*/
41 static int cur_scope
=-1;
44 static Variable
NewVariableType(char *name
,char *type
);
47 /*++++++++++++++++++++++++++++++++++++++
48 Function that is called when a variable definition is seen.
50 char* name The name of the variable.
52 char* type The type of the variable.
54 int scope The scope of variable that has been seen.
55 ++++++++++++++++++++++++++++++++++++++*/
57 void SeenVariableDefinition(char* name
,char* type
,int scope
)
63 printf("#Var.c# Variable definition for '%s'\n",name
);
66 for(var
=CurFile
->variables
;var
;var
=var
->next
)
67 if(!strcmp(var
->name
,name
))
71 if(!in_header
&& var
->scope
&EXTERN_H
)
75 var
->comment
=MallocString(GetCurrentComment());
76 var
->lineno
=parse_line
;
83 var
=NewVariableType(name
,type
);
85 var
->comment
=MallocString(GetCurrentComment());
88 var
->lineno
=parse_line
;
90 if(in_header
&& !(scope
&EXTERN_H
))
91 var
->incfrom
=MallocString(parse_file
);
93 AddToLinkedList(CurFile
->variables
,Variable
,var
);
97 /*++++++++++++++++++++++++++++++++++++++
98 Called when a new scope is entered.
99 ++++++++++++++++++++++++++++++++++++++*/
106 printf("#Var.c# Scope ++ (%2d)\n",cur_scope
);
109 if(cur_scope
>=max_scope
)
112 variable
=Malloc(16*sizeof(StringList2
));
114 variable
=Realloc(variable
,(max_scope
+16)*sizeof(StringList2
));
118 variable
[cur_scope
]=NewStringList2();
122 /*++++++++++++++++++++++++++++++++++++++
123 Called when an old scope is exited.
124 ++++++++++++++++++++++++++++++++++++++*/
129 printf("#Var.c# Scope -- (%2d)\n",cur_scope
);
132 DeleteStringList2(variable
[cur_scope
]);
138 /*++++++++++++++++++++++++++++++++++++++
139 Add a variable to the list of known variables.
141 char* name The name of the variable.
142 ++++++++++++++++++++++++++++++++++++++*/
144 void SeenScopeVariable(char* name
)
147 printf("#Var.c# Scope Variable depth %2d '%s'\n",cur_scope
,name
);
150 AddToStringList2(variable
[cur_scope
],name
,NULL
,0,0);
154 /*++++++++++++++++++++++++++++++++++++++
155 Check through the scope variables to look for the named one.
157 int IsAScopeVariable Returns 1 if the name does refer to a variable that is scoped.
159 char* name The name of the variable to search for.
160 ++++++++++++++++++++++++++++++++++++++*/
162 int IsAScopeVariable(char* name
)
167 printf("#Var.c# Lookup variable '%s'\n",name
);
170 for(scope
=cur_scope
;scope
>=0;scope
--)
171 for(i
=0;i
<variable
[scope
]->n
;i
++)
172 if(!strcmp(variable
[scope
]->s1
[i
],name
))
179 /*++++++++++++++++++++++++++++++++++++++
180 Tidy up all of the local variables in case of a problem and abnormal parser termination.
181 ++++++++++++++++++++++++++++++++++++++*/
183 void ResetVariableAnalyser(void)
187 DeleteStringList2(variable
[cur_scope
]);
191 if(variable
) Free(variable
);
199 /*++++++++++++++++++++++++++++++++++++++
200 Create a new variable type.
202 Variable NewVariableType Returns a new Variable type.
204 char *name The name of the variable.
206 char *type The type of the variable.
207 ++++++++++++++++++++++++++++++++++++++*/
209 static Variable
NewVariableType(char *name
,char *type
)
211 Variable var
=(Variable
)Calloc(1,sizeof(struct _Variable
)); /* clear unused pointers */
213 var
->name
=MallocString(name
);
214 var
->type
=MallocString(type
);
215 var
->visible
=NewStringList2();
216 var
->used
=NewStringList2();
222 /*++++++++++++++++++++++++++++++++++++++
223 Delete the specified Variable type.
225 Variable var The Variable type to be deleted.
226 ++++++++++++++++++++++++++++++++++++++*/
228 void DeleteVariableType(Variable var
)
230 if(var
->comment
) Free(var
->comment
);
231 if(var
->name
) Free(var
->name
);
232 if(var
->type
) Free(var
->type
);
233 if(var
->defined
) Free(var
->defined
);
234 if(var
->incfrom
) Free(var
->incfrom
);
235 if(var
->visible
) DeleteStringList2(var
->visible
);
236 if(var
->used
) DeleteStringList2(var
->used
);