Files
int2ssl/FalloutScript.h
T

129 lines
3.9 KiB
C++
Raw Normal View History

2015-02-15 18:53:04 +03:00
/**
*
* Copyright (c) 2005-2009 Anchorite (TeamX), <anchorite2001@yandex.ru>
2015-02-15 21:33:27 +03:00
* Copyright (c) 2014-2015 Nirran, phobos2077
* Copyright (c) 2015 alexeevdv <mail@alexeevdv.ru>
2015-02-15 18:53:04 +03:00
* Distributed under the GNU GPL v3. For full terms see the file license.txt
*
*/
2015-02-13 16:59:11 +03:00
#ifndef FALLOUT_SCRIPT_H
#define FALLOUT_SCRIPT_H
2015-02-15 16:31:38 +03:00
// C++ standard includes
#include <vector>
// int2ssl includes
2015-02-13 16:59:11 +03:00
#include "StartupCode.h"
#include "ProcTable.h"
#include "Namespace.h"
#include "Node.h"
2015-02-15 16:31:38 +03:00
// Third party includes
2015-02-15 16:16:45 +03:00
2015-02-14 14:38:14 +03:00
class CFalloutScript
{
2015-02-13 16:59:11 +03:00
public:
2015-02-14 13:39:47 +03:00
CFalloutScript();
virtual ~CFalloutScript();
2015-02-13 16:59:11 +03:00
public:
2015-02-16 00:30:55 +03:00
virtual void Serialize();
2015-02-13 16:59:11 +03:00
2015-02-16 00:30:55 +03:00
void Dump();
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
void InitDefinitions();
void ProcessCode();
2015-02-13 16:59:11 +03:00
2015-02-16 00:30:55 +03:00
void StoreSource();
void StoreTree();
2015-02-13 16:59:11 +03:00
private:
2015-02-14 13:39:47 +03:00
enum Assoc {
NON_ASSOC,
LEFT_ASSOC,
RIGHT_ASSOC,
};
2015-02-13 16:59:11 +03:00
private:
2015-02-15 22:27:31 +03:00
void ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Destination, uint16_t wDelimeter, uint32_t nSizeOfCodeItem, const char* lpszErrorMessage, bool (CFalloutScript::*pCheckFunc)(uint16_t, int32_t));
2015-02-15 19:05:45 +03:00
bool CheckExportVarCode(uint16_t wOperator, int32_t nIndex);
bool CheckSetExportedVarValueCode(uint16_t wOperator, int32_t nIndex);
bool CheckExportProcCode(uint16_t wOperator, int32_t nIndex);
2015-02-13 16:59:11 +03:00
2015-02-15 19:05:45 +03:00
int32_t GetIndexOfProc(const char* lpszName);
int32_t GetIndexOfProc(uint32_t ulNameOffset);
int32_t GetIndexOfExportedVariable(uint32_t ulNameOffset);
2015-02-13 16:59:11 +03:00
2015-02-15 18:28:27 +03:00
void SetExternalVariable(uint32_t ulNameOffset);
2015-02-14 13:39:47 +03:00
void TryRenameGlobalVariables();
void TryRenameImportedVariables();
2015-02-13 16:59:11 +03:00
2015-02-15 19:05:45 +03:00
int32_t NextNodeIndex( CNodeArray& NodeArray, int32_t nCurrentIndex, int32_t nSteep);
bool CheckSequenceOfNodes(CNodeArray& NodeArray, int32_t nStartIndex, const uint16_t wSequence[], int32_t nSequenceLen);
bool RemoveSequenceOfNodes(CNodeArray& NodeArray,int32_t nStartIndex, int32_t nCount, const uint16_t wSequence[], int32_t nSequenceLen);
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
void InitialReduce();
void BuildTree(CNodeArray& NodeArray);
2015-02-15 19:05:45 +03:00
void ExtractAndReduceCondition(CNodeArray& Source, CNodeArray& Destination, int32_t nStartIndex);
2015-02-14 13:39:47 +03:00
void SetBordersOfBlocks(CNodeArray& NodeArray);
2015-02-15 18:28:27 +03:00
uint32_t BuildTreeBranch(CNodeArray& NodeArray, uint32_t nStartIndex, uint32_t ulEndOffset);
2015-02-15 18:10:01 +03:00
bool IsOmittetArgsAllowed(uint16_t wOpcode);
2015-02-13 16:59:11 +03:00
2015-02-16 00:30:55 +03:00
void StoreDefinitions();
void StoreDeclarations();
2015-02-13 16:59:11 +03:00
2015-02-15 18:28:27 +03:00
std::string GetSource( CNode& node, bool bLabel, uint32_t ulNumArgs);
2023-06-27 23:16:07 +02:00
std::string GetSource( CNode& node, uint32_t ulNumArgs, uint32_t aulProcArg[], uint32_t ulProcArgCount);
2015-02-14 13:39:47 +03:00
bool ArgNeedParens(const CNode& node, const CNode& argument, CFalloutScript::Assoc assoc = CFalloutScript::NON_ASSOC);
2015-02-15 19:05:45 +03:00
std::string GetIndentString(int32_t nLevel);
2015-02-13 16:59:11 +03:00
2015-02-15 18:10:01 +03:00
int GetPriority(uint16_t wOperator);
Assoc GetAssociation(uint16_t wOperator);
2015-02-13 16:59:11 +03:00
private:
2015-02-14 14:38:14 +03:00
class CDefObject
{
2015-02-14 13:39:47 +03:00
public:
enum ObjectType {
OBJECT_VARIABLE,
OBJECT_PROCEDURE
};
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
public:
2015-02-15 18:28:27 +03:00
CDefObject(ObjectType type = OBJECT_VARIABLE, uint32_t ulAttributes = 0, uint32_t ulObjectData = 0);
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
public:
ObjectType m_ObjectType;
2015-02-15 18:28:27 +03:00
uint32_t m_ulAttributes;
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
union {
2015-02-15 18:28:27 +03:00
uint32_t m_ulVarValue;
uint32_t m_ulProcIndex;
2015-02-14 13:39:47 +03:00
};
};
2015-02-13 16:59:11 +03:00
private:
2015-02-15 18:28:27 +03:00
// CMapuint32_tToDefObject
typedef CMap<uint32_t, uint32_t, CDefObject, CDefObject&> CMapuint32_tToDefObject;
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
CStartupCode m_StartupCode;
CProcTable m_ProcTable;
CNamespace m_Namespace;
CNamespace m_Stringspace;
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
COpcodeArray m_GlobalVar;
COpcodeArray m_ExportedVar;
COpcodeArray m_ExportedVarValue;
COpcodeArray m_ExportedProc;
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
CArrayOfNodeArray m_ProcBodies;
CArrayOfNodeArray m_Conditions;
2015-02-13 16:59:11 +03:00
2015-02-15 18:28:27 +03:00
CMapuint32_tToDefObject m_Definitions;
2015-02-15 16:16:45 +03:00
std::vector<std::string> m_GlobalVarsNames;
2015-02-13 16:59:11 +03:00
};
2015-02-15 16:31:38 +03:00
#endif //FALLOUT_SCRIPT_H