acpa/include/element.h
szdytom 3d1ffa838f
改善了一些实现
Co-authored-by: lcw <ez_lcw@foxmail.com>
2023-08-30 09:02:34 +08:00

76 lines
2.9 KiB
C++

#ifndef ACPA_ELEMENT_H
#define ACPA_ELEMENT_H
#include <map>
#include <set>
#include <utility>
#include <memory>
#include <string>
#include <vector>
using std::map;
using std::set;
using std::pair;
using std::shared_ptr;
using std::string;
using std::vector;
using std::weak_ptr;
struct Struct;
struct ValType;
struct TemplateType;
struct StructType;
struct FunctionType;
struct Struct {
weak_ptr<Struct> fa;
vector<shared_ptr<TemplateType>> c1;
vector<shared_ptr<ValType>> c2;
map<string, shared_ptr<ValType>> vars;
map<string, shared_ptr<Struct>> structs;
};
struct ValType {
enum Type {
TEMPLATE,
STRUCT,
FUNCTION
};
virtual ValType::Type type() const = 0;
virtual shared_ptr<ValType> struct_replace(shared_ptr<StructType>, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) = 0;
virtual shared_ptr<ValType> function_replace(const map<shared_ptr<TemplateType>, shared_ptr<ValType>>&, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) = 0;
virtual bool sameType(shared_ptr<ValType>, set<pair<shared_ptr<TemplateType>, shared_ptr<TemplateType>>>&) = 0;
virtual ~ValType() = default;
};
struct TemplateType : ValType {
ValType::Type type() const override;
shared_ptr<ValType> struct_replace(shared_ptr<StructType>, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
shared_ptr<ValType> function_replace(const map<shared_ptr<TemplateType>, shared_ptr<ValType>>&, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
bool sameType(shared_ptr<ValType>, set<pair<shared_ptr<TemplateType>, shared_ptr<TemplateType>>>&) override;
};
struct StructType : ValType {
ValType::Type type() const override;
shared_ptr<ValType> struct_replace(shared_ptr<StructType>, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
shared_ptr<ValType> function_replace(const map<shared_ptr<TemplateType>, shared_ptr<ValType>>&, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
bool sameType(shared_ptr<ValType>, set<pair<shared_ptr<TemplateType>, shared_ptr<TemplateType>>>&) override;
shared_ptr<Struct> str;
map<shared_ptr<TemplateType>, shared_ptr<ValType>> mp;
};
struct FunctionType : ValType {
ValType::Type type() const override;
shared_ptr<ValType> struct_replace(shared_ptr<StructType>, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
shared_ptr<ValType> function_replace(const map<shared_ptr<TemplateType>, shared_ptr<ValType>>&, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
bool sameType(shared_ptr<ValType>, set<pair<shared_ptr<TemplateType>, shared_ptr<TemplateType>>>&) override;
vector<shared_ptr<TemplateType>> c1;
vector<shared_ptr<ValType>> c2;
shared_ptr<ValType> c3;
};
shared_ptr<ValType> struct_replace(shared_ptr<ValType>, shared_ptr<StructType>);
shared_ptr<ValType> function_replace(shared_ptr<ValType>, const map<shared_ptr<TemplateType>, shared_ptr<ValType>>&);
bool sameType(shared_ptr<ValType>, shared_ptr<ValType>);
#endif