aboutsummaryrefslogtreecommitdiff
path: root/backendC/CleanCompilerSources/tcsupport_2.c
blob: 96d3e21057c1aa18e6f8fef15670407966e4701f (plain) (blame)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
	Version 1.2 21/01/1997

	Author:  Sjaak Smetsers
*/

#pragma options (!macsbug_names)

#include "compiledefines.h"
#include "types.t"
#include "system.h"
#include "settings.h"
#include "syntaxtr.t"
#include "comsupport.h"

#include "sizes.h"
#include "checker.h"
#include "checksupport.h"
#include "typeconv.h"
#include "tcsupport.h"
#include "scanner.h"
#include "comparser.h"
#include "buildtree.h"

BITVECT DetermineUniPropOfTypeCons (SymbDef typecons)
{
	if (typecons -> sdef_kind == TYPE || typecons -> sdef_kind == RECORDTYPE)
		return (typecons -> sdef_type) ? typecons -> sdef_type -> type_uniprop : ALLBITSSET;
	else
		return (typecons -> sdef_kind == TYPESYN) ? typecons -> sdef_syn_type -> syntype_uniprop : ALLBITSSET;
		
} /* DetermineUniPropOfTypeCons */

BITVECT DetermineConsVarsOfTypeCons (SymbDef typecons, ConsVarList * cons_vars)
{
	if (typecons -> sdef_kind == TYPE || typecons -> sdef_kind == RECORDTYPE)
	{	if (typecons -> sdef_type)
		{	* cons_vars = NULL;
			return typecons -> sdef_type -> type_consvars;
		}
		else
		{	* cons_vars = NULL;
			return ALLBITSCLEAR;
		}
	}
	else if (typecons -> sdef_kind == TYPESYN)
	{	 * cons_vars =  NULL;
		return typecons -> sdef_syn_type -> syn_consvars;
	}
	else
	{	* cons_vars = NULL;
		return ALLBITSCLEAR;
	}
		
} /* DetermineConsVarsOfTypeCons */

#define SubstitutedType(typeargs) ((typeargs)[-1])

void PrintNodeSymbol (Node node, int arg_nr, File file)
{
	Symbol rootsymb;
	
	switch (node -> node_kind)
	{
	case IfNode:
		switch (arg_nr)
		{
		case 1:	FPutS ("condition part of guard or if rule", file);
				return;
		case 2:	FPutS ("then part of guard or if rule", file);
				return;
		case 3:	FPutS ("else part of guard or if rule", file);
				return;
		default:	FPutS ("guard or if rule", file);
				return;
		}
		break;
	case SelectorNode:
		if (arg_nr == 1)
			FPutS ("argument of selection", file);
		else
			FPutS ("selection", file);
		return;
	case MatchNode:
		if (arg_nr == 1)
		{	FPutS ("rhs selection of", file);
			break;
		}
		else
		{	FPutS ("rhs selection", file);
			return;
		}
	case UpdateNode:
		FPutS ("update of record", file);
		break;
	case NodeIdNode:
		if (node -> node_node_id -> nid_ident != NULL)
		{	Ident id =  node -> node_node_id -> nid_ident;
			if (TestMark (node -> node_node_id, nid_mark2, NID_FIELD_NAME_MASK))
			{	SymbDef rec_symb = (SymbDef) id -> ident_environ;
			
				FPrintF (file, "field %s of record %s", id -> ident_name, rec_symb -> sdef_ident -> ident_name);
			}
			else
				FPutS (id  -> ident_name, file);
		}
		else if (node -> node_node_id -> nid_node)
			PrintNodeSymbol (node -> node_node_id -> nid_node, 0, file);
		return;
	default:
		break;
	}

	rootsymb = node -> node_symbol;
	
	if (rootsymb -> symb_kind == select_symb)
	{	if (arg_nr == 1)
		{	FPrintF (file, "%d-tuple selection of ", rootsymb -> symb_arity);
			PrintNodeSymbol (node -> node_arguments -> arg_node, 0, file);
		}
		else
			FPrintF (file, "selection of the %d-th argument of a %d-tuple ", node -> node_arity, rootsymb -> symb_arity);
	}
	else if (rootsymb -> symb_kind == apply_symb)				
	{	if (arg_nr == 1)
			PrintNodeSymbol (node -> node_arguments -> arg_node, 0, file);
		else
		{	Node argnode;
			for (arg_nr = 1, argnode = node -> node_arguments -> arg_node; 
				argnode -> node_kind == NormalNode && argnode -> node_symbol -> symb_kind == apply_symb;
				argnode = argnode -> node_arguments -> arg_node)
				arg_nr ++;
			PrintNodeSymbol (argnode, arg_nr, file);
		}
	}
	else if (rootsymb -> symb_kind == tuple_symb)
	{	int tup_arity = node -> node_arity;
		FPutS ("(_", file);
		for (tup_arity--; tup_arity > 0; tup_arity--)
			FPutS (",_", file);
		FPutC (')', file);
	}
	else
	{	if (arg_nr > 0)
			FPrintF (StdError, "argument %d of ", arg_nr);
		PrintSymbol (rootsymb, file);
	}

} /* PrintNodeSymbol */