Files
int2ssl/FalloutScript.h
T

121 lines
3.6 KiB
C++
Raw Normal View History

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-14 13:39:47 +03:00
virtual void Serialize(CArchive& ar);
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
void Dump(CArchive& ar);
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-14 13:39:47 +03:00
void StoreSource(CArchive& ar);
void StoreTree(CArchive& ar);
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 16:59:52 +03:00
void ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Destination, WORD wDelimeter, int nSizeOfCodeItem, const char* lpszErrorMessage, bool (CFalloutScript::*pCheckFunc)(WORD, INT_PTR));
bool CheckExportVarCode(WORD wOperator, INT_PTR nIndex);
bool CheckSetExportedVarValueCode(WORD wOperator, INT_PTR nIndex);
bool CheckExportProcCode(WORD wOperator, INT_PTR nIndex);
2015-02-13 16:59:11 +03:00
2015-02-13 23:09:21 +03:00
INT_PTR GetIndexOfProc(const char* lpszName);
2015-02-14 13:39:47 +03:00
INT_PTR GetIndexOfProc(ULONG ulNameOffset);
INT_PTR GetIndexOfExportedVariable(ULONG ulNameOffset);
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
void SetExternalVariable(ULONG ulNameOffset);
void TryRenameGlobalVariables();
void TryRenameImportedVariables();
2015-02-13 16:59:11 +03:00
INT_PTR NextNodeIndex( CNodeArray& NodeArray, INT_PTR nCurrentIndex, INT_PTR nSteep);
2015-02-15 16:59:52 +03:00
bool CheckSequenceOfNodes(CNodeArray& NodeArray, INT_PTR nStartIndex, const WORD wSequence[], INT_PTR nSequenceLen);
bool RemoveSequenceOfNodes(CNodeArray& NodeArray,INT_PTR nStartIndex, INT_PTR nCount, const WORD wSequence[], INT_PTR nSequenceLen);
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
void InitialReduce();
void BuildTree(CNodeArray& NodeArray);
void ExtractAndReduceCondition(CNodeArray& Source, CNodeArray& Destination, INT_PTR nStartIndex);
void SetBordersOfBlocks(CNodeArray& NodeArray);
ULONG BuildTreeBranch(CNodeArray& NodeArray, ULONG nStartIndex, ULONG ulEndOffset);
void ReduceConditionalExpressions(CNodeArray& NodeArray);
2015-02-15 16:59:52 +03:00
bool IsOmittetArgsAllowed(WORD wOpcode);
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
void StoreDefinitions(CArchive& ar);
void StoreDeclarations(CArchive& ar);
2015-02-13 16:59:11 +03:00
2015-02-15 16:59:52 +03:00
std::string GetSource( CNode& node, bool bLabel, ULONG ulNumArgs);
std::string GetSource( CNode& node, bool bLabel, ULONG ulNumArgs, ULONG aulProcArg[], ULONG 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 16:16:45 +03:00
std::string GetIndentString(INT_PTR nLevel);
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
int GetPriority(WORD wOperator);
Assoc GetAssociation(WORD 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:
CDefObject(ObjectType type = OBJECT_VARIABLE, ULONG ulAttributes = 0, ULONG ulObjectData = 0);
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
public:
ObjectType m_ObjectType;
ULONG m_ulAttributes;
2015-02-13 16:59:11 +03:00
2015-02-14 13:39:47 +03:00
union {
ULONG m_ulVarValue;
ULONG m_ulProcIndex;
};
};
2015-02-13 16:59:11 +03:00
private:
2015-02-14 13:39:47 +03:00
// CMapULongToDefObject
typedef CMap<ULONG, ULONG, CDefObject, CDefObject&> CMapULongToDefObject;
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-14 13:39:47 +03:00
CMapULongToDefObject 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