<commit_before>/*

  SjASMPlus Z80 Cross Compiler

  This is modified sources of SjASM by Aprisobal - <EMAIL>

  Copyright (c) 2006 <NAME>

  This software is provided 'as-is', without any express or implied warranty.
  In no event will the authors be held liable for any damages arising from the
  use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it freely,
  subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim
	 that you wrote the original software. If you use this software in a product,
	 an acknowledgment in the product documentation would be appreciated but is
	 not required.

  2. Altered source versions must be plainly marked as such, and must not be
	 misrepresented as being the original software.

  3. This notice may not be removed or altered from any source distribution.

*/

// tables.h

#include <unordered_map>

struct TextFilePos {
	const char*		filename;
	uint32_t		line;				// line numbering start at 1 (human way) 0 = invalid/init value
	uint32_t 		colBegin, colEnd;	// columns coordinates are unused at this moment

	TextFilePos();
	void newFile(const char* fileNamePtr);	// requires stable immutable pointer (until sjasmplus exits)

	// advanceColumns are valid only when true == endsWithColon (else advanceColumns == 0)
	// default arguments are basically "next line"
	void nextSegment(bool endsWithColon = false, size_t advanceColumns = 0);
};

enum EStructureMembers {
	SMEMBUNKNOWN, SMEMBALIGN,
	SMEMBBYTE, SMEMBWORD, SMEMBBLOCK, SMEMBDWORD, SMEMBD24, SMEMBTEXT,
	SMEMBPARENOPEN, SMEMBPARENCLOSE
};

struct SLabelTableEntry;

char* ValidateLabel(const char* naam, bool setNameSpace);
char* ExportLabelToSld(const char* naam, const SLabelTableEntry* label);
char* ExportModuleToSld(bool endModule = false);
extern char* PreviousIsLabel;
bool GetLabelPage(char*& p, aint& val);
bool GetLabelValue(char*& p, aint& val);
int GetLocalLabelValue(char*& op, aint& val);

constexpr int LABEL_PAGE_UNDEFINED = -1;
constexpr int LABEL_PAGE_ROM = 0x7F00;			// must be minimum of special values (but positive)
constexpr int LABEL_PAGE_OUT_OF_BOUNDS = 0x7F80;	// label is defined, but not within Z80 address space

constexpr unsigned LABEL_IS_UNDEFINED = (1<<0);
constexpr unsigned LABEL_IS_DEFL = (1<<1);
constexpr unsigned LABEL_IS_EQU = (1<<2);
constexpr unsigned LABEL_IS_STRUCT_D = (1<<3);
constexpr unsigned LABEL_IS_STRUCT_E = (1<<4);
constexpr unsigned LABEL_HAS_RELOC_TRAIT = (1<<5);
constexpr unsigned LABEL_IS_RELOC = (1<<6);
// constexpr unsigned LABEL_IS_USED = (1<<7);	// currently not explicitly used in Insert(..) (calculated implicitly)

struct SLabelTableEntry {
	aint	value = 0;
	int		updatePass = 0;	// last update was in pass
	short	page = LABEL_PAGE_UNDEFINED;
	bool	IsDEFL = false;
	bool	IsEQU = false;
	bool	used = false;
	bool	isRelocatable = false;
	bool	isStructDefinition = false;
	bool	isStructEmit = false;
};

typedef std::unordered_map<std::string, SLabelTableEntry> symbol_map_t;

class CLabelTable {
private:
	symbol_map_t symbols;
public:
	int Insert(const char* nname, aint nvalue, unsigned traits = 0, short equPageNum = LABEL_PAGE_UNDEFINED);<commit_msg>experimental: add reserve(..) call to the std::unordered_map for symbols table<commit_after>/*

  SjASMPlus Z80 Cross Compiler

  This is modified sources of SjASM by Aprisobal - <EMAIL>

  Copyright (c) 2006 <NAME>

  This software is provided 'as-is', without any express or implied warranty.
  In no event will the authors be held liable for any damages arising from the
  use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it freely,
  subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim
	 that you wrote the original software. If you use this software in a product,
	 an acknowledgment in the product documentation would be appreciated but is
	 not required.

  2. Altered source versions must be plainly marked as such, and must not be
	 misrepresented as being the original software.

  3. This notice may not be removed or altered from any source distribution.

*/

// tables.h

#include <unordered_map>

struct TextFilePos {
	const char*		filename;
	uint32_t		line;				// line numbering start at 1 (human way) 0 = invalid/init value
	uint32_t 		colBegin, colEnd;	// columns coordinates are unused at this moment

	TextFilePos();
	void newFile(const char* fileNamePtr);	// requires stable immutable pointer (until sjasmplus exits)

	// advanceColumns are valid only when true == endsWithColon (else advanceColumns == 0)
	// default arguments are basically "next line"
	void nextSegment(bool endsWithColon = false, size_t advanceColumns = 0);
};

enum EStructureMembers {
	SMEMBUNKNOWN, SMEMBALIGN,
	SMEMBBYTE, SMEMBWORD, SMEMBBLOCK, SMEMBDWORD, SMEMBD24, SMEMBTEXT,
	SMEMBPARENOPEN, SMEMBPARENCLOSE
};

struct SLabelTableEntry;

char* ValidateLabel(const char* naam, bool setNameSpace);
char* ExportLabelToSld(const char* naam, const SLabelTableEntry* label);
char* ExportModuleToSld(bool endModule = false);
extern char* PreviousIsLabel;
bool GetLabelPage(char*& p, aint& val);
bool GetLabelValue(char*& p, aint& val);
int GetLocalLabelValue(char*& op, aint& val);

constexpr int LABEL_PAGE_UNDEFINED = -1;
constexpr int LABEL_PAGE_ROM = 0x7F00;			// must be minimum of special values (but positive)
constexpr int LABEL_PAGE_OUT_OF_BOUNDS = 0x7F80;	// label is defined, but not within Z80 address space

constexpr unsigned LABEL_IS_UNDEFINED = (1<<0);
constexpr unsigned LABEL_IS_DEFL = (1<<1);
constexpr unsigned LABEL_IS_EQU = (1<<2);
constexpr unsigned LABEL_IS_STRUCT_D = (1<<3);
constexpr unsigned LABEL_IS_STRUCT_E = (1<<4);
constexpr unsigned LABEL_HAS_RELOC_TRAIT = (1<<5);
constexpr unsigned LABEL_IS_RELOC = (1<<6);
// constexpr unsigned LABEL_IS_USED = (1<<7);	// currently not explicitly used in Insert(..) (calculated implicitly)

struct SLabelTableEntry {
	aint	value = 0;
	int		updatePass = 0;	// last update was in pass
	short	page = LABEL_PAGE_UNDEFINED;
	bool	IsDEFL = false;
	bool	IsEQU = false;
	bool	used = false;
	bool	isRelocatable = false;
	bool	isStructDefinition = false;
	bool	isStructEmit = false;
};

typedef std::unordered_map<std::string, SLabelTableEntry> symbol_map_t;

class CLabelTable {
private:
	symbol_map_t symbols;
public:
	CLabelTable() { symbols.reserve(LABTABSIZE); }
	int Insert(const char* nname, aint nvalue, unsigned traits = 0, short equPageNum = LABEL_PAGE_UNDEFINED);
{'fraction_non_alphanumeric': 0.07832313889303297, 'fraction_numerical': 0.014620319260032821, 'mean_word_length': 4.870402802101577, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6909227', 'n_tokens_mistral': 2246, 'n_tokens_neox': 2097, 'n_words': 788}