1 Star 0 Fork 14

xiejian/ftrpc

forked from RonxBulld/ftrpc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
symman.cpp 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
RonxBulld 提交于 2018-07-09 00:23 . 添加数组支持
//
// Created by Rexfield on 2018/5/3.
//
#include <exception>
#include "symman.h"
TokenManage::TokenManage(std::initializer_list<std::pair<std::string, TokenID>> initToken) {
for(const auto & [literal,id] : initToken) {
this->i2s.insert(std::make_pair(id, literal));
this->s2i.insert(std::make_pair(literal, id));
this->indexReg = id >= this->indexReg ? id + 1 : this->indexReg;
}
}
TokenID TokenManage::operator[](const std::string &Token) {
if (this->s2i.find(Token) != this->s2i.end()) {
return this->s2i[Token];
}
TokenID i = this->indexReg++;
this->s2i.insert(std::make_pair(Token, i));
this->i2s.insert(std::make_pair(i, Token));
return i;
}
const std::string &TokenManage::operator[](const TokenID &ID) {
if (this->i2s.find(ID) != this->i2s.end()) {
return this->i2s[ID];
}
}
TypeManage::TypeManage(std::initializer_list<std::pair<TypeID, TokenID>> initBaseType) {
for(auto member : initBaseType) {
this->tk2ty.insert(std::make_pair(member.second, member.first));
this->ty2tk.insert(std::make_pair(member.first, member.second));
this->indexReg = member.first >= this->indexReg ? member.first + 1 : this->indexReg;
}
}
TypeID TypeManage::getTypeID(TokenID Name) {
if (this->tk2ty.find(Name) == this->tk2ty.end()) {
throw std::runtime_error("Referenced an undefined type.");
}
return this->tk2ty[Name];
}
void TypeManage::registType(TokenID Name, enum typeDefType DeclareType, MemberLists &MemberList) {
if (this->tk2ty.find(Name) != this->tk2ty.end()) {
throw std::runtime_error("Redefine the type.");
}
TypeID i = this->indexReg++;
this->tk2ty.insert(std::make_pair(Name, i));
this->ty2tk.insert(std::make_pair(i, Name));
switch (DeclareType)
{
case typeDefType::DeclareStruct: {
this->StructsMap[i] = MemberList;
break;
}
case typeDefType::DeclareBase: {
// If *MemberList is nullptr, it means that the underlying type is being defined.
// No extra work needs to be done.
break;
}
default:
throw std::runtime_error("DeclareType was set to an inappropriate value.");
}
}
bool TypeManage::isType(TokenID Name) {
return this->tk2ty.find(Name) != this->tk2ty.end();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/xiejian601/ftrpc.git
git@gitee.com:xiejian601/ftrpc.git
xiejian601
ftrpc
ftrpc
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385