1 //**************************************************************************
2 //**
3 //**	##   ##    ##    ##   ##   ####     ####   ###     ###
4 //**	##   ##  ##  ##  ##   ##  ##  ##   ##  ##  ####   ####
5 //**	 ## ##  ##    ##  ## ##  ##    ## ##    ## ## ## ## ##
6 //**	 ## ##  ########  ## ##  ##    ## ##    ## ##  ###  ##
7 //**	  ###   ##    ##   ###    ##  ##   ##  ##  ##       ##
8 //**	   #    ##    ##    #      ####     ####   ##       ##
9 //**
10 //**	$Id: vc_member.h 3833 2008-10-19 21:10:53Z dj_jl $
11 //**
12 //**	Copyright (C) 1999-2006 Jānis Legzdiņš
13 //**
14 //**	This program is free software; you can redistribute it and/or
15 //**  modify it under the terms of the GNU General Public License
16 //**  as published by the Free Software Foundation; either version 2
17 //**  of the License, or (at your option) any later version.
18 //**
19 //**	This program is distributed in the hope that it will be useful,
20 //**  but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 //**  GNU General Public License for more details.
23 //**
24 //**************************************************************************
25 
26 class VExpression;
27 class VStatement;
28 
29 #define ANY_PACKAGE				((VPackage*)-1)
30 #define ANY_MEMBER				255
31 
32 enum
33 {
34 	MEMBER_Package,
35 	MEMBER_Field,
36 	MEMBER_Property,
37 	MEMBER_Method,
38 	MEMBER_State,
39 	MEMBER_Const,
40 	MEMBER_Struct,
41 	MEMBER_Class,
42 
43 	//	A fake type for DECORATE class imports.
44 	MEMBER_DecorateClass,
45 };
46 
47 //==========================================================================
48 //
49 //	VMemberBase
50 //
51 //	The base class of all objects.
52 //
53 //==========================================================================
54 
55 class VMemberBase
56 {
57 public:
58 	//	Internal variables.
59 	vuint8			MemberType;
60 	vint32			MemberIndex;
61 	VName			Name;
62 	VMemberBase*	Outer;
63 	TLocation		Loc;
64 	VMemberBase*	HashNext;
65 
66 	static bool						GObjInitialised;
67 	static TArray<VMemberBase*>		GMembers;
68 	static VMemberBase*				GMembersHash[4096];
69 
70 	static TArray<VStr>				GPackagePath;
71 	static TArray<VPackage*>		GLoadedPackages;
72 	static TArray<VClass*>			GDecorateClassImports;
73 
74 	static VClass*					GClasses;	// Linked list of all classes.
75 
76 	//	Srtuctors.
77 	VMemberBase(vuint8, VName, VMemberBase*, TLocation);
78 	virtual ~VMemberBase();
79 
80 	//	Accessors.
GetName()81 	const char *GetName() const
82 	{
83 		return *Name;
84 	}
GetVName()85 	const VName GetVName() const
86 	{
87 		return Name;
88 	}
89 	VStr GetFullName() const;
90 	VPackage* GetPackage() const;
91 	bool IsIn(VMemberBase*) const;
92 
93 	virtual void Serialise(VStream&);
94 	virtual void PostLoad();
95 	virtual void Shutdown();
96 
97 	static void StaticInit();
98 	static void StaticExit();
99 	static void StaticAddPackagePath(const char*);
100 	static VPackage* StaticLoadPackage(VName, TLocation);
101 	static VMemberBase* StaticFindMember(VName, VMemberBase*, vuint8);
102 
103 	//FIXME This looks ugly.
104 	static VFieldType StaticFindType(VClass*, VName);
105 	static VClass* StaticFindClass(VName);
106 
107 	static void StaticSplitStateLabel(const VStr&, TArray<VName>&);
108 };
109 
GetTypeHash(VMemberBase * M)110 inline vuint32 GetTypeHash(VMemberBase* M)
111 {
112 	return M ? M->MemberIndex : 0;
113 }
114