summaryrefslogtreecommitdiff
path: root/ZAPD/Declaration.h
blob: 68070ff00ec04809dd832e1af841aef9f2c8d838 (plain)
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
#pragma once

#include <string>
#include <vector>
#include <cstdint>

// TODO: should we drop the `_t` suffix because of UNIX compliance?
typedef uint32_t segptr_t;
typedef uint32_t offset_t;

#define SEGMENTED_NULL ((segptr_t)0)

enum class DeclarationAlignment
{
	Align4,
	Align8
};

enum class StaticConfig
{
	Off,
	Global,
	On
};

class Declaration
{
public:
	offset_t address;
	DeclarationAlignment alignment;
	size_t size;
	std::string preText;
	std::string text;
	std::string rightText;
	std::string postText;
	std::string preComment;
	std::string postComment;
	std::string varType;
	std::string varName;
	std::string defines = "";  // Defines to be included in the header
	std::string includePath;

	bool isExternal = false;
	bool isArray = false;
	bool forceArrayCnt = false;
	size_t arrayItemCnt = 0;
	std::string arrayItemCntStr = ""; // Can be used to put a specific string inside an array declaration's brackets
	std::vector<segptr_t> references;
	bool isUnaccounted = false;
	bool isPlaceholder = false;
	bool declaredInXml = false;
	StaticConfig staticConf = StaticConfig::Global;

	Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
	            const std::string& nVarType, const std::string& nVarName, bool nIsArray,
	            const std::string& nText);
	Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
	            const std::string& nVarType, const std::string& nVarName, bool nIsArray,
	            size_t nArrayItemCnt, const std::string& nText);
	Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
	            const std::string& nVarType, const std::string& nVarName, bool nIsArray,
	            const std::string& nArrayItemCntStr, const std::string& nText);
	Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
	            const std::string& nVarType, const std::string& nVarName, bool nIsArray,
	            size_t nArrayItemCnt, const std::string& nText, bool nIsExternal);

	Declaration(offset_t nAddress, const std::string& nIncludePath, size_t nSize,
	            const std::string& nVarType, const std::string& nVarName);

	Declaration(offset_t nAddress, const std::string& nIncludePath, size_t nSize,
	            const std::string& nVarType, const std::string& nVarName,
	            const std::string& nDefines);

	bool IsStatic() const;

	std::string GetNormalDeclarationStr() const;
	std::string GetExternalDeclarationStr() const;

	std::string GetExternStr() const;
	std::string GetDefinesStr() const;

	std::string GetStaticForwardDeclarationStr() const;

protected:
	Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
	            const std::string& nText);
};