xref: /aoo41x/main/soltools/cpp/_mcrvalid.c (revision 7ce20373)
1*7ce20373SAndrew Rist /**************************************************************
2*7ce20373SAndrew Rist  *
3*7ce20373SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*7ce20373SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*7ce20373SAndrew Rist  * distributed with this work for additional information
6*7ce20373SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*7ce20373SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*7ce20373SAndrew Rist  * "License"); you may not use this file except in compliance
9*7ce20373SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*7ce20373SAndrew Rist  *
11*7ce20373SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*7ce20373SAndrew Rist  *
13*7ce20373SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*7ce20373SAndrew Rist  * software distributed under the License is distributed on an
15*7ce20373SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*7ce20373SAndrew Rist  * KIND, either express or implied.  See the License for the
17*7ce20373SAndrew Rist  * specific language governing permissions and limitations
18*7ce20373SAndrew Rist  * under the License.
19*7ce20373SAndrew Rist  *
20*7ce20373SAndrew Rist  *************************************************************/
21*7ce20373SAndrew Rist 
22cdf0e10cSrcweir #include <stdio.h>
23cdf0e10cSrcweir #include <stdlib.h>
24cdf0e10cSrcweir #include <string.h>
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "cpp.h"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /*
29cdf0e10cSrcweir 	Nlist *				pMacro;
30cdf0e10cSrcweir 	Token *				pTokenWhereMacroBecomesValid;
31cdf0e10cSrcweir 	struct macroValidator *
32cdf0e10cSrcweir 						pNext;
33cdf0e10cSrcweir */
34cdf0e10cSrcweir 
35cdf0e10cSrcweir void
mvl_init(MacroValidatorList * out_pValidators)36cdf0e10cSrcweir mvl_init(MacroValidatorList	* out_pValidators)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	out_pValidators->pFirst = 0;
39cdf0e10cSrcweir 	out_pValidators->nextFreeIdentifier = 1;
40cdf0e10cSrcweir }
41cdf0e10cSrcweir 
42cdf0e10cSrcweir void
mvl_destruct(MacroValidatorList * out_pValidators)43cdf0e10cSrcweir mvl_destruct(MacroValidatorList	* out_pValidators)
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	MacroValidator * pV = out_pValidators->pFirst;
46cdf0e10cSrcweir 	MacroValidator * pDel;
47cdf0e10cSrcweir 	for ( pDel = out_pValidators->pFirst;
48cdf0e10cSrcweir 		  pDel != 0;
49cdf0e10cSrcweir 		  pDel = pV )
50cdf0e10cSrcweir 	{
51cdf0e10cSrcweir 		pV = pV->pNext;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 		pDel->pMacro->flag &= (~ISACTIVE);
54cdf0e10cSrcweir 		dofree(pDel);
55cdf0e10cSrcweir 	}
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #define INVALID_TILL_ENDOFROW 32000
60cdf0e10cSrcweir 
61cdf0e10cSrcweir /*	If in_pTokenWhereMacroBecomesValid == 0, the macro is at row end
62cdf0e10cSrcweir 	and therefore there does not exist any token, where the macro becomes
63cdf0e10cSrcweir 	valid again. It is revalidated, when the row was processed complete.
64cdf0e10cSrcweir */
65cdf0e10cSrcweir void
mvl_add(MacroValidatorList * inout_pValidators,Nlist * in_pMacro,Token * in_pTokenWhereMacroBecomesValid)66cdf0e10cSrcweir mvl_add( MacroValidatorList *	inout_pValidators,
67cdf0e10cSrcweir 		 Nlist *            	in_pMacro,
68cdf0e10cSrcweir 		 Token *				in_pTokenWhereMacroBecomesValid )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	MacroValidator * pNew = new(MacroValidator);
72cdf0e10cSrcweir 	pNew->pMacro = in_pMacro;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	if (in_pTokenWhereMacroBecomesValid == 0)
75cdf0e10cSrcweir 	{
76cdf0e10cSrcweir 		pNew->nTokenWhereMacroBecomesValid = INVALID_TILL_ENDOFROW;
77cdf0e10cSrcweir 	}
78cdf0e10cSrcweir 	else if (in_pTokenWhereMacroBecomesValid->identifier > 0)
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 		pNew->nTokenWhereMacroBecomesValid = in_pTokenWhereMacroBecomesValid->identifier;
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 	else
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 		pNew->nTokenWhereMacroBecomesValid = inout_pValidators->nextFreeIdentifier;
85cdf0e10cSrcweir 		in_pTokenWhereMacroBecomesValid->identifier = inout_pValidators->nextFreeIdentifier;
86cdf0e10cSrcweir 		inout_pValidators->nextFreeIdentifier++;
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	pNew->pNext = inout_pValidators->pFirst;
90cdf0e10cSrcweir 	inout_pValidators->pFirst = pNew;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir /*
94cdf0e10cSrcweir void
95cdf0e10cSrcweir mvl_move( MacroValidatorList * inout_pValidators,
96cdf0e10cSrcweir 		  int				   in_nSpace )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	MacroValidator * pV;
99cdf0e10cSrcweir 	for ( pV = inout_pValidators->pFirst;
100cdf0e10cSrcweir 		  pV != 0;
101cdf0e10cSrcweir 		  pV = pV->pNext )
102cdf0e10cSrcweir 	{
103cdf0e10cSrcweir 		pV->pTokenWhereMacroBecomesValid += in_nSpace;
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir }
106cdf0e10cSrcweir */
107cdf0e10cSrcweir 
108cdf0e10cSrcweir void
mvl_check(MacroValidatorList * inout_pValidators,Token * inout_pTokenToCheck)109cdf0e10cSrcweir mvl_check(	MacroValidatorList * inout_pValidators,
110cdf0e10cSrcweir 			Token *			     inout_pTokenToCheck)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	MacroValidator * pV;			/* Running pointer */
113cdf0e10cSrcweir 	MacroValidator * pCheckedOnes;  /* Here new list is built.  */
114cdf0e10cSrcweir 	pCheckedOnes = 0;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	for ( pV = inout_pValidators->pFirst;
117cdf0e10cSrcweir 		  pV != 0;
118cdf0e10cSrcweir 		  pV = inout_pValidators->pFirst )
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		inout_pValidators->pFirst = pV->pNext;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 		if (pV->nTokenWhereMacroBecomesValid == inout_pTokenToCheck->identifier)
123cdf0e10cSrcweir 		{
124cdf0e10cSrcweir 			pV->pMacro->flag &= (~ISACTIVE);
125cdf0e10cSrcweir 			dofree(pV);
126cdf0e10cSrcweir 		}
127cdf0e10cSrcweir 		else
128cdf0e10cSrcweir 		{
129cdf0e10cSrcweir 			pV->pNext = pCheckedOnes;
130cdf0e10cSrcweir 			pCheckedOnes = pV;
131cdf0e10cSrcweir 		}
132cdf0e10cSrcweir 	}	/* end for  */
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	/* Assign new built list (too old ones were removed) to
135cdf0e10cSrcweir 	   original list:
136cdf0e10cSrcweir 	*/
137cdf0e10cSrcweir 	inout_pValidators->pFirst = pCheckedOnes;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 
141cdf0e10cSrcweir void
tokenrow_zeroTokenIdentifiers(Tokenrow * trp)142cdf0e10cSrcweir tokenrow_zeroTokenIdentifiers(Tokenrow* trp)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	Token * tp;
145cdf0e10cSrcweir 	for (tp = trp->bp; tp < trp->lp; tp++)
146cdf0e10cSrcweir 	{
147cdf0e10cSrcweir 		tp->identifier = 0;
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151