LuaFunctionRegisterSpreadsheet/GhidraParser/Utility.hpp

72 lines
1017 B
C++

#pragma once
#include <iostream>
#include <optional>
#include <string>
#include <vector>
#define PL(msg) std::cout << msg << '\n' // print line
enum Op
{ // https://en.cppreference.com/w/cpp/language/operator_precedence
BRL,
BRR,
LOR,
LAND,
BOR,
BXOR,
BAND,
EQ,
UEQ,
LT,
LTE,
BT,
BTE,
PLS,
MIN,
MUL,
DIV,
MOD,
};
__forceinline int op_prec(Op op)
{
switch (op)
{
case BRL:
return -9000;
case LOR:
return -15;
case LAND:
return -14;
case BOR:
return -13;
case BXOR:
return -12;
case BAND:
return -11;
case EQ:
case UEQ:
return -10;
case LT:
case LTE:
case BT:
case BTE:
return -9;
case PLS:
case MIN:
return -6;
case MUL:
case DIV:
case MOD:
return -5;
}
return -1; // unsupporeted op
}
std::optional<int> prsi(std::string str);
std::vector<char>* lf(std::string& path);
std::vector<char>* lf(const char* path);
bool lnew(std::string& ln, const char* ew);
bool lnsw(std::string& ln, int idx, const char* sw);
void ssie(std::string& str, std::string repl);