xref: /aoo41x/main/soltools/cpp/_mcrvalid.c (revision cdf0e10c)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 #include "cpp.h"
6 
7 /*
8 	Nlist *				pMacro;
9 	Token *				pTokenWhereMacroBecomesValid;
10 	struct macroValidator *
11 						pNext;
12 */
13 
14 void
15 mvl_init(MacroValidatorList	* out_pValidators)
16 {
17 	out_pValidators->pFirst = 0;
18 	out_pValidators->nextFreeIdentifier = 1;
19 }
20 
21 void
22 mvl_destruct(MacroValidatorList	* out_pValidators)
23 {
24 	MacroValidator * pV = out_pValidators->pFirst;
25 	MacroValidator * pDel;
26 	for ( pDel = out_pValidators->pFirst;
27 		  pDel != 0;
28 		  pDel = pV )
29 	{
30 		pV = pV->pNext;
31 
32 		pDel->pMacro->flag &= (~ISACTIVE);
33 		dofree(pDel);
34 	}
35 }
36 
37 
38 #define INVALID_TILL_ENDOFROW 32000
39 
40 /*	If in_pTokenWhereMacroBecomesValid == 0, the macro is at row end
41 	and therefore there does not exist any token, where the macro becomes
42 	valid again. It is revalidated, when the row was processed complete.
43 */
44 void
45 mvl_add( MacroValidatorList *	inout_pValidators,
46 		 Nlist *            	in_pMacro,
47 		 Token *				in_pTokenWhereMacroBecomesValid )
48 {
49 
50 	MacroValidator * pNew = new(MacroValidator);
51 	pNew->pMacro = in_pMacro;
52 
53 	if (in_pTokenWhereMacroBecomesValid == 0)
54 	{
55 		pNew->nTokenWhereMacroBecomesValid = INVALID_TILL_ENDOFROW;
56 	}
57 	else if (in_pTokenWhereMacroBecomesValid->identifier > 0)
58 	{
59 		pNew->nTokenWhereMacroBecomesValid = in_pTokenWhereMacroBecomesValid->identifier;
60 	}
61 	else
62 	{
63 		pNew->nTokenWhereMacroBecomesValid = inout_pValidators->nextFreeIdentifier;
64 		in_pTokenWhereMacroBecomesValid->identifier = inout_pValidators->nextFreeIdentifier;
65 		inout_pValidators->nextFreeIdentifier++;
66 	}
67 
68 	pNew->pNext = inout_pValidators->pFirst;
69 	inout_pValidators->pFirst = pNew;
70 }
71 
72 /*
73 void
74 mvl_move( MacroValidatorList * inout_pValidators,
75 		  int				   in_nSpace )
76 {
77 	MacroValidator * pV;
78 	for ( pV = inout_pValidators->pFirst;
79 		  pV != 0;
80 		  pV = pV->pNext )
81 	{
82 		pV->pTokenWhereMacroBecomesValid += in_nSpace;
83 	}
84 }
85 */
86 
87 void
88 mvl_check(	MacroValidatorList * inout_pValidators,
89 			Token *			     inout_pTokenToCheck)
90 {
91 	MacroValidator * pV;			/* Running pointer */
92 	MacroValidator * pCheckedOnes;  /* Here new list is built.  */
93 	pCheckedOnes = 0;
94 
95 	for ( pV = inout_pValidators->pFirst;
96 		  pV != 0;
97 		  pV = inout_pValidators->pFirst )
98 	{
99 		inout_pValidators->pFirst = pV->pNext;
100 
101 		if (pV->nTokenWhereMacroBecomesValid == inout_pTokenToCheck->identifier)
102 		{
103 			pV->pMacro->flag &= (~ISACTIVE);
104 			dofree(pV);
105 		}
106 		else
107 		{
108 			pV->pNext = pCheckedOnes;
109 			pCheckedOnes = pV;
110 		}
111 	}	/* end for  */
112 
113 	/* Assign new built list (too old ones were removed) to
114 	   original list:
115 	*/
116 	inout_pValidators->pFirst = pCheckedOnes;
117 }
118 
119 
120 void
121 tokenrow_zeroTokenIdentifiers(Tokenrow* trp)
122 {
123 	Token * tp;
124 	for (tp = trp->bp; tp < trp->lp; tp++)
125 	{
126 		tp->identifier = 0;
127 	}
128 }
129 
130