File: ade_doc.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (170 lines) | stat: -rw-r--r-- 6,564 bytes parent folder | download | duplicates (2)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "ade_doc.h"

#include "globalincs/pstypes.h"

namespace scripting {

ade_type_info::ade_type_info(const ade_type_tuple& tupleType)
	: _type(ade_type_info_type::Tuple), _elements(tupleType.getElementTypes())
{
}
ade_type_info::ade_type_info(const char* single_type) : _type(ade_type_info_type::Simple)
{
	if (single_type != nullptr) {
		_identifier.assign(single_type);
	}

	if (single_type == nullptr) {
		// It would be better to handle this via an overload with std::nullptr_t but there are a lot of NULL usages left
		// so this is the soltuion that requires fewer changes
		_type = ade_type_info_type::Empty;
		return;
	}

	// Otherwise, make sure no one tries to specify a tuple with a single string.
	Assertion(strchr(single_type, ',') == nullptr,
		"Type string '%s' may not contain commas! Use the intializer list instead.",
		single_type);
}
ade_type_info::ade_type_info(SCP_string single_type)
	: _type(ade_type_info_type::Simple), _identifier(std::move(single_type))
{
	if (_identifier.empty()) {
		_type = ade_type_info_type::Empty;
		return;
	}

	// Otherwise, make sure no one tries to specify a tuple with a single string.
	Assertion(_identifier.find(',') == SCP_string::npos,
		"Type string '%s' may not contain commas! Use the intializer list instead.",
		_identifier.c_str());
}
ade_type_info::ade_type_info(const ade_type_array& listType)
	: _type(ade_type_info_type::Array), _elements{listType.getElementType()}
{
}
ade_type_info::ade_type_info(const ade_type_map& listType)
	: _type(ade_type_info_type::Map), _elements{listType.getKeyType(), listType.getValueType()}
{
}
ade_type_info::ade_type_info(const ade_type_iterator& iteratorType)
	: _type(ade_type_info_type::Iterator), _elements{iteratorType.getElementType()}
{
}
ade_type_info::ade_type_info(const ade_type_alternative& alternativeType)
	: _type(ade_type_info_type::Alternative), _elements(alternativeType.getElementTypes())
{
}
ade_type_info::ade_type_info(const ade_type_function& functionType) : _type(ade_type_info_type::Function) {
	_elements.reserve(functionType.getArgumentTypes().size() + 1);

	// First is return type
	_elements.push_back(functionType.getReturnType());
	// Rest are parameters
	_elements.insert(_elements.end(), functionType.getArgumentTypes().begin(), functionType.getArgumentTypes().end());
}

ade_type_info::ade_type_info(const ade_type_generic& genericType) : _type(ade_type_info_type::Generic)
{
	_elements.reserve(genericType.getGenericTypes().size() + 1);

	// First is base type
	_elements.push_back(genericType.getBaseType());
	// Rest are parameters
	_elements.insert(_elements.end(), genericType.getGenericTypes().begin(), genericType.getGenericTypes().end());
}
ade_type_info::ade_type_info(const ade_type_varargs& genericType) : _type(ade_type_info_type::Varargs)
{
	_elements.push_back(genericType.getBaseType());
}

ade_type_info::ade_type_info(ade_type_info&&) noexcept = default;
ade_type_info& ade_type_info::operator=(ade_type_info&&) noexcept = default;

bool ade_type_info::isEmpty() const { return _type == ade_type_info_type::Empty; }
bool ade_type_info::isTuple() const { return _type == ade_type_info_type::Tuple; }
bool ade_type_info::isSimple() const { return _type == ade_type_info_type::Simple; }
bool ade_type_info::isArray() const { return _type == ade_type_info_type::Array; }
bool ade_type_info::isAlternative() const { return _type == ade_type_info_type::Alternative; }
const SCP_vector<ade_type_info>& ade_type_info::elements() const { return _elements; }
const char* ade_type_info::getIdentifier() const { return _identifier.c_str(); }
ade_type_info_type ade_type_info::getType() const { return _type; }
const ade_type_info& ade_type_info::arrayType() const { return _elements.front(); }

const SCP_string& ade_type_info::getName() const { return _name; }
void ade_type_info::setName(const SCP_string& name) { _name = name; }

ade_type_array::ade_type_array(ade_type_info elementType) : _element_type(std::move(elementType)) {}
const ade_type_info& ade_type_array::getElementType() const { return _element_type; }

ade_type_map::ade_type_map(ade_type_info keyType, ade_type_info valueType)
	: _key_type(std::move(keyType)), _value_type(std::move(valueType))
{
}
const ade_type_info& ade_type_map::getKeyType() const { return _key_type; }
const ade_type_info& ade_type_map::getValueType() const { return _value_type; }

ade_type_iterator::ade_type_iterator(ade_type_info elementType) : _element_type(std::move(elementType)) {}
const ade_type_info& ade_type_iterator::getElementType() const { return _element_type; }

ade_type_alternative::ade_type_alternative(SCP_vector<ade_type_info> elements) : _elements(std::move(elements)) {}
const SCP_vector<ade_type_info>& ade_type_alternative::getElementTypes() const { return _elements; }

ade_type_tuple::ade_type_tuple(SCP_vector<ade_type_info> elements) : _elements(std::move(elements)) {}
const SCP_vector<ade_type_info>& ade_type_tuple::getElementTypes() const { return _elements; }

ade_type_function::ade_type_function(ade_type_info returnType, SCP_vector<ade_type_info> argumentTypes)
	: _returnType(std::move(returnType)), _argumentTypes(std::move(argumentTypes))
{
}
const ade_type_info& ade_type_function::getReturnType() const
{
	return _returnType;
}
const SCP_vector<scripting::ade_type_info>& ade_type_function::getArgumentTypes() const
{
	return _argumentTypes;
}

ade_type_generic::ade_type_generic(ade_type_info baseType, SCP_vector<ade_type_info> genericTypes)
	: _baseType(std::move(baseType)), _genericTypes(std::move(genericTypes))
{
}
const ade_type_info& ade_type_generic::getBaseType() const
{
	return _baseType;
}
const SCP_vector<scripting::ade_type_info>& ade_type_generic::getGenericTypes() const
{
	return _genericTypes;
}

ade_type_varargs::ade_type_varargs(ade_type_info baseType) : _baseType(std::move(baseType)) {}
const ade_type_info& ade_type_varargs::getBaseType() const
{
	return _baseType;
}

ade_overload_list::ade_overload_list(const char* arglist) : ade_overload_list({arglist})
{
	fixNullPointers();
}
ade_overload_list::ade_overload_list(std::initializer_list<const char*> overloads) : _arg_lists(overloads)
{
	fixNullPointers();
}
ade_overload_list::ade_overload_list() : ade_overload_list({nullptr}) {}
const SCP_vector<const char*>& ade_overload_list::overloads()
{
	return _arg_lists;
}
void ade_overload_list::fixNullPointers()
{
	for (auto& arg : _arg_lists) {
		if (arg == nullptr) {
			// Fix null pointers to empty strings so we don't have to deal with that elsewhere
			arg = "";
		}
	}
}
} // namespace scripting