File: GdlTablePass.cpp

package info (click to toggle)
grcompiler 4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,076 kB
  • ctags: 5,163
  • sloc: cpp: 45,565; sh: 4,451; ansic: 4,377; makefile: 185; xml: 175; perl: 127
file content (131 lines) | stat: -rw-r--r-- 4,672 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.

Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.

File: GdlTablePass.cpp
Responsibility: Sharon Correll
Last reviewed: Not yet.

Description:
    Implements the classes corresponding to the tables of rules and their passes.
-------------------------------------------------------------------------------*//*:End Ignore*/

/***********************************************************************************************
	Include files
***********************************************************************************************/
#include "main.h"

#ifdef _MSC_VER
#pragma hdrstop
#endif
#undef THIS_FILE
DEFINE_THIS_FILE

/***********************************************************************************************
	Forward declarations
***********************************************************************************************/

/***********************************************************************************************
	Local Constants and static variables
***********************************************************************************************/

/***********************************************************************************************
	Methods: Post-parser
***********************************************************************************************/

/*----------------------------------------------------------------------------------------------
    Return the pass with the given number; create it if it does not exist. Pass 0 is the
	special unnumbered pass, for tables with only one pass.
----------------------------------------------------------------------------------------------*/
GdlPass* GdlRuleTable::GetPass(GrpLineAndFile & lnf, int ipassNumber,
	int nMaxRuleLoop, int nMaxBackup)
{
	char rgch[20];
	itoa(ipassNumber, rgch, 10);

	if (ipassNumber < 0)
	{
		g_errorList.AddError(3150, NULL,
			"Invalid pass number",
			lnf);
		return NULL;
	}

	while (ipassNumber >= signed(m_vppass.size()))
		m_vppass.push_back(NULL);

	if (m_vppass[ipassNumber] == NULL)
	{
		m_vppass[ipassNumber] = new GdlPass(ipassNumber, nMaxRuleLoop, nMaxBackup);
		m_vppass[ipassNumber]->SetLineAndFile(lnf);
	}

	if (m_vppass[ipassNumber]->MaxRuleLoop() != nMaxRuleLoop && m_vppass[ipassNumber]->HasRules())
	{
		int nMax = max(m_vppass[ipassNumber]->MaxRuleLoop(), nMaxRuleLoop);
		char rgchMax[20];
		itoa(nMax, rgchMax, 10);
		g_errorList.AddWarning(3527, NULL,
			"Conflicting MaxRuleLoop values for pass ", rgch, "; maxiumum value, ", rgchMax, ", will be used",
			lnf);
		m_vppass[ipassNumber]->SetMaxRuleLoop(nMax);
	}
	if (m_vppass[ipassNumber]->MaxBackup() != nMaxBackup && m_vppass[ipassNumber]->HasRules())
	{
		int nMax = max(m_vppass[ipassNumber]->MaxBackup(), nMaxBackup);
		char rgchMax[20];
		itoa(nMax, rgchMax, 10);
		g_errorList.AddWarning(3528, NULL,
			"Conflicting MaxBackup values for pass ", rgch, "; maxiumum value, ", rgchMax, ", will be used",
			lnf);
		m_vppass[ipassNumber]->SetMaxBackup(nMax);
	}

	return m_vppass[ipassNumber];
}


/*----------------------------------------------------------------------------------------------
	Destructor.
----------------------------------------------------------------------------------------------*/
GdlPass::~GdlPass()
{
	size_t i;
	for (i = 0; i < m_vprule.size(); ++i)
		delete m_vprule[i];

	for (i = 0; i < m_vpexpConstraints.size(); ++i)
		delete m_vpexpConstraints[i];

	if (m_pfsm)
		delete m_pfsm;

	ClearFsmWorkSpace();
}

/*----------------------------------------------------------------------------------------------
	Clear the data structures that are used to manage the stuff for FSM generation.
----------------------------------------------------------------------------------------------*/
void GdlPass::ClearFsmWorkSpace()
{
	//	Delete all the machine-class lists in the hash map.
	for (std::map<int, MachineClassList>::iterator hmit = m_hmMachineClassMap.begin();
		hmit != m_hmMachineClassMap.end();
		++hmit)
	{
		delete hmit->second;	// vector containing a group of machine classes with the same key;
								// notice that we store a pointer to the vector which is separately
								// allocated, not the vector itself, due to the limitations of the
								// previous HashMap implementation.
	}
	m_hmMachineClassMap.clear();

	//	Delete all the FsmMachineClasses and clear the master list.
	for (size_t i = 0; i < m_vpfsmc.size(); i++)
		delete m_vpfsmc[i];
	m_vpfsmc.clear();
}