diff --git a/src/MapleFE/ast2cpp/include/cpp_declaration.h b/src/MapleFE/ast2cpp/include/cpp_declaration.h index f782d0a8f8aee5331d399fc6fb9c880e61f32c01..fcf6b61c323171b9e610b6907c739231132cc512 100644 --- a/src/MapleFE/ast2cpp/include/cpp_declaration.h +++ b/src/MapleFE/ast2cpp/include/cpp_declaration.h @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -76,6 +76,8 @@ public: std::string EmitArrayLiteral(ArrayLiteralNode *node, int dim, std::string type); std::string EmitTSEnum(StructNode *node); std::string EmitInterface(StructNode *node); + + void CollectFuncArgInfo(TreeNode* node); }; inline bool IsVarInitStructLiteral(DeclNode* node) { diff --git a/src/MapleFE/ast2cpp/include/cpp_definition.h b/src/MapleFE/ast2cpp/include/cpp_definition.h index f4721648df952dae5ecb4f24f4247058cff65438..07dfec249ed6cc74b436aac3a7d428f40a6bcd12 100644 --- a/src/MapleFE/ast2cpp/include/cpp_definition.h +++ b/src/MapleFE/ast2cpp/include/cpp_definition.h @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/ast2cpp/include/cpp_emitter.h b/src/MapleFE/ast2cpp/include/cpp_emitter.h index 601d341cd85340c407824d8d353017967b6e59ca..74d81734fdf2746d8b6853074ccabc0cf39d7ef1 100644 --- a/src/MapleFE/ast2cpp/include/cpp_emitter.h +++ b/src/MapleFE/ast2cpp/include/cpp_emitter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/ast2cpp/include/emitter.h b/src/MapleFE/ast2cpp/include/emitter.h index 99046a87056031f271c8d74c913dd23bad6ea2ad..7ad2b1e895eccb8911887cf04aa5a5431ea06007 100644 --- a/src/MapleFE/ast2cpp/include/emitter.h +++ b/src/MapleFE/ast2cpp/include/emitter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/ast2cpp/include/helper.h b/src/MapleFE/ast2cpp/include/helper.h index 71ae151b5fad5dc8a1d1c9f7e7607d8c718e4fe5..297d57f4070a956300db59c14899edab68cef580 100644 --- a/src/MapleFE/ast2cpp/include/helper.h +++ b/src/MapleFE/ast2cpp/include/helper.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -34,12 +34,15 @@ extern std::unordered_mapTypeIdToJSType; extern std::unordered_mapTypeIdToJSTypeCXX; extern TypeId hlpGetTypeId(TreeNode* node); extern std::string GenClassFldAddProp(std::string, std::string, std::string, std::string, std::string); -extern std::string GenFuncClass(std::string retType, std::string funcName, std::string params, std::string args); +extern std::string FunctionTemplate(std::string retType, std::string funcName, std::string params, std::string args); +extern std::string GenGeneratorClass(std::string funcName, std::vector>args); extern std::string tab(int n); extern bool IsClassMethod(TreeNode* node); extern std::string GetClassOfAssignedFunc(TreeNode* node); extern std::string GenAnonFuncName(TreeNode* node); inline std::string ClsName(std::string func) { return "Cls_"s + func; } +inline std::string GeneratorName(std::string func) { return "Generator_"s + func; } +inline std::string GeneratorFuncName(std::string func) { return "GeneratorFunc_"s + func; } extern void HandleThisParam(unsigned nParams, TreeNode* node, std::string& params, std::string&args); extern std::string hlpGetJSValTypeStr(TypeId typeId); extern std::string ArrayCtorName(int dim, std::string type); @@ -51,6 +54,9 @@ private: std::set ImportedFields; std::set StaticMembers; + // map of FunctionNode node id to vector of function arg info (pair of arg type and name) + std::unordered_map>> args; + public: FuncTable() {} ~FuncTable() {} @@ -93,6 +99,15 @@ public: bool IsStaticMember(std::string& field) { return(StaticMembers.find(field) != StaticMembers.end()); } + + // Function arg info + void AddArgInfo(unsigned nodeId, std::string type, std::string name) { + args[nodeId].push_back(std::pair(type, name)); + } + std::vector> GetArgInfo(unsigned nodeId) { + return args[nodeId]; + } + }; extern FuncTable hFuncTable; diff --git a/src/MapleFE/ast2cpp/runtime/include/builtins.h b/src/MapleFE/ast2cpp/runtime/include/builtins.h index d5aa30f5ec7827faa994092f19701ec5357f0595..8acac0e030cdd30ce4605930dec3629cac8ddc83 100644 --- a/src/MapleFE/ast2cpp/runtime/include/builtins.h +++ b/src/MapleFE/ast2cpp/runtime/include/builtins.h @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -162,8 +162,8 @@ public: IteratorProto(Function* ctor, Object* proto) : Object(ctor, proto) { } ~IteratorProto() { } // note: the arg on an iterator's 1st next() call is ignored per spec 27.5.1.2 - virtual IteratorResult _next(JS_Val* arg) { return IteratorResult(); } - virtual IteratorResult _return(JS_Val* val) { return IteratorResult(); } + virtual IteratorResult _next (JS_Val* arg = nullptr) { return IteratorResult(); } + virtual IteratorResult _return(JS_Val* val = nullptr) { return IteratorResult(); } virtual IteratorResult _throw(Error exception) { return IteratorResult(); } // TODO: %IteratorPrototype%[Symbol.iterator]() = this (current iterator instance) @@ -181,7 +181,15 @@ public: void* _yield = nullptr; // pointer to yield label to resume execution bool _finished = false; // flag if generator is in finished state bool _firstNext = true; // flag if first next has been called on iterator (27.5.1.2) - JS_Val _retval = undefined; // save optional arg from iterator's return(arg) method + + IteratorResult _return(JS_Val* arg = nullptr) override { + IteratorResult res; + _finished = true; + if (arg != nullptr) { + res._value = *arg; + } + return res; + } }; // 27.3.1 GeneratorFunction Constructor diff --git a/src/MapleFE/ast2cpp/runtime/include/ts2cpp.h b/src/MapleFE/ast2cpp/runtime/include/ts2cpp.h index 5318a3c22fe48126c78948382ca4963b6c6882d2..c94ea6fd2d282526fd2e10f8fea0dde29a300334 100644 --- a/src/MapleFE/ast2cpp/runtime/include/ts2cpp.h +++ b/src/MapleFE/ast2cpp/runtime/include/ts2cpp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/ast2cpp/src/a2c_util.cpp b/src/MapleFE/ast2cpp/src/a2c_util.cpp index 4b272e6859280d7968b8ff8a53d6b22318e58e66..f9bb62cadc557da43df4949d5b5d2e3702303830 100644 --- a/src/MapleFE/ast2cpp/src/a2c_util.cpp +++ b/src/MapleFE/ast2cpp/src/a2c_util.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/ast2cpp/src/cpp_declaration.cpp b/src/MapleFE/ast2cpp/src/cpp_declaration.cpp index ab6ea0c89a36f40e6ea571dc7f644487d4939c47..96a1e654b0ad4ce3770cbe39f3821cb78f2548cd 100644 --- a/src/MapleFE/ast2cpp/src/cpp_declaration.cpp +++ b/src/MapleFE/ast2cpp/src/cpp_declaration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -346,7 +346,23 @@ std::string CppDecl::GenFunctionClass(FunctionNode* node) { if (node->GetParamsNum() == 0) HandleThisParam(0, nullptr, params, args); - return GenFuncClass(GetTypeString(node->GetType(), nullptr), GetIdentifierName(node), params, args); + return FunctionTemplate(GetTypeString(node->GetType(), nullptr), GetIdentifierName(node), params, args); +} + +void CppDecl::CollectFuncArgInfo(TreeNode* node) { + if (!node->IsFunction()) + return; + + FunctionNode* func = static_cast(node); + for (unsigned i = 0; i < func->GetParamsNum(); ++i) { + if (auto n = func->GetParam(i)) { + // build vector of string pairs of argument types and names + std::string name = GetIdentifierName(n); + std::string type = GetTypeString(n, n->IsIdentifier()? static_cast(n)->GetType(): nullptr); + type.erase(type.find_last_not_of(' ')+1); // strip trailing spaces + hFuncTable.AddArgInfo(func->GetNodeId(), type, name); + } + } } std::string CppDecl::EmitModuleNode(ModuleNode *node) { @@ -388,19 +404,25 @@ namespace )""" + module + R"""( { CfgFunc *func = mod->GetNestedFuncAtIndex(i); TreeNode *node = func->GetFuncNode(); if (!IsClassMethod(node)) { + bool isGenerator = static_cast(node)->IsGenerator(); + CollectFuncArgInfo(node); std::string ns = GetNamespace(node); if (!ns.empty()) str += "namespace "s + ns + " {\n"s; - str += GenFunctionClass(static_cast(node)); // gen func cls for each top level func + if (isGenerator) + str += GenGeneratorClass(GetIdentifierName(node), hFuncTable.GetArgInfo(node->GetNodeId())); + else + str += GenFunctionClass(static_cast(node)); // gen func cls for each top level func if (!mHandler->IsFromLambda(node)) { // top level funcs instantiated here as function objects from their func class // top level lamda funcs instantiated later in assignment stmts - std::string funcinit = ClsName(node->GetName()) + "* "s + node->GetName() + " = new "s + ClsName(node->GetName()) + "();\n"s; + std::string typeName = isGenerator? GeneratorFuncName(node->GetName()): ClsName(node->GetName()); + std::string funcinit = typeName + "* "s + node->GetName() + " = new "s + typeName + "();\n"s; if (ns.empty()) AddDefinition(funcinit); else AddDefinition("namespace "s + ns + " {\n"s + funcinit + "\n}\n"s); - str += "extern "s + ClsName(node->GetName()) + "* "s + node->GetName() + ";\n"s; + str += "extern "s + typeName + "* "s + node->GetName() + ";\n"s; } if (!ns.empty()) str += "\n} // namespace " + ns + '\n'; @@ -684,6 +706,11 @@ std::string CppDecl::GetTypeString(TreeNode *node, TreeNode *child) { if (str != "none"s) return str + " "s; } + if (mHandler->IsGeneratorUsed(node->GetNodeId())) { + // check if generator type + if (auto func = mHandler->GetGeneratorUsed(node->GetNodeId())) + return GeneratorName(GetIdentifierName(func)) + "*"s; + } } return "t2crt::JS_Val "s; } diff --git a/src/MapleFE/ast2cpp/src/cpp_definition.cpp b/src/MapleFE/ast2cpp/src/cpp_definition.cpp index f8d5691caffa58373b68a748f38d1f4abc2110a1..6ac4cfd41551455954c094d2a829b45992f6f6e9 100644 --- a/src/MapleFE/ast2cpp/src/cpp_definition.cpp +++ b/src/MapleFE/ast2cpp/src/cpp_definition.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/ast2cpp/src/cpp_emitter.cpp b/src/MapleFE/ast2cpp/src/cpp_emitter.cpp index ba77a9c75c7426bfff3a90d19ebe10b36612825e..ab730ccb84fc15d9f1f607c160f8bddd81f275db 100644 --- a/src/MapleFE/ast2cpp/src/cpp_emitter.cpp +++ b/src/MapleFE/ast2cpp/src/cpp_emitter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/ast2cpp/src/emitter.cpp b/src/MapleFE/ast2cpp/src/emitter.cpp index 5de29d991dc6f1556651d74fe0fbdc115bd62373..e4926858fae238e405496ce4a490d8e76b6d6703 100644 --- a/src/MapleFE/ast2cpp/src/emitter.cpp +++ b/src/MapleFE/ast2cpp/src/emitter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. + * Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/ast2cpp/src/helper.cpp b/src/MapleFE/ast2cpp/src/helper.cpp index 281e3558b85c392e5bd83b10641316d8ec561d24..5ee7e1b5f90db1160d66573baa814b8228c9af0f 100644 --- a/src/MapleFE/ast2cpp/src/helper.cpp +++ b/src/MapleFE/ast2cpp/src/helper.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -108,9 +108,9 @@ std::string GenClassFldAddProp(std::string objName, // for ctor(), it calls _body() but ignores return val from _body(), and instead returns _this // per TS/JS spec. -std::string GenFuncClass(std::string retType, std::string funcName, std::string params, std::string args) { +std::string FunctionTemplate(std::string retType, std::string funcName, std::string params, std::string args) { std::string str; - std::string clsName = "Cls_" + funcName; + std::string clsName = ClsName(funcName); std::string functorArgs = args; std::string functorParams = params; std::string thisType; @@ -146,6 +146,70 @@ class )""" + clsName + R"""( : public t2crt::Function { return str; } +// Template for generating Generators and Generator Functions: +// For each TS generator function, 2 C++ classes: generator and generator function are emitted. +// The generator function has only a single instance. It is called to create generator instances. +std::string GenGeneratorClass(std::string funcName, std::vector> args) { + std::string str; + std::string generatorName = GeneratorName(funcName); + std::string generatorFuncName = GeneratorFuncName(funcName); + + // Different formats of arg list as needed by generator and generator function interfaces: + // - args for function class functor and generation class constructor + // () - generator class constructor field init list + // & - args passed by reference to generation function _body method + // ; - generator class fields for capturing closure + std::string functorArgs, ctorArgs, refArgs, initList, captureFields; + + for (bool hasArg=false; auto elem : args) { + if (!hasArg) + hasArg = true; + else { + functorArgs += ", "s; + refArgs += ", "s; + initList += ", "s; + } + std::string type = elem.first, name = elem.second; + functorArgs += type + " " + name; + refArgs += type + "& "+ name; + initList += name + "("s+ name + ")"s; + captureFields += tab(1) + type + " " + name + ";\n"s; + } + if (!refArgs.empty()) + refArgs = ", " + refArgs; + if (!initList.empty()) + initList = ", " + initList; + ctorArgs = functorArgs.empty()? std::string(): (", "s + functorArgs); + + str = R"""( +// )""" + funcName + R"""( generators +class )""" + generatorName + R"""( : public t2crt::GeneratorProto { +public: + )""" + generatorName + R"""((t2crt::Function* ctor, t2crt::Object* proto)""" + ctorArgs + R"""() : t2crt::GeneratorProto(ctor, proto))""" + initList + R"""( {} + ~)""" + generatorName + R"""(() {} + + // closure capture fields +)""" + captureFields + R"""( + // iterator interface (override _return and _throw when needed) + t2crt::IteratorResult _next(t2crt::JS_Val* arg) override; +}; + +// )""" + funcName + R"""( generator function +class )""" + generatorFuncName + R"""( : public t2crt::GeneratorFuncPrototype { +public: + )""" + generatorFuncName + R"""(() : t2crt::GeneratorFuncPrototype(&t2crt::GeneratorFunction, &t2crt::Generator, t2crt::GeneratorPrototype) {} + ~)""" + generatorFuncName + R"""(() {} + + // call operator returns generator instances + )""" + generatorName + R"""(* operator()()""" + functorArgs + R"""(); + // generator function body + t2crt::IteratorResult _body(t2crt::Object* _this, void*& yield)""" + refArgs + R"""(); +}; + +)"""; + return str; +} + bool IsClassMethod(TreeNode* node) { return(node->IsFunction() && node->GetParent() && node->GetParent()->IsClass()); } diff --git a/src/MapleFE/astopt/include/ast_adj.h b/src/MapleFE/astopt/include/ast_adj.h index 5674e6678dab4f008ff0bc19db9230f9d44307c9..36675d91eb0d6004051f5d04c2518db280fe7337 100644 --- a/src/MapleFE/astopt/include/ast_adj.h +++ b/src/MapleFE/astopt/include/ast_adj.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/astopt/include/ast_handler.h b/src/MapleFE/astopt/include/ast_handler.h index fdeaa249df760cbcc02d81d69024506f6049a036..42153f013fb46b771480e7cba2c63a86480d7f76 100644 --- a/src/MapleFE/astopt/include/ast_handler.h +++ b/src/MapleFE/astopt/include/ast_handler.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -252,7 +252,7 @@ class Module_Handler { void AddGeneratorUsed(unsigned nid, FunctionNode *func); bool IsGeneratorUsed(unsigned nid); FunctionNode *GetGeneratorUsed(unsigned nid); - void UpdateGeneratorUsed(unsigned target, unsigned src); + bool UpdateGeneratorUsed(unsigned target, unsigned src); // API to check a node is c++ field which satisfy both: // 1. direct field diff --git a/src/MapleFE/astopt/include/ast_info.h b/src/MapleFE/astopt/include/ast_info.h index e94aeaf2245dc0befd92d3853958b8f5d56ca37b..4753f50dace00bff128a2e2753bec54cd5d5773f 100644 --- a/src/MapleFE/astopt/include/ast_info.h +++ b/src/MapleFE/astopt/include/ast_info.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -46,6 +46,7 @@ class AST_INFO { std::unordered_set mWithTypeParamNodeSet; std::unordered_set mWithThisFuncSet;; std::unordered_set mFromLambda; + std::unordered_map mStrIdx2TypeIdxMap; void AddField(unsigned nid, TreeNode *node); @@ -106,6 +107,11 @@ class AST_INFO { void AddFromLambda(unsigned nid) { mFromLambda.insert(nid); } bool IsFromLambda(unsigned nid) { return mFromLambda.find(nid) != mFromLambda.end(); } + + void AddBuiltInTypes(); + bool IsBuiltInType(TreeNode *node); + unsigned GetBuiltInTypeIdx(unsigned stridx); + unsigned GetBuiltInTypeIdx(TreeNode *node); }; class FillNodeInfoVisitor : public AstVisitor { diff --git a/src/MapleFE/astopt/include/ast_scp.h b/src/MapleFE/astopt/include/ast_scp.h index ba864fdd5788cf3b91c6d6a3e40933d7edd5b12c..fd2dcb485df20f92f96bb929b1b4fc31c5662012 100644 --- a/src/MapleFE/astopt/include/ast_scp.h +++ b/src/MapleFE/astopt/include/ast_scp.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/astopt/include/ast_ti.h b/src/MapleFE/astopt/include/ast_ti.h index a569b4d7a4bad13e09a6e399f69cdcf478d4e04d..ece38d68dcbe7e6257562c68bfc23f37383b231b 100644 --- a/src/MapleFE/astopt/include/ast_ti.h +++ b/src/MapleFE/astopt/include/ast_ti.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/astopt/src/ast_adj.cpp b/src/MapleFE/astopt/src/ast_adj.cpp index 3a36e80d0fe0de7b765e0e6de151fffd46c0cc19..d7015ef214abb17ceabce1118442277c042c16e6 100644 --- a/src/MapleFE/astopt/src/ast_adj.cpp +++ b/src/MapleFE/astopt/src/ast_adj.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/astopt/src/ast_handler.cpp b/src/MapleFE/astopt/src/ast_handler.cpp index 205cb110c67743b98ad8bdd926e985db9ec55110..d08f7415070c5c5908d0d876d002fec026d97733 100644 --- a/src/MapleFE/astopt/src/ast_handler.cpp +++ b/src/MapleFE/astopt/src/ast_handler.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -302,10 +302,12 @@ FunctionNode *Module_Handler::GetGeneratorUsed(unsigned nid) { return NULL; } -void Module_Handler::UpdateGeneratorUsed(unsigned target, unsigned src) { +bool Module_Handler::UpdateGeneratorUsed(unsigned target, unsigned src) { if (mGeneratorUsedMap.find(src) != mGeneratorUsedMap.end()) { mGeneratorUsedMap[target] = mGeneratorUsedMap[src]; + return true; } + return false; } bool Module_Handler::IsFromLambda(TreeNode *node) { diff --git a/src/MapleFE/astopt/src/ast_info.cpp b/src/MapleFE/astopt/src/ast_info.cpp index 81c9dfd12a1d888ab2cc13fc1c14438b8e04119d..e841e0d65a0c061c6c4ee9df7481a9b74f4b654b 100644 --- a/src/MapleFE/astopt/src/ast_info.cpp +++ b/src/MapleFE/astopt/src/ast_info.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -32,6 +32,8 @@ void AST_INFO::CollectInfo() { it->SetParent(module); } + AddBuiltInTypes(); + // collect import/export info MSGNOLOC0("============== XXport info =============="); mHandler->GetASTXXport()->CollectXXportInfo(mHandler->GetHidx()); @@ -67,6 +69,32 @@ void AST_INFO::CollectInfo() { visitor.Visit(module); } +void AST_INFO::AddBuiltInTypes() { + // add language builtin types + TreeNode *node = NULL; +#define BUILTIN(T) \ + node = gTypeTable.CreateBuiltinType(#T, TY_Class);\ + gTypeTable.AddType(node);\ + mStrIdx2TypeIdxMap[node->GetStrIdx()] = node->GetTypeIdx(); +#include "lang_builtin.def" +} + +bool AST_INFO::IsBuiltInType(TreeNode *node) { + return mStrIdx2TypeIdxMap.find(node->GetStrIdx()) != mStrIdx2TypeIdxMap.end(); +} + +unsigned AST_INFO::GetBuiltInTypeIdx(unsigned stridx) { + if (mStrIdx2TypeIdxMap.find(stridx) != mStrIdx2TypeIdxMap.end()) { + return mStrIdx2TypeIdxMap[stridx]; + } + return 0; +} + +unsigned AST_INFO::GetBuiltInTypeIdx(TreeNode *node) { + unsigned stridx = node->GetStrIdx(); + return GetBuiltInTypeIdx(stridx); +} + TypeId AST_INFO::GetTypeId(TreeNode *node) { return node->GetTypeId(); } @@ -394,8 +422,10 @@ IdentifierNode *AST_INFO::CreateIdentifierNode(unsigned stridx) { } UserTypeNode *AST_INFO::CreateUserTypeNode(unsigned stridx, ASTScope *scope) { + unsigned tidx = GetBuiltInTypeIdx(stridx); IdentifierNode *node = CreateIdentifierNode(stridx); SetTypeId(node, TY_Class); + SetTypeIdx(node, tidx); if (scope) { node->SetScope(scope); } @@ -404,6 +434,7 @@ UserTypeNode *AST_INFO::CreateUserTypeNode(unsigned stridx, ASTScope *scope) { utype->SetId(node); utype->SetStrIdx(stridx); SetTypeId(utype, TY_Class); + SetTypeIdx(utype, tidx); node->SetParent(utype); return utype; } @@ -638,6 +669,11 @@ FunctionNode *FillNodeInfoVisitor::VisitFunctionNode(FunctionNode *node) { if (type) { mInfo->SetTypeId(node, type->GetTypeId()); mInfo->SetTypeIdx(node, type->GetTypeIdx()); + } else if (node->IsGenerator()) { + unsigned stridx = gStringPool.GetStrIdx("Generator"); + unsigned tidx = mInfo->GetBuiltInTypeIdx(stridx); + UserTypeNode *ut = mInfo->CreateUserTypeNode(stridx); + node->SetType(ut); } return node; } @@ -700,8 +736,16 @@ PrimTypeNode *FillNodeInfoVisitor::VisitPrimTypeNode(PrimTypeNode *node) { UserTypeNode *FillNodeInfoVisitor::VisitUserTypeNode(UserTypeNode *node) { (void) AstVisitor::VisitUserTypeNode(node); TreeNode *id = node->GetId(); - if (id && !id->IsTypeIdNone()) { - mInfo->SetTypeId(node, id->GetTypeId()); + if (id) { + unsigned tidx = mInfo->GetBuiltInTypeIdx(id); + if (tidx) { + mInfo->SetTypeId(id, TY_Class); + mInfo->SetTypeIdx(id, tidx); + } + if (!id->IsTypeIdNone()) { + mInfo->SetTypeId(node, id->GetTypeId()); + mInfo->SetTypeIdx(node, id->GetTypeIdx()); + } } return node; } diff --git a/src/MapleFE/astopt/src/ast_scp.cpp b/src/MapleFE/astopt/src/ast_scp.cpp index a1473f8a744ae4131a396f120c95dde9b3433ea3..9179704ab7e33a937ccc8b436abd125fe2d06911 100644 --- a/src/MapleFE/astopt/src/ast_scp.cpp +++ b/src/MapleFE/astopt/src/ast_scp.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/astopt/src/ast_ti.cpp b/src/MapleFE/astopt/src/ast_ti.cpp index d69b053d62d0877b86ec92335343e3657c2cec12..22706289ed7bda7a3ff2fc87224962a9d16fc330 100644 --- a/src/MapleFE/astopt/src/ast_ti.cpp +++ b/src/MapleFE/astopt/src/ast_ti.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -31,6 +31,7 @@ void TypeInfer::TypeInference() { ModuleNode *module = mHandler->GetASTModule(); if (mFlags & FLG_trace_3) { + gStringPool.Dump(); gTypeTable.Dump(); } @@ -133,7 +134,7 @@ FieldLiteralNode *BuildIdDirectFieldVisitor::VisitFieldLiteralNode(FieldLiteralN IdentifierNode *field = static_cast(name); TreeNode *decl = mHandler->FindDecl(field); TreeNode *vtype = GetParentVarClass(decl); - if (vtype) { + if (vtype && !mHandler->GetINFO()->IsBuiltInType(vtype)) { // check if decl is a field of vtype // note: vtype could be in different module Module_Handler *h = mHandler->GetModuleHandler(vtype); @@ -1256,6 +1257,7 @@ DeclNode *TypeInferVisitor::VisitDeclNode(DeclNode *node) { TypeId elemTypeId = TY_None; unsigned elemTypeIdx = 0; bool isArray = false; + bool isFromGenerator = false; if (init) { merged = MergeTypeId(merged, init->GetTypeId()); mergedtidx = MergeTypeIdx(mergedtidx, init->GetTypeIdx()); @@ -1264,14 +1266,20 @@ DeclNode *TypeInferVisitor::VisitDeclNode(DeclNode *node) { elemTypeIdx = GetArrayElemTypeIdx(init); isArray = (elemTypeId != TY_None); // pass IsGeneratorUsed - mHandler->UpdateGeneratorUsed(node->GetNodeId(), init->GetNodeId()); - if (var) { + isFromGenerator = mHandler->UpdateGeneratorUsed(node->GetNodeId(), init->GetNodeId()); + if (var && isFromGenerator) { mHandler->UpdateGeneratorUsed(var->GetNodeId(), init->GetNodeId()); } } if (var) { // normal cases if(var->IsIdentifier()) { + IdentifierNode *idvar = static_cast(var); + if (isFromGenerator && !idvar->GetType()) { + unsigned stridx = gStringPool.GetStrIdx("Generator"); + UserTypeNode *ut = mInfo->CreateUserTypeNode(stridx, var->GetScope()); + idvar->SetType(ut); + } merged = MergeTypeId(merged, var->GetTypeId()); mergedtidx = MergeTypeIdx(mergedtidx, var->GetTypeIdx()); bool isFunc = UpdateVarTypeWithInit(var, init); @@ -1557,8 +1565,10 @@ IdentifierNode *TypeInferVisitor::VisitIdentifierNode(IdentifierNode *node) { TreeNode *uptype = gTypeTable.GetTypeFromTypeIdx(upper->GetTypeIdx()); if (uptype) { scope = uptype->GetScope(); - node->SetScope(scope); - decl = mHandler->FindDecl(node, true); + if (scope) { + node->SetScope(scope); + decl = mHandler->FindDecl(node, true); + } } } else { NOTYETIMPL("node not in field"); @@ -1719,10 +1729,12 @@ ReturnNode *TypeInferVisitor::VisitReturnNode(ReturnNode *node) { type->SetPrimType(TY_None); func->SetType(type); } - UpdateFuncRetTypeId(func, node->GetTypeId(), node->GetTypeIdx()); - if (res) { - // use res to update function's return type - UpdateTypeUseNode(func->GetType(), res); + if (!func->IsGenerator() && !func->IsIterator()) { + UpdateFuncRetTypeId(func, node->GetTypeId(), node->GetTypeIdx()); + if (res) { + // use res to update function's return type + UpdateTypeUseNode(func->GetType(), res); + } } } return node; diff --git a/src/MapleFE/astopt/src/ast_xxport.cpp b/src/MapleFE/astopt/src/ast_xxport.cpp index 43e28d11735ba302410b7119e846d659b049cc58..3b828851ba70dbec2137c069b8d0b647e1f34ca0 100644 --- a/src/MapleFE/astopt/src/ast_xxport.cpp +++ b/src/MapleFE/astopt/src/ast_xxport.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/c/include/lang_builtin.def b/src/MapleFE/c/include/lang_builtin.def new file mode 100644 index 0000000000000000000000000000000000000000..8c127c72a426bb6113253cdf59a103a11785e8fb --- /dev/null +++ b/src/MapleFE/c/include/lang_builtin.def @@ -0,0 +1,14 @@ +// Copyright (C) [2022] Futurewei Technologies, Inc. All rights reverved. +// +// OpenArkFE is licensed under the Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// +// http://license.coscl.org.cn/MulanPSL2 +// +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +// FIT FOR A PARTICULAR PURPOSE. +// See the Mulan PSL v2 for more details. +// + diff --git a/src/MapleFE/docs/builtin-constructors.md b/src/MapleFE/docs/builtin-constructors.md new file mode 100644 index 0000000000000000000000000000000000000000..b38060c8add67af8b593b04c5294ecb66a0f55e2 --- /dev/null +++ b/src/MapleFE/docs/builtin-constructors.md @@ -0,0 +1,95 @@ + +## JavaScript built-in objects + +JavaScript built-in object info is available at: + +### 1. ECMA-262 standard +https://262.ecma-international.org/12.0/#sec-ecmascript-standard-built-in-objects +``` +Under sections: + 19 The Global Object + 20 Fundamental Objects + 21 Numbers and Dates + 22 Text Processing + 23 Indexed Collections + 24 Keyed Collections + 25 Structured Data +``` + +### 2. Mozilla Developer docs +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference under Built-in objects + +## JavaScript built-in object constructors + +Not all built-in objects work as object constructors. The following is a list of +JavaScript built-in objects that works as object constructors to create objects +of corresponding built-in type: + +## List of JavaScript built-in object constructors +``` + 1 AggregateError + 2 Array + 3 ArrayBuffer + 4 AsyncFunction + 5 BigInt64Array + 6 BigUint64Array + 7 Boolean + 8 DataView + 9 Date + 10 Error + 11 EvalError + 12 FinalizationRegistry + 13 Float32Array + 14 Float64Array + 15 Function + 16 Generator + 17 GeneratorFunction + 18 Int16Array + 19 Int32Array + 20 Int8Array + 21 InternalError (Mozilla only) + 22 Map + 23 Math + 24 Number + 25 Object + 26 Promise + 27 Proxy + 28 RangeError + 29 ReferenceError + 30 RegExp + 31 Set + 32 SharedArrayBuffer + 33 String + 34 Symbol + 35 SyntaxError + 36 TypeError + 37 Uint16Array + 38 Uint32Array + 39 Uint8Array + 40 Uint8ClampedArray + 41 URIError + 42 WeakMap + 43 WeakRef + 44 WeakSet +``` + +## TypeScript types + +Additionally these TypeScript types will be treated as built-in object types too: +- Record +- Tuple +- Iterable +- Iterator + +### 1. Record and Tuple types +Record and Tuple currently are TypeScript only types. They are +not ECMA-262 standard yet, but has been proposed and undergoing standardization. + +- https://tc39.es/proposal-record-tuple +- https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types +- https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type + +### 2. Iterable and Iterator types +These are TypeScript types +- https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-6.html#stricter-generators +- https://www.typescriptlang.org/docs/handbook/iterators-and-generators.html#iterable-interface diff --git a/src/MapleFE/java/include/lang_builtin.def b/src/MapleFE/java/include/lang_builtin.def new file mode 100644 index 0000000000000000000000000000000000000000..8c127c72a426bb6113253cdf59a103a11785e8fb --- /dev/null +++ b/src/MapleFE/java/include/lang_builtin.def @@ -0,0 +1,14 @@ +// Copyright (C) [2022] Futurewei Technologies, Inc. All rights reverved. +// +// OpenArkFE is licensed under the Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// +// http://license.coscl.org.cn/MulanPSL2 +// +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +// FIT FOR A PARTICULAR PURPOSE. +// See the Mulan PSL v2 for more details. +// + diff --git a/src/MapleFE/shared/include/ast.h b/src/MapleFE/shared/include/ast.h index 6c3dd0640c28e00e203d47e81d2a71bdf93d62a6..58d327ce4fc805b2834e182011b870f95f73f99f 100644 --- a/src/MapleFE/shared/include/ast.h +++ b/src/MapleFE/shared/include/ast.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/include/ast_module.h b/src/MapleFE/shared/include/ast_module.h index adc2467ed391487625af9536b1262220d7a8ec90..58e6b19e1a0289949de47e4911f4ccc071203648 100644 --- a/src/MapleFE/shared/include/ast_module.h +++ b/src/MapleFE/shared/include/ast_module.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/include/ast_nk.def b/src/MapleFE/shared/include/ast_nk.def index 57c1e2b35160cbde4d5c732c3a0a3659d444c664..df99869326ebf7eb81550f2a848277d7d739c885 100644 --- a/src/MapleFE/shared/include/ast_nk.def +++ b/src/MapleFE/shared/include/ast_nk.def @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/include/ast_type.h b/src/MapleFE/shared/include/ast_type.h index 89254ee2402a7d2e9bb943b14da7362dffea9f31..d120eafa87e479250a90ad64622fc82126e45fbc 100644 --- a/src/MapleFE/shared/include/ast_type.h +++ b/src/MapleFE/shared/include/ast_type.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/include/lexer.h b/src/MapleFE/shared/include/lexer.h index 380d8ed41bed256c18b28a3ef4090e7e8f790096..151f55b258b5ebb5e8a6c92faecead47c5edb363 100644 --- a/src/MapleFE/shared/include/lexer.h +++ b/src/MapleFE/shared/include/lexer.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/include/parser.h b/src/MapleFE/shared/include/parser.h index 2e35ad570c88f072b52e47883b5dcf6494548c2a..a747c23656ba23838301a06b86ad6ed762098a68 100644 --- a/src/MapleFE/shared/include/parser.h +++ b/src/MapleFE/shared/include/parser.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/include/ruletable.h b/src/MapleFE/shared/include/ruletable.h index f9d7d20c4ea419bc32b2945b85f6e52ba6bd196c..2464e7c6eaaafaf414c2420b5780d9f3a72e63e7 100644 --- a/src/MapleFE/shared/include/ruletable.h +++ b/src/MapleFE/shared/include/ruletable.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/include/stringpool.h b/src/MapleFE/shared/include/stringpool.h index db2efeee63bdc5fc86f6118a1bfebe4b74167672..259e33e6209f4e48f58465f7c7ba4ef7b7cc5cb7 100644 --- a/src/MapleFE/shared/include/stringpool.h +++ b/src/MapleFE/shared/include/stringpool.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -75,6 +75,8 @@ public: MASSERT(idx < mStringTable.size() && "string index out of range"); return mStringTable[idx]; } + + void Dump(); }; // Lexing, Parsing, AST Building and IR Building all share one global diff --git a/src/MapleFE/shared/include/supported_types.def b/src/MapleFE/shared/include/supported_types.def index b2f6159eb850fb941cc84f707eebc5fe87cd711f..c16bd4a934d49783017babb74231ece08d02a74d 100644 --- a/src/MapleFE/shared/include/supported_types.def +++ b/src/MapleFE/shared/include/supported_types.def @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/include/token.h b/src/MapleFE/shared/include/token.h index d9132cc681c720cf5948a5a58ab9be945e9157d8..f2406ee14ead46ea4581bf5a584ed6531026a84a 100644 --- a/src/MapleFE/shared/include/token.h +++ b/src/MapleFE/shared/include/token.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/include/typetable.h b/src/MapleFE/shared/include/typetable.h index fa63b6548222b875d2be4f9b48741cbe6d5e917d..2817fadd4efbb22a9dd34536abdabc411f503f5d 100644 --- a/src/MapleFE/shared/include/typetable.h +++ b/src/MapleFE/shared/include/typetable.h @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/src/ast_module.cpp b/src/MapleFE/shared/src/ast_module.cpp index 0d4c7e830a6b675c003efeceffb646c14449fe5d..9cab6e95aaf3856b52ef1283fdef66b794d7a798 100644 --- a/src/MapleFE/shared/src/ast_module.cpp +++ b/src/MapleFE/shared/src/ast_module.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/src/ast_scope.cpp b/src/MapleFE/shared/src/ast_scope.cpp index fc907786e9527c1285954eaab705319b3d4527c1..7441ddac5ef88164751bc1e475463b9ff510dbc7 100644 --- a/src/MapleFE/shared/src/ast_scope.cpp +++ b/src/MapleFE/shared/src/ast_scope.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/src/ast_type.cpp b/src/MapleFE/shared/src/ast_type.cpp index 3a4d3774689e67efed66ebdde1262c2c29d14240..48744a1850407b0574586ad28d1e4eb1a7da73e7 100644 --- a/src/MapleFE/shared/src/ast_type.cpp +++ b/src/MapleFE/shared/src/ast_type.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/src/lexer.cpp b/src/MapleFE/shared/src/lexer.cpp index 89460e331b044f22a6fc028693afeb9381ff4ccc..ccd8a5a2550bfde4a62a4a98b4df4660e8a2d61f 100644 --- a/src/MapleFE/shared/src/lexer.cpp +++ b/src/MapleFE/shared/src/lexer.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/src/parser.cpp b/src/MapleFE/shared/src/parser.cpp index a4736a6b939ec4848b4ce63e942e7d5335de24cf..12e8d953dc4e61a8ad5ddeb8efc18b7c7d9251a4 100644 --- a/src/MapleFE/shared/src/parser.cpp +++ b/src/MapleFE/shared/src/parser.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/src/stringpool.cpp b/src/MapleFE/shared/src/stringpool.cpp index 63b957481f4b6d1d8ae9bcfbacae7921a341185e..1c96f4553e687943d4a866b4be67693bcb9dc7ab 100644 --- a/src/MapleFE/shared/src/stringpool.cpp +++ b/src/MapleFE/shared/src/stringpool.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -172,5 +172,12 @@ unsigned StringPool::GetStrIdx(const char *str, size_t len) { s.assign(str, len); return mMap->LookupEntryFor(s)->GetStrIdx(); } + +void StringPool::Dump() { + std::cout << "===================== StringTable =====================" << std::endl; + for (unsigned idx = 1; idx < mStringTable.size(); idx++) { + std::cout << " " << idx << " : " << mStringTable[idx] << std::endl; + } +} } diff --git a/src/MapleFE/shared/src/token.cpp b/src/MapleFE/shared/src/token.cpp index 2155b3368728f4c86bd97cc54588fd6a702cec24..39b20a15fe084e9007cf60667d4b3233f7e86ce6 100644 --- a/src/MapleFE/shared/src/token.cpp +++ b/src/MapleFE/shared/src/token.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/shared/src/typetable.cpp b/src/MapleFE/shared/src/typetable.cpp index 90b0e4ac608b030c1073a273593c6fb511977483..ad58543fd809f6c4f6a31c1204ba28f853c1db07 100644 --- a/src/MapleFE/shared/src/typetable.cpp +++ b/src/MapleFE/shared/src/typetable.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2021] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2021-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. @@ -154,6 +154,7 @@ void TypeTable::Dump() { AstDump::GetEnumTypeId(tid) << " " << "(typeid " << tid << ") " << "(typeidx " << node->GetTypeIdx() << ") " << + "(stridx " << node->GetStrIdx() << ") " << "(nodeid " << node->GetNodeId() << ")" << std::endl; } std::cout << "===================== End TypeTable =====================" << std::endl; diff --git a/src/MapleFE/shared/src/vfy.cpp b/src/MapleFE/shared/src/vfy.cpp index 4f771a5a7d6267780412eb8314d8e5553b18dce3..cb03fb5439385aabf65f7bf4684633acb8c0cb85 100644 --- a/src/MapleFE/shared/src/vfy.cpp +++ b/src/MapleFE/shared/src/vfy.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. +* Copyright (C) [2020-2022] Futurewei Technologies, Inc. All rights reverved. * * OpenArkFE is licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. diff --git a/src/MapleFE/typescript/include/lang_builtin.def b/src/MapleFE/typescript/include/lang_builtin.def new file mode 100644 index 0000000000000000000000000000000000000000..3b529b2cbb3922b4cb24343f2f10422991afe1ee --- /dev/null +++ b/src/MapleFE/typescript/include/lang_builtin.def @@ -0,0 +1,67 @@ +// Copyright (C) [2022] Futurewei Technologies, Inc. All rights reverved. +// +// OpenArkFE is licensed under the Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// +// http://license.coscl.org.cn/MulanPSL2 +// +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +// FIT FOR A PARTICULAR PURPOSE. +// See the Mulan PSL v2 for more details. +// + +// refer to docs/builtin-constructors.md + +// javascript builtin object types +BUILTIN(AggregateError) +BUILTIN(Array) +BUILTIN(ArrayBuffer) +BUILTIN(AsyncFunction) +BUILTIN(BigInt64Array) +BUILTIN(BigUint64Array) +BUILTIN(Boolean) +BUILTIN(DataView) +BUILTIN(Date) +BUILTIN(Error) +BUILTIN(EvalError) +BUILTIN(FinalizationRegistry) +BUILTIN(Float32Array) +BUILTIN(Float64Array) +BUILTIN(Function) +BUILTIN(Generator) +BUILTIN(GeneratorFunction) +BUILTIN(Int16Array) +BUILTIN(Int32Array) +BUILTIN(Int8Array) +BUILTIN(InternalError (Mozilla only)) +BUILTIN(Map) +BUILTIN(Math) +BUILTIN(Number) +BUILTIN(Object) +BUILTIN(Promise) +BUILTIN(Proxy) +BUILTIN(RangeError) +BUILTIN(ReferenceError) +BUILTIN(RegExp) +BUILTIN(Set) +BUILTIN(SharedArrayBuffer) +BUILTIN(String) +BUILTIN(Symbol) +BUILTIN(SyntaxError) +BUILTIN(TypeError) +BUILTIN(Uint16Array) +BUILTIN(Uint32Array) +BUILTIN(Uint8Array) +BUILTIN(Uint8ClampedArray) +BUILTIN(URIError) +BUILTIN(WeakMap) +BUILTIN(WeakRef) +BUILTIN(WeakSet) + +// typescript builtin object types +BUILTIN(Record) +BUILTIN(Tuple) +BUILTIN(Iterable) +BUILTIN(Iterator)