/*	Copyright  (c)	Günter Woigk 2010 - 2021
					mailto:kio@little-bat.de

	This file is free software.

	Permission to use, copy, modify, distribute, and sell this software
	and its documentation for any purpose is hereby granted without fee,
	provided that the above copyright notice appears in all copies and
	that both that copyright notice, this permission notice and the
	following disclaimer appear in supporting documentation.

	THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY,
	NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
	A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE COPYRIGHT HOLDER
	BE LIABLE FOR ANY DAMAGES ARISING FROM THE USE OF THIS SOFTWARE,
	TO THE EXTENT PERMITTED BY APPLICABLE LAW.
*/

#pragma once

#include "kio/kio.h"
#include "Templates/Array.h"
#include "types.h"

//	––––––––––––––––––––––––––––––––––––––––––
//	Ein Word repräsentiert ein Wort im Source.
//	Es enthält:
//		Namen			als idf_id
//		Sourceposition:	als Offset im Source
//		ggf. den Wert:	Value*
//	––––––––––––––––––––––––––––––––––––––––––


class Word final
{
public:
	NameID	idf;			// name or tIVAL
	uint32  spos;			// position (offset) in source
	Ival*	value;			// if idf==tIVAL

public:
	~Word();
	Word (cWord& q);
	Word (Word&& q);
	Word& operator = (cWord& q);
	Word& operator = (Word&& q);

	Word ()									noexcept : idf(NameID(0)),spos(0) {}
	Word (uint32 spos, NameID idf)			noexcept; // identifiers
	Word (uint32 spos, cType*, float128 v)	noexcept; // numeric values
	Word (uint32 spos, cstr s)				noexcept; // cstring: sets errno, may contain null as a 2-byte encoding
	Word (uint32 spos, Ival*)				noexcept; // takes ownership of Value

	bool operator == (NameID idf) const		noexcept { return this->idf == idf; }
	bool operator != (NameID idf) const		noexcept { return this->idf != idf; }
	bool operator != (cWord&)     const		noexcept;

	void serialize (FD&) const throws;
	void deserialize (FD&) throws;
};






















