add explicit member func call, ready to merge new testcases
This commit is contained in:
@ -244,7 +244,6 @@ class ICMPAction : public ActionItem {
|
||||
};
|
||||
class BlockItem : public LLVMIRItemBase {
|
||||
friend class IRBuilder;
|
||||
friend void ArrangeConstArr(BlockItem &blk, class ConstantExpr_ASTNode *node, size_t &tmp_var_counter);
|
||||
std::string label_full;
|
||||
std::vector<std::shared_ptr<ActionItem>> actions;
|
||||
std::shared_ptr<JMPActionItem> exit_action;
|
||||
|
@ -138,6 +138,7 @@ class ClassDefScope : public ScopeBase {
|
||||
std::unordered_map<std::string, ExprTypeInfo> member_variables;
|
||||
std::unordered_map<std::string, std::shared_ptr<FunctionScope>> member_functions;
|
||||
IRClassInfo llvm_class_info;
|
||||
size_t arrange_counter;
|
||||
bool add_variable(const std::string &name, const ExprTypeInfo &type) override {
|
||||
if (!VariableNameAvailable(name, 0)) {
|
||||
return false;
|
||||
@ -150,6 +151,14 @@ class ClassDefScope : public ScopeBase {
|
||||
throw SemanticError("Invalid Type", 1);
|
||||
}
|
||||
member_variables[name] = type;
|
||||
llvm_class_info.member_var_offset[name] = arrange_counter++;
|
||||
size_t cur_element_size = 4;
|
||||
ExprTypeInfo bool_std = IdentifierType("bool");
|
||||
if (type == bool_std) {
|
||||
cur_element_size = 1;
|
||||
}
|
||||
llvm_class_info.member_var_size.push_back(cur_element_size);
|
||||
llvm_class_info.member_var_type.push_back(Type_AST2LLVM(type));
|
||||
return true;
|
||||
}
|
||||
virtual ExprTypeInfo fetch_varaible(const std::string &name) override {
|
||||
@ -196,6 +205,9 @@ class ClassDefScope : public ScopeBase {
|
||||
}
|
||||
return parent->VariableNameAvailable(name, ttl + 1);
|
||||
}
|
||||
|
||||
public:
|
||||
ClassDefScope() : arrange_counter(0) {}
|
||||
};
|
||||
class GlobalScope : public ScopeBase {
|
||||
friend class Visitor;
|
||||
@ -307,6 +319,15 @@ class GlobalScope : public ScopeBase {
|
||||
}
|
||||
return parent->fetch_variable_for_IR(name);
|
||||
}
|
||||
IRClassInfo fetch_class_info(const std::string &name) {
|
||||
if (classes.find(name) == classes.end()) {
|
||||
throw SemanticError("Undefined Identifier", 1);
|
||||
}
|
||||
auto &tmp = classes[name]->llvm_class_info;
|
||||
tmp.class_name_raw = name;
|
||||
tmp.ArrangeSpace();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public:
|
||||
GlobalScope() { parent = nullptr; }
|
||||
|
@ -117,13 +117,17 @@ struct LLVMIRCLASSTYPE {
|
||||
using LLVMType = std::variant<LLVMIRIntType, LLVMIRPTRType, LLVMVOIDType, LLVMIRCLASSTYPE>;
|
||||
class IRClassInfo {
|
||||
public:
|
||||
std::string class_name_raw; // This data must be provided by user
|
||||
std::vector<size_t> member_var_size; // This data must be provided by user. Each of them is the size of a member
|
||||
// variable, which must be in [1,4]
|
||||
std::string class_name_raw; // This data must be provided by user
|
||||
std::vector<size_t> member_var_size; // This data must be provided by user. Each of them is the size of a member
|
||||
// variable, which must be in [1,4]
|
||||
std::vector<LLVMType> member_var_type; // This data must be provided by user
|
||||
std::unordered_map<std::string, size_t> member_var_offset; // This data must be provided by user
|
||||
std::vector<size_t> member_var_pos_after_align;
|
||||
size_t class_size_after_align;
|
||||
bool alread_arranged;
|
||||
void ArrangeSpace() {
|
||||
if (alread_arranged) return;
|
||||
alread_arranged = true;
|
||||
size_t cur_pos = 0;
|
||||
size_t align_size = 1;
|
||||
for (size_t cur_size : member_var_size) {
|
||||
@ -142,6 +146,7 @@ class IRClassInfo {
|
||||
}
|
||||
}
|
||||
std::string GenerateFullName() { return "%.class." + class_name_raw; }
|
||||
IRClassInfo() : alread_arranged(false) {}
|
||||
};
|
||||
class IRVariableInfo {
|
||||
public:
|
||||
|
Reference in New Issue
Block a user