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