checksupport.c 3.79 KB
Newer Older
clean's avatar
clean committed
1

2
#include "compiledefines.h"
clean's avatar
clean committed
3 4 5 6 7 8 9 10 11 12 13 14 15
#include "types.t"
#include "syntaxtr.t"
#include "comsupport.h"
#include "checksupport.h"
#include "settings.h"
#include "buildtree.h"
#include "checker.h"
#include <ctype.h>

char *ConvertSymbolKindToString (SymbKind skind)
{
	switch (skind)
	{
16 17 18 19 20 21 22 23 24 25 26 27
		case int_type: 		return "Int";
		case bool_type:		return "Bool";
		case char_type:		return "Char";
		case real_type:		return "Real";
		case file_type:		return "File";
		case array_type:		return "{ }";
		case strict_array_type:	return "{ ! }";
		case unboxed_array_type:return "{ # }";
		case world_type:	return "World";
		case procid_type:	return "ProcId";
		case redid_type:	return "RedId";
		case fun_type:		return "=>";
28 29
		case list_type:		return "List";
		case tuple_type:	return "Tuple";
30
		case dynamic_type:	return "Dynamic";
31
		default:			return "Erroneous";
clean's avatar
clean committed
32 33 34 35
	}

} /* ConvertSymbolKindToString */

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
static int string_and_string_begin_equal (char *s1,char *s2_begin,char *s2_passed_end)
{
	char c,*s2;
	
	s2=s2_begin;
	do {
		c=*s1++;
		if (c=='\0')
			return s2==s2_passed_end;
		if (s2>=s2_passed_end)
			return 0;
	} while (*s2++ == c);

	return 0;
}
clean's avatar
clean committed
51

52 53
static char *print_compiler_generated_function_name (char *name, char *name_end, unsigned line_nr, File file)
{
54
	char *parsed_digits;
55 56 57

	FPutS (name,file);
	
58
	parsed_digits=NULL;
59 60 61 62 63 64 65
	if (name_end[0]==';' && isdigit (name_end[1])){
		char *s;
		
		s=name_end+2;
		while (isdigit (*s))
			++s;
		if (*s==';')
66
			parsed_digits=s;
67 68 69 70
	}
	
	if (line_nr>0){
		FPrintF (file,"[line: %u]", line_nr);
71 72
		if (parsed_digits)
			name_end=parsed_digits;
73
	} else
74
		if (parsed_digits){
75 76 77
			char *d_p;

			FPutS ("[line:",file);
78
			for (d_p=name_end+1; d_p<parsed_digits; ++d_p)
79 80 81
				FPutC (*d_p,file);
			FPutC (']',file);

82
			name_end=parsed_digits;
83 84 85 86 87 88 89
		}
	FPutS (name_end,file);

	return name_end+strlen (name_end);
}

static char *PrintName (char *name, char *name_end, unsigned line_nr, File file)
clean's avatar
clean committed
90
{
91 92 93 94 95 96 97 98 99 100
	if (*name=='\\' && name+1==name_end)
		return print_compiler_generated_function_name ("<lambda>",name_end,line_nr,file);

	if (*name == '_'){
		char *name_tail;

		if (string_and_string_begin_equal ("c",name+1,name_end))
			return print_compiler_generated_function_name ("<case>",name_end,line_nr,file);
		else if (string_and_string_begin_equal ("if",name+1,name_end))
			return print_compiler_generated_function_name ("<if>",name_end,line_nr,file);
clean's avatar
clean committed
101 102 103 104 105
	
		for (name_tail = name + 1; name_tail != name_end; name_tail++)
			if (isdigit (*name_tail))
				break;

106
		if (string_and_string_begin_equal (kCasePrefix,name,name_tail))
clean's avatar
clean committed
107
			FPutS ("<case expression>", file);
108
		else if (string_and_string_begin_equal (kLambdaPrefix,name,name_tail))
clean's avatar
clean committed
109
			FPutS ("<lambda expression>", file);
110
		else if (string_and_string_begin_equal (kListGeneratorPrefix,name,name_tail))
clean's avatar
clean committed
111
			FPutS ("<list comprehension>", file);
112
		else if (string_and_string_begin_equal (kArrayGeneratorPrefix,name,name_tail))
clean's avatar
clean committed
113
			FPutS ("<array comprehension>", file);
114 115
		else {
			FPutS (name, file);
116 117
			while (*name_end!='\0')
				++name_end;
118
			return name_end;
clean's avatar
clean committed
119 120
		}
		FPrintF (file, " [line: %u]", line_nr);
121 122
		return name_end;
	} else {
123 124 125
		for (; name!=name_end; name++)
			FPutC (*name, file);

126
		return name_end;
clean's avatar
clean committed
127
	}
128
}
clean's avatar
clean committed
129

130
void PrintSymbolOfIdent (char *name, unsigned line_nr, File file)
clean's avatar
clean committed
131
{
132
	char *next_char;
clean's avatar
clean committed
133

134 135 136
	for (next_char=name; *next_char!=';' && *next_char!='\0'; ++next_char)
		;

137
	next_char = PrintName (name, next_char, line_nr, file);
clean's avatar
clean committed
138

139 140
	if (*next_char == ';'){
		++next_char;
clean's avatar
clean committed
141
	
142 143
		if (isdigit (*next_char)){
			char *end_name;
clean's avatar
clean committed
144
		
145
			for (end_name = next_char + 1; *end_name!=';' && *end_name!='\0'; end_name++)
clean's avatar
clean committed
146 147
				 ;
			
148 149 150
			if (line_nr > 0){
				FPrintF (file, " [line: %u]", line_nr);
			} else {
151
				FPutC (';', file);
clean's avatar
clean committed
152 153 154
				PrintName (next_char, end_name, line_nr, file);
			}
			
155 156 157
			if (*end_name == '\0')
				return;
			next_char = end_name;
158
		} else
159
			FPutC (';', file);
160 161

		FPutS (next_char, file);
clean's avatar
clean committed
162 163
	}
}