DataType

used to store data types for data at compile time

Constructors

this
this(DataType.Type dataType, uinteger arrayDimension, bool isReference)

constructor

this
this(string sType)

constructor

this
this(Token[] data)

constructor

Members

Enums

Type
enum Type

enum defining all data types

Functions

fromByteCode
bool fromByteCode(string s)

reads DataType from a byte code style string

fromData
void fromData(Token[] data)

identifies the data type from the actual data keep in mind, this won't be able to identify if the data type is a reference or not

fromString
void fromString(string s)

reads DataType from a string, in case of failure or bad format in string, throws Exception

toByteCode
string toByteCode()

converts this to a byte code style data type, which is a string

toString
string toString()

converts this DataType to string

Properties

isArray
bool isArray [@property getter]

returns true if it's an array

Variables

arrayDimensionCount
uinteger arrayDimensionCount;

stores if it's an array. If type is int, it will be 0, if int[] it will be 1, if int[][], then 2 ...

isRef
bool isRef;

stores if it's a reference to a type

type
Type type;

the actual data type

Examples

st{
	assert(DataType("int") == DataType(DataType.Type.Integer, 0));
	assert(DataType("string[]") == DataType(DataType.Type.String, 1));
	assert(DataType("double[][]") == DataType(DataType.Type.Double, 2));
	assert(DataType("void") == DataType(DataType.Type.Void, 0));
	// unittests for `fromData`
	import qscript.compiler.tokengen : stringToTokens;
	DataType dType;
	dType.fromData(["\"bla bla\""].stringToTokens);
	assert(dType == DataType("string"));
	dType.fromData(["20"].stringToTokens);
	assert(dType == DataType("int"));
	dType.fromData(["2.5"].stringToTokens);
	assert(dType == DataType("double"));
	dType.fromData(["[", "\"bla\"", ",", "\"bla\"", "]"].stringToTokens);
	assert(dType == DataType("string[]"));
	dType.fromData(["[", "[", "25.0", ",", "2.5", "]", ",", "[", "15.0", ",", "25.0", "]", "]"].stringToTokens);
	assert(dType == DataType("double[][]")

Meta