File: allknown.cpp

package info (click to toggle)
sludge 2.2.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,852 kB
  • sloc: cpp: 32,432; sh: 1,237; makefile: 634; xml: 284
file content (60 lines) | stat: -rw-r--r-- 2,673 bytes parent folder | download | duplicates (7)
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
#include "messbox.h"
#include "splitter.hpp"

extern stringArray * functionNames;
extern stringArray * builtInFunc;
extern stringArray * typeDefFrom;
extern stringArray * objectTypeNames;
extern stringArray * allKnownFlags;
stringArray * * globalVarsP;

bool checkNotKnown (const char * thisName, const char * filename) {
	if (findElement (functionNames, thisName) != -1) return addComment (ERRORTYPE_PROJECTERROR, "Already the name of a function", thisName, filename, 0);
	if (findElement (objectTypeNames, thisName) != -1) return addComment (ERRORTYPE_PROJECTERROR, "Already the name of an object type", thisName, filename, 0);
	if (findElement (builtInFunc, thisName) != -1) return addComment (ERRORTYPE_PROJECTERROR, "Can't overload built-in functions", thisName, filename, 0);
	if (findElement (typeDefFrom, thisName) != -1) return addComment (ERRORTYPE_PROJECTERROR, "Already the name of a typedef", thisName, filename, 0);
	if (findElement (* globalVarsP, thisName) != -1) return addComment (ERRORTYPE_PROJECTERROR, "Already the name of a global variable", thisName, filename, 0);
	if (findElement (allKnownFlags, thisName) != -1) return addComment (ERRORTYPE_PROJECTERROR, "Already the name of an object flag", thisName, filename, 0);
	return true;
}

bool checkNotKnown2 (const char * thisName, const char * filename) {
//	if (findElement (functionNames, thisName) != -1) return addComment ("Already the name of a function", thisName);
//	if (findElement (objectTypeNames, thisName) != -1) return addComment ("Already the name of an object type", thisName);
	if (findElement (builtInFunc, thisName) != -1) return addComment (ERRORTYPE_PROJECTERROR, "Can't overload built-in functions", thisName, filename, 0);
	if (findElement (typeDefFrom, thisName) != -1) return addComment (ERRORTYPE_PROJECTERROR, "Already the name of a typedef", thisName, filename, 0);
//	if (findElement (* globalVarsP, thisName) != -1) return addComment ("Already the name of a global variable", thisName);
	return true;
}

void setGlobPointer (stringArray * * g) {
	globalVarsP = g;
}

bool checkValidName (const char * thisName, const char * error, const char * filename)
{
	if (thisName[0])
	{
		if ((thisName[0] >= 'a' && thisName[0] <= 'z') ||
			(thisName[0] >= 'A' && thisName[0] <= 'Z') ||
			(thisName[0] == '_'))
		{
			for (int i = 1;; i ++)
			{
				if (! thisName[i])
					return true;

				if ((thisName[i] < 'a' || thisName[i] > 'z') &&
					(thisName[i] < 'A' || thisName[i] > 'Z') &&
					(thisName[i] < '0' || thisName[i] > '9') &&
					(thisName[i] != '_'))
					break;
			}
		}
	}
	
	addComment (ERRORTYPE_PROJECTERROR, error, thisName, filename, 0);
	return false;
}