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