Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
2dcb6c45
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2dcb6c45
编写于
4月 28, 2017
作者:
D
Daniel Larimer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding TypeParser.hpp
上级
50f2bef9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
112 addition
and
0 deletion
+112
-0
libraries/types/include/eos/types/TypeParser.hpp
libraries/types/include/eos/types/TypeParser.hpp
+112
-0
未找到文件。
libraries/types/include/eos/types/TypeParser.hpp
0 → 100644
浏览文件 @
2dcb6c45
#pragma once
#include <map>
#include <string>
#include <vector>
#include <istream>
#include <fc/exception/exception.hpp>
#include <fc/reflect/reflect.hpp>
#include <fc/reflect/variant.hpp>
#include <eos/types/native.hpp>
namespace
EOS
{
using
std
::
map
;
using
std
::
set
;
using
std
::
string
;
using
std
::
vector
;
class
AbstractSymbolTable
{
public:
virtual
~
AbstractSymbolTable
(){};
virtual
void
addType
(
const
Struct
&
s
)
=
0
;
virtual
void
addTypeDef
(
const
TypeName
&
from
,
const
TypeName
&
to
)
=
0
;
virtual
bool
isKnownType
(
const
TypeName
&
name
)
=
0
;
virtual
TypeName
resolveTypedef
(
TypeName
name
)
const
=
0
;
virtual
Struct
getType
(
TypeName
name
)
const
=
0
;
/**
* Parses the input stream and populatse the symbol table, the table may be pre-populated
*/
void
parse
(
std
::
istream
&
in
);
string
binaryToJson
(
const
TypeName
&
type
,
const
Bytes
&
binary
);
Bytes
jsonToBinary
(
const
TypeName
&
type
,
const
string
&
json
);
};
class
SimpleSymbolTable
:
public
AbstractSymbolTable
{
public:
SimpleSymbolTable
()
:
known
(
{
"FixedString16"
,
"FixedString32"
,
"UInt8"
,
"UInt16"
,
"UInt32"
,
"UInt64"
,
"UInt128"
,
"Checksum"
,
"UInt256"
,
"UInt512"
,
"Int8"
,
"Int16"
,
"Int32"
,
"Int64"
,
"Int128"
,
"Int224"
,
"Int256"
,
"Int512"
,
"Bytes"
,
"PublicKey"
,
"Signature"
,
"String"
,
"Time"
}
)
{
}
virtual
void
addType
(
const
Struct
&
s
)
override
{
try
{
FC_ASSERT
(
!
isKnownType
(
s
.
name
)
);
for
(
const
auto
&
f
:
s
.
fields
)
{
FC_ASSERT
(
isKnownType
(
f
.
type
),
""
,
(
"type"
,
f
.
type
)
);
}
structs
[
s
.
name
]
=
s
;
order
.
push_back
(
s
.
name
);
// wdump((s.name)(s.base)(s.fields));
}
FC_CAPTURE_AND_RETHROW
(
(
s
)
)
}
virtual
void
addTypeDef
(
const
TypeName
&
from
,
const
TypeName
&
to
)
override
{
try
{
FC_ASSERT
(
!
isKnownType
(
to
)
);
FC_ASSERT
(
isKnownType
(
from
)
);
typedefs
[
to
]
=
from
;
order
.
push_back
(
to
);
}
FC_CAPTURE_AND_RETHROW
(
(
from
)(
to
)
)
}
virtual
bool
isKnownType
(
const
TypeName
&
name
)
override
{
try
{
FC_ASSERT
(
name
.
size
()
>
0
);
if
(
name
.
size
()
>
2
&&
name
.
back
()
==
']'
)
{
FC_ASSERT
(
name
[
name
.
size
()
-
2
]
==
'['
);
return
isKnownType
(
name
.
substr
(
0
,
name
.
size
()
-
2
)
);
}
return
known
.
find
(
name
)
!=
known
.
end
()
||
typedefs
.
find
(
name
)
!=
typedefs
.
end
()
||
structs
.
find
(
name
)
!=
structs
.
end
();
}
FC_CAPTURE_AND_RETHROW
(
(
name
)
)
}
virtual
Struct
getType
(
TypeName
name
)
const
override
{
name
=
resolveTypedef
(
name
);
auto
itr
=
structs
.
find
(
name
);
if
(
itr
!=
structs
.
end
()
)
return
itr
->
second
;
if
(
known
.
find
(
name
)
!=
known
.
end
()
)
FC_ASSERT
(
!
"type is a built in type"
);
FC_ASSERT
(
!
"unknown type"
,
""
,
(
"n"
,
name
)
);
}
virtual
TypeName
resolveTypedef
(
TypeName
name
)
const
override
{
auto
tdef
=
typedefs
.
find
(
name
);
while
(
tdef
!=
typedefs
.
end
()
)
{
name
=
tdef
->
second
;
tdef
=
typedefs
.
find
(
name
);
}
return
name
;
}
// private:
set
<
TypeName
>
known
;
vector
<
TypeName
>
order
;
map
<
TypeName
,
TypeName
>
typedefs
;
map
<
TypeName
,
Struct
>
structs
;
};
}
// namespace EOS
FC_REFLECT
(
EOS
::
Field
,
(
name
)(
type
)
)
FC_REFLECT
(
EOS
::
Struct
,
(
name
)(
base
)(
fields
)
)
FC_REFLECT
(
EOS
::
SimpleSymbolTable
,
(
typedefs
)(
structs
)
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录