网站首页 > 资源文章 正文
一,Instance是所有实例对象的基类(也称为Dart源代码中的Object类)
二,canonicalization(规范化) 是编译器 IR(intermediate representation) 设计中的一个重要部分,它使代码转换(transformations) 变得简单高效。大多数编译器都有 canonicalization pass,对于后续进行编译器优化也起到很大作用
/*如果无法规范化实例,则返回Instance::null()。任何非规范number,字符串都将在此处规范化。如果实例的字段中仍然包含非规范实例,则无法规范化该实例。返回error_str中的错误,如果无法发生错误,则传递NULL。 */
virtual RawInstance* CheckAndCanonicalize(Thread* thread,
const char** error_str) const;
三,检查此实例的类型是否为给定其他类型的子类型 ,如果需要,类型参数向量用于实例化其他类型.
bool IsInstanceOf(const AbstractType& other,
const TypeArguments& other_instantiator_type_arguments,
const TypeArguments& other_function_type_arguments) const;
void SetNativeField(int index, intptr_t value) const
void SetField(const Field& field, const Object& value) const;
virtual RawTypeArguments* GetTypeArguments() const;
RawAbstractType* GetType(Heap::Space space) const;
四,如果此实例的类型是FutureOr<T>的子类型,则返回true ,由实例化类型“other”指定。 如果其他类型不是FutureOr,则返回false。
bool IsFutureOrInstanceOf(Zone* zone,
const AbstractType& other) const;
五,如果实例是可调用对象,即闭包或实现“call”方法的类的实例,则返回true并将函数(如果不是NULL)设置为调用
bool IsCallable(Function* function) const;
六,指针可能有子类型,但其子类型可能没有额外的字段。子类型运行时表示具有完全相同的对象布局,只有class_id不同。因此,在指针句柄中使用子类型实例是安全的
virtual bool IsPointer() const;
七,获取instace的所有参数类型,如:int 4/8个字节等,地址是连续的
RawTypeArguments* Instance::GetTypeArguments() const {
ASSERT(!IsType());
const Class& cls = Class::Handle(clazz());
intptr_t field_offset = cls.host_type_arguments_field_offset();
ASSERT(field_offset != Class::kNoTypeArguments);
TypeArguments& type_arguments = TypeArguments::Handle();
type_arguments ^= *FieldAddrAtOffset(field_offset);
return type_arguments.raw();
}
void Instance::SetTypeArguments(const TypeArguments& value) const {
ASSERT(!IsType());
ASSERT(value.IsNull() || value.IsCanonical());
const Class& cls = Class::Handle(clazz());
intptr_t field_offset = cls.host_type_arguments_field_offset();
ASSERT(field_offset != Class::kNoTypeArguments);
SetFieldAtOffset(field_offset, value);
}
八,检查类型T0是否为类型T1的子类型。
类型T0由用“Type_arguments”参数化的类“cls”和“nullability”指定,类型T1由“other”指定,并且必须具有类型类
此函数不支持类型为T0的Null、Never、dynamic或void
bool Class::IsSubtypeOf(const Class& cls,
const TypeArguments& type_arguments,
Nullability nullability,
const AbstractType& other,
Heap::Space space){
….
// 左边 FutureOr:
// if T0 is FutureOr<S0> then:
// T0 <: T1 iff Future<S0> <: T1 && S0 <: T1
if (this_cid == kFutureOrCid) {
// Check Future<S0> <: T1.
ObjectStore* object_store = Isolate::Current()->object_store();
const Class& future_class =
Class::Handle(zone, object_store->future_class());
ASSERT(!future_class.IsNull() && future_class.NumTypeParameters() == 1 &&
this_class.NumTypeParameters() == 1);
ASSERT(type_arguments.IsNull() || type_arguments.Length() >= 1);
if (Class::IsSubtypeOf(future_class, type_arguments,
Nullability::kNonNullable, other, space)) {
// Check S0 <: T1.
const AbstractType& type_arg =
AbstractType::Handle(zone, type_arguments.TypeAtNullSafe(0));
if (type_arg.IsSubtypeOf(other, space)) {
return verified_nullability;
}
}
}
}
九,FutureOr类型后续需详细分析
十,Symbols(包含规范化格式的常用字符串列表。此列表保存在vm_isolate中,以便在隔离之间共享副本,而无需在每个隔离中维护副本)
class Symbols : public AllStatic {
}
代码扣析
define DART_TOKEN_LIST(TOK) \
TOK(kEOS, "", 0, kNoAttribute) \
\
TOK(kLPAREN, "(", 0, kNoAttribute) \
TOK(kRPAREN, ")", 0, kNoAttribute) \
TOK(kLBRACK, "[", 0, kNoAttribute) \
TOK(kRBRACK, "]", 0, kNoAttribute) \
TOK(kLBRACE, "{", 0, kNoAttribute) \
TOK(kRBRACE, "}", 0, kNoAttribute) \
TOK(kARROW, "=>", 0, kNoAttribute) \
TOK(kCOLON, ":", 0, kNoAttribute) \
TOK(kSEMICOLON, ";", 0, kNoAttribute) \
TOK(kPERIOD, ".", 0, kNoAttribute) \
TOK(kQM_PERIOD, "?.", 0, kNoAttribute) \
TOK(kINCR, "++", 0, kNoAttribute) \
TOK(kDECR, "--", 0, kNoAttribute)
#define DART_KEYWORD_LIST(KW) \
KW(kABSTRACT, "abstract", 0, kPseudoKeyword) /* == kFirstKeyword */ \
KW(kAS, "as", 11, kPseudoKeyword) \
KW(kASSERT, "assert", 0, kKeyword) \
KW(kBREAK, "break", 0, kKeyword) \
KW(kCASE, "case", 0, kKeyword) \
#define PREDEFINED_SYMBOLS_LIST(V) \
V(AbstractClassInstantiationError, "AbstractClassInstantiationError") \
V(AllocateInvocationMirror, "_allocateInvocationMirror") \
V(AllocateInvocationMirrorForClosure, "_allocateInvocationMirrorForClosure") \
V(AnonymousClosure, "<anonymous closure>") \
V(AnonymousSignature, "<anonymous signature>") \
V(ApiError, "ApiError") \
V(ArgDescVar, ":arg_desc") \
V(ArgumentError, "ArgumentError") \
V(AsFunctionInternal, "_asFunctionInternal") \
V(AssertionError, "_AssertionError") \
V(AssignIndexToken, "[]=") \
V(AsyncCompleter, ":async_completer") \
V(AsyncOperation, ":async_op") \
V(AsyncStackTraceVar, ":async_stack_trace") \
V(AsyncStarMoveNextHelper, "_asyncStarMoveNextHelper") \
V(AwaitContextVar, ":await_ctx_var") \
V(AwaitJumpVar, ":await_jump_var") \
V(Bool, "bool") \
V(BooleanExpression, "boolean expression") \
V(BoundsCheckForPartialInstantiation, "_boundsCheckForPartialInstantiation") \
V(ByteData, "ByteData") \
V(ByteDataDot, "ByteData.") \
V(ByteDataDot_view, "ByteData._view")
// List of strings that are pre created in the vm isolate.
enum { kMaxOneCharCodeSymbol = 0xFF };
enum SymbolId {
// clang-format off
kIllegal = 0,
#define DEFINE_SYMBOL_INDEX(symbol, literal) k##symbol##Id,
PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX)
#undef DEFINE_SYMBOL_INDEX
kTokenTableStart, // First token at kTokenTableStart + 1.
#define DEFINE_TOKEN_SYMBOL_INDEX(t, s, p, a) t##Id,
DART_TOKEN_LIST(DEFINE_TOKEN_SYMBOL_INDEX) DART_KEYWORD_LIST(
DEFINE_TOKEN_SYMBOL_INDEX)
#undef DEFINE_TOKEN_SYMBOL_INDEX
kNullCharId, // One char code symbol starts here and takes up 256 entries.
kMaxPredefinedId = kNullCharId + kMaxOneCharCodeSymbol + 1,
// clang-format on
};
static const char* names[] = {
// clang-format off
NULL,
#define DEFINE_SYMBOL_LITERAL(symbol, literal) literal,
PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL)
#undef DEFINE_SYMBOL_LITERAL
"", // matches kTokenTableStart.
#define DEFINE_TOKEN_SYMBOL_INDEX(t, s, p, a) s,
DART_TOKEN_LIST(DEFINE_TOKEN_SYMBOL_INDEX)
DART_KEYWORD_LIST(DEFINE_TOKEN_SYMBOL_INDEX)
#undef DEFINE_TOKEN_SYMBOL_INDEX
// clang-format on
};
string name = names[kBoolId];//name “bool”
猜你喜欢
- 2024-10-08 instance substance circumstance
- 2024-10-08 百度二面:你了解instanceof原理吗?
- 2024-10-08 「JS很简单」JavaScript 基础之 instanceof操作符
- 2024-10-08 Java程序设计-向下转型、instanceof(笔记)
- 2024-10-08 谷歌Chrome浏览器开放Instance Switcher功能
- 2024-10-08 深入了解,Python 中 type 和 isinstance 的用法
- 2024-10-08 性能高、上手快,实体类转换工具 MapStruct 到底有多强大
- 2024-10-08 深入分析java中的instanceof关键字
- 2024-10-08 为什么使用instanceof判断数组并不准确
- 2024-10-08 讲解python中assert、isinstance的用法,这个思维方式能理解吗?
你 发表评论:
欢迎- 07-03win7去掉桌面图标小箭头怎么操作 win7桌面快捷方式箭头怎么去除
- 07-03win7声音图标不见了怎么办(windows7声音没了怎么办)
- 07-03男生勿入:Win10/Win7/Win8.1女生图标下载
- 07-03桌面只有回收站图标,给Win7/10系统在桌面添加“计算机”图标
- 07-03经典windows桌面图标手机壁纸(经典windows桌面背景)
- 07-03如何在Win10启用Win7/Win8.1通知区域图标设置?
- 07-03win7声音图标不见了解决步骤(win7旗舰版声音图标不显示)
- 07-03为什么回收站图标没了?win11/win10/win7电脑如何显示回收站图标
- 最近发表
-
- win7去掉桌面图标小箭头怎么操作 win7桌面快捷方式箭头怎么去除
- win7声音图标不见了怎么办(windows7声音没了怎么办)
- 男生勿入:Win10/Win7/Win8.1女生图标下载
- 桌面只有回收站图标,给Win7/10系统在桌面添加“计算机”图标
- 经典windows桌面图标手机壁纸(经典windows桌面背景)
- 如何在Win10启用Win7/Win8.1通知区域图标设置?
- win7声音图标不见了解决步骤(win7旗舰版声音图标不显示)
- 为什么回收站图标没了?win11/win10/win7电脑如何显示回收站图标
- Win7怎么更换本地磁盘图标?(win7桌面改d盘)
- Win7桌面图标消失怎么办?(win7桌面图标全没了怎么办)
- 标签列表
-
- 电脑显示器花屏 (79)
- 403 forbidden (65)
- linux怎么查看系统版本 (54)
- 补码运算 (63)
- 缓存服务器 (61)
- 定时重启 (59)
- plsql developer (73)
- 对话框打开时命令无法执行 (61)
- excel数据透视表 (72)
- oracle认证 (56)
- 网页不能复制 (84)
- photoshop外挂滤镜 (58)
- 网页无法复制粘贴 (55)
- vmware workstation 7 1 3 (78)
- jdk 64位下载 (65)
- phpstudy 2013 (66)
- 卡通形象生成 (55)
- psd模板免费下载 (67)
- shift (58)
- localhost打不开 (58)
- 检测代理服务器设置 (55)
- frequency (66)
- indesign教程 (55)
- 运行命令大全 (61)
- ping exe (64)
本文暂时没有评论,来添加一个吧(●'◡'●)