From f7a22f54fc568ea71408087db9f51464039a3072 Mon Sep 17 00:00:00 2001 From: Junyoung Cho Date: Thu, 8 Dec 2016 13:37:18 +0900 Subject: [PATCH] Apply clang-formatting --- .clang-format | 90 + src/Escargot.h | 315 ++- src/interpreter/ByteCode.cpp | 3 +- src/interpreter/ByteCode.h | 195 +- src/interpreter/ByteCodeGenerator.cpp | 27 +- src/interpreter/ByteCodeGenerator.h | 24 +- src/interpreter/ByteCodeInterpreter.cpp | 1073 ++++---- src/interpreter/ByteCodeInterpreter.h | 7 +- src/parser/CodeBlock.cpp | 17 +- src/parser/CodeBlock.h | 12 +- src/parser/Script.cpp | 3 +- src/parser/Script.h | 3 +- src/parser/ScriptParser.cpp | 55 +- src/parser/ScriptParser.h | 3 +- src/parser/ast/AST.h | 40 +- src/parser/ast/ArrayExpressionNode.h | 1 - .../ast/AssignmentExpressionBitwiseAndNode.h | 4 +- .../ast/AssignmentExpressionBitwiseOrNode.h | 4 +- .../ast/AssignmentExpressionBitwiseXorNode.h | 4 +- .../ast/AssignmentExpressionDivisionNode.h | 4 +- .../ast/AssignmentExpressionLeftShiftNode.h | 4 +- .../ast/AssignmentExpressionMinusNode.h | 4 +- src/parser/ast/AssignmentExpressionModNode.h | 4 +- .../ast/AssignmentExpressionMultiplyNode.h | 3 +- src/parser/ast/AssignmentExpressionPlusNode.h | 4 +- ...AssignmentExpressionSignedRightShiftNode.h | 4 +- .../ast/AssignmentExpressionSimpleNode.h | 4 +- ...signmentExpressionUnsignedRightShiftNode.h | 4 +- .../ast/BinaryExpressionBitwiseAndNode.h | 6 +- .../ast/BinaryExpressionBitwiseOrNode.h | 6 +- .../ast/BinaryExpressionBitwiseXorNode.h | 6 +- src/parser/ast/BinaryExpressionDivisionNode.h | 5 +- src/parser/ast/BinaryExpressionEqualNode.h | 5 +- .../ast/BinaryExpressionGreaterThanNode.h | 4 +- .../BinaryExpressionGreaterThanOrEqualNode.h | 4 +- src/parser/ast/BinaryExpressionInNode.h | 4 +- .../ast/BinaryExpressionInstanceOfNode.h | 4 +- .../ast/BinaryExpressionLeftShiftNode.h | 4 +- src/parser/ast/BinaryExpressionLessThanNode.h | 4 +- .../ast/BinaryExpressionLessThanOrEqualNode.h | 4 +- .../ast/BinaryExpressionLogicalAndNode.h | 5 +- .../ast/BinaryExpressionLogicalOrNode.h | 5 +- src/parser/ast/BinaryExpressionMinusNode.h | 5 +- src/parser/ast/BinaryExpressionModNode.h | 4 +- src/parser/ast/BinaryExpressionMultiplyNode.h | 5 +- src/parser/ast/BinaryExpressionNotEqualNode.h | 4 +- .../ast/BinaryExpressionNotStrictEqualNode.h | 4 +- src/parser/ast/BinaryExpressionPlusNode.h | 5 +- .../BinaryExpressionSignedRightShiftNode.h | 4 +- .../ast/BinaryExpressionStrictEqualNode.h | 4 +- .../BinaryExpressionUnsignedRightShiftNode.h | 4 +- src/parser/ast/BlockStatementNode.h | 5 +- src/parser/ast/BreakLabelStatementNode.h | 2 - src/parser/ast/BreakStatementNode.h | 2 - src/parser/ast/CallExpressionNode.h | 8 +- src/parser/ast/CatchClauseNode.h | 18 +- src/parser/ast/ConditionalExpressionNode.h | 10 +- src/parser/ast/ContinueLabelStatementNode.h | 2 - src/parser/ast/ContinueStatementNode.h | 2 - src/parser/ast/DeclarationNode.h | 2 +- src/parser/ast/DirectiveNode.h | 3 +- src/parser/ast/DoWhileStatementNode.h | 8 +- src/parser/ast/EmptyNode.h | 2 - src/parser/ast/EmptyStatementNode.h | 2 - src/parser/ast/ExpressionNode.h | 2 +- src/parser/ast/ExpressionStatementNode.h | 4 +- src/parser/ast/ForInStatementNode.h | 10 +- src/parser/ast/ForStatementNode.h | 14 +- src/parser/ast/FunctionDeclarationNode.h | 2 - src/parser/ast/FunctionExpressionNode.h | 4 +- src/parser/ast/FunctionNode.h | 4 +- src/parser/ast/IdentifierNode.h | 5 +- src/parser/ast/IfStatementNode.h | 16 +- src/parser/ast/LabeledStatementNode.h | 2 - src/parser/ast/LiteralNode.h | 4 +- src/parser/ast/MemberExpressionNode.h | 4 +- src/parser/ast/NewExpressionNode.h | 6 +- src/parser/ast/Node.h | 24 +- src/parser/ast/ObjectExpressionNode.h | 5 +- src/parser/ast/PatternNode.h | 2 +- src/parser/ast/ProgramNode.h | 5 +- src/parser/ast/PropertyNode.h | 6 +- src/parser/ast/RegExpLiteralNode.h | 1 - src/parser/ast/RestElementNode.h | 4 +- src/parser/ast/ReturnStatmentNode.h | 3 +- src/parser/ast/SequenceExpressionNode.h | 3 - src/parser/ast/SpreadElementNode.h | 2 +- src/parser/ast/StatementNode.h | 1 - src/parser/ast/SwitchCaseNode.h | 6 +- src/parser/ast/SwitchStatementNode.h | 8 +- src/parser/ast/ThisExpressionNode.h | 6 +- src/parser/ast/ThrowStatementNode.h | 5 +- src/parser/ast/TryStatementNode.h | 12 +- .../ast/UnaryExpressionBitwiseNotNode.h | 2 - src/parser/ast/UnaryExpressionDeleteNode.h | 4 +- .../ast/UnaryExpressionLogicalNotNode.h | 2 - src/parser/ast/UnaryExpressionMinusNode.h | 2 +- src/parser/ast/UnaryExpressionPlusNode.h | 2 +- src/parser/ast/UnaryExpressionTypeOfNode.h | 2 - src/parser/ast/UnaryExpressionVoidNode.h | 2 - .../UpdateExpressionDecrementPostfixNode.h | 5 +- .../ast/UpdateExpressionDecrementPrefixNode.h | 5 +- .../UpdateExpressionIncrementPostfixNode.h | 5 +- .../ast/UpdateExpressionIncrementPrefixNode.h | 5 +- src/parser/ast/VariableDeclarationNode.h | 4 +- src/parser/ast/VariableDeclaratorNode.h | 7 +- src/parser/ast/WhileStatementNode.h | 9 +- src/parser/esprima_cpp/esprima.cpp | 2340 ++++++++--------- src/parser/esprima_cpp/esprima.h | 9 +- src/runtime/AtomicString.cpp | 3 +- src/runtime/AtomicString.h | 37 +- src/runtime/BooleanObject.cpp | 1 - src/runtime/BooleanObject.h | 2 +- src/runtime/Context.cpp | 19 +- src/runtime/Context.h | 8 +- src/runtime/Environment.h | 17 +- src/runtime/EnvironmentRecord.cpp | 8 +- src/runtime/EnvironmentRecord.h | 33 +- src/runtime/ErrorObject.cpp | 4 +- src/runtime/ErrorObject.h | 3 +- src/runtime/ExecutionContext.h | 2 +- src/runtime/ExecutionState.cpp | 1 - src/runtime/ExecutionState.h | 3 +- src/runtime/FunctionObject.cpp | 15 +- src/runtime/FunctionObject.h | 5 +- src/runtime/GlobalObject.cpp | 13 +- src/runtime/GlobalObject.h | 3 +- src/runtime/GlobalObjectBuiltinBoolean.cpp | 7 +- src/runtime/GlobalObjectBuiltinError.cpp | 57 +- src/runtime/GlobalObjectBuiltinFunction.cpp | 19 +- src/runtime/GlobalObjectBuiltinMath.cpp | 7 +- src/runtime/GlobalObjectBuiltinNumber.cpp | 7 +- src/runtime/GlobalObjectBuiltinObject.cpp | 15 +- src/runtime/GlobalObjectBuiltinString.cpp | 7 +- src/runtime/NumberObject.cpp | 1 - src/runtime/NumberObject.h | 2 +- src/runtime/Object.cpp | 1 - src/runtime/Object.h | 11 +- src/runtime/ObjectPropertyDescriptor.h | 15 +- src/runtime/ObjectStructure.h | 16 +- src/runtime/PointerValue.h | 1 - src/runtime/PropertyName.cpp | 1 - src/runtime/PropertyName.h | 13 +- src/runtime/RopeString.cpp | 18 +- src/runtime/RopeString.h | 5 +- src/runtime/SandBox.cpp | 5 +- src/runtime/SandBox.h | 6 +- src/runtime/SmallValue.cpp | 1 - src/runtime/SmallValue.h | 25 +- src/runtime/SmallValueData.h | 2 - src/runtime/StaticStrings.cpp | 5 +- src/runtime/StaticStrings.h | 533 ++-- src/runtime/String.cpp | 68 +- src/runtime/String.h | 40 +- src/runtime/StringBuilder.cpp | 18 +- src/runtime/StringBuilder.h | 5 +- src/runtime/StringObject.cpp | 1 - src/runtime/StringObject.h | 2 +- src/runtime/StringView.h | 13 +- src/runtime/VMInstance.cpp | 2 - src/runtime/VMInstance.h | 2 +- src/runtime/Value.cpp | 116 +- src/runtime/Value.h | 58 +- src/runtime/ValueInlines.h | 10 +- src/shell/shell.cpp | 21 +- src/util/BasicString.cpp | 1 - src/util/BasicString.h | 16 +- src/util/Vector.cpp | 1 - src/util/Vector.h | 28 +- 169 files changed, 2946 insertions(+), 3074 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..bf43cfe79 --- /dev/null +++ b/.clang-format @@ -0,0 +1,90 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: true +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IndentCaseLabels: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 500 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +ReflowComments: true +SortIncludes: false +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 8 +UseTab: Never +... + diff --git a/src/Escargot.h b/src/Escargot.h index 20c40b038..2dd1c28ae 100644 --- a/src/Escargot.h +++ b/src/Escargot.h @@ -1,28 +1,28 @@ #ifndef __Escargot__ #define __Escargot__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include #include #include +#include +#include +#include +#include +#include #include +#include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -31,8 +31,8 @@ #ifndef PROFILE_MASSIF -#include #include +#include #else @@ -55,8 +55,8 @@ void GC_free_hook(void* address); #define GC_REGISTER_FINALIZER_NO_ORDER(p, f, d, of, od) GC_register_finalizer_no_order(p, f, d, of, od) -#include #include +#include #endif @@ -66,57 +66,56 @@ namespace Escargot { template class gc_malloc_allocator { public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef GC_Tp* pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef GC_Tp* pointer; typedef const GC_Tp* const_pointer; - typedef GC_Tp& reference; + typedef GC_Tp& reference; typedef const GC_Tp& const_reference; - typedef GC_Tp value_type; + typedef GC_Tp value_type; - template struct rebind { + template + struct rebind { typedef gc_malloc_allocator other; }; - gc_malloc_allocator() throw() { } - gc_malloc_allocator(const gc_malloc_allocator&) throw() { } -# if !(GC_NO_MEMBER_TEMPLATES || 0 < _MSC_VER && _MSC_VER <= 1200) + gc_malloc_allocator() throw() {} + gc_malloc_allocator(const gc_malloc_allocator&) throw() {} +#if !(GC_NO_MEMBER_TEMPLATES || 0 < _MSC_VER && _MSC_VER <= 1200) // MSVC++ 6.0 do not support member templates - template gc_malloc_allocator - (const gc_malloc_allocator&) throw() { } -# endif - ~gc_malloc_allocator() throw() { } + template + gc_malloc_allocator(const gc_malloc_allocator&) throw() {} +#endif + ~gc_malloc_allocator() throw() + { + } pointer address(reference GC_x) const { return &GC_x; } const_pointer address(const_reference GC_x) const { return &GC_x; } - // GC_n is permitted to be 0. The C++ standard says nothing about what // the return value is when GC_n == 0. GC_Tp* allocate(size_type GC_n, const void* = 0) { - return (GC_Tp *)GC_MALLOC(sizeof(GC_Tp) * GC_n); + return (GC_Tp*)GC_MALLOC(sizeof(GC_Tp) * GC_n); } // __p is not permitted to be a null pointer. - void deallocate(pointer __p, size_type GC_ATTR_UNUSED GC_n) - { GC_FREE(__p); } - - size_type max_size() const throw() - { return size_t(-1) / sizeof(GC_Tp); } - - void construct(pointer __p, const GC_Tp& __val) { new(__p) GC_Tp(__val); } + void deallocate(pointer __p, size_type GC_ATTR_UNUSED GC_n) { GC_FREE(__p); } + size_type max_size() const throw() { return size_t(-1) / sizeof(GC_Tp); } + void construct(pointer __p, const GC_Tp& __val) { new (__p) GC_Tp(__val); } void destroy(pointer __p) { __p->~GC_Tp(); } }; -template<> +template <> class gc_malloc_allocator { - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef void* pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef void* pointer; typedef const void* const_pointer; - typedef void value_type; + typedef void value_type; - template struct rebind { + template + struct rebind { typedef gc_malloc_allocator other; }; }; @@ -137,57 +136,56 @@ inline bool operator!=(const gc_malloc_allocator&, const gc_malloc_alloca template class gc_malloc_pointer_free_allocator { public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef GC_Tp* pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef GC_Tp* pointer; typedef const GC_Tp* const_pointer; - typedef GC_Tp& reference; + typedef GC_Tp& reference; typedef const GC_Tp& const_reference; - typedef GC_Tp value_type; + typedef GC_Tp value_type; - template struct rebind { + template + struct rebind { typedef gc_malloc_pointer_free_allocator other; }; - gc_malloc_pointer_free_allocator() throw() { } - gc_malloc_pointer_free_allocator(const gc_malloc_pointer_free_allocator&) throw() { } -# if !(GC_NO_MEMBER_TEMPLATES || 0 < _MSC_VER && _MSC_VER <= 1200) + gc_malloc_pointer_free_allocator() throw() {} + gc_malloc_pointer_free_allocator(const gc_malloc_pointer_free_allocator&) throw() {} +#if !(GC_NO_MEMBER_TEMPLATES || 0 < _MSC_VER && _MSC_VER <= 1200) // MSVC++ 6.0 do not support member templates - template gc_malloc_pointer_free_allocator - (const gc_malloc_pointer_free_allocator&) throw() { } -# endif - ~gc_malloc_pointer_free_allocator() throw() { } + template + gc_malloc_pointer_free_allocator(const gc_malloc_pointer_free_allocator&) throw() {} +#endif + ~gc_malloc_pointer_free_allocator() throw() + { + } pointer address(reference GC_x) const { return &GC_x; } const_pointer address(const_reference GC_x) const { return &GC_x; } - // GC_n is permitted to be 0. The C++ standard says nothing about what // the return value is when GC_n == 0. GC_Tp* allocate(size_type GC_n, const void* = 0) { - return (GC_Tp *)GC_MALLOC_ATOMIC(sizeof(GC_Tp) * GC_n); + return (GC_Tp*)GC_MALLOC_ATOMIC(sizeof(GC_Tp) * GC_n); } // __p is not permitted to be a null pointer. - void deallocate(pointer __p, size_type GC_ATTR_UNUSED GC_n) - { GC_FREE(__p); } - - size_type max_size() const throw() - { return size_t(-1) / sizeof(GC_Tp); } - - void construct(pointer __p, const GC_Tp& __val) { new(__p) GC_Tp(__val); } + void deallocate(pointer __p, size_type GC_ATTR_UNUSED GC_n) { GC_FREE(__p); } + size_type max_size() const throw() { return size_t(-1) / sizeof(GC_Tp); } + void construct(pointer __p, const GC_Tp& __val) { new (__p) GC_Tp(__val); } void destroy(pointer __p) { __p->~GC_Tp(); } }; -template<> +template <> class gc_malloc_pointer_free_allocator { - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef void* pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef void* pointer; typedef const void* const_pointer; - typedef void value_type; + typedef void value_type; - template struct rebind { + template + struct rebind { typedef gc_malloc_pointer_free_allocator other; }; }; @@ -209,61 +207,60 @@ inline bool operator!=(const gc_malloc_pointer_free_allocator&, const gc_ template class gc_malloc_ignore_off_page_allocator { public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef GC_Tp* pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef GC_Tp* pointer; typedef const GC_Tp* const_pointer; - typedef GC_Tp& reference; + typedef GC_Tp& reference; typedef const GC_Tp& const_reference; - typedef GC_Tp value_type; + typedef GC_Tp value_type; - template struct rebind { + template + struct rebind { typedef gc_malloc_ignore_off_page_allocator other; }; - gc_malloc_ignore_off_page_allocator() throw() { } - gc_malloc_ignore_off_page_allocator(const gc_malloc_ignore_off_page_allocator&) throw() { } -# if !(GC_NO_MEMBER_TEMPLATES || 0 < _MSC_VER && _MSC_VER <= 1200) + gc_malloc_ignore_off_page_allocator() throw() {} + gc_malloc_ignore_off_page_allocator(const gc_malloc_ignore_off_page_allocator&) throw() {} +#if !(GC_NO_MEMBER_TEMPLATES || 0 < _MSC_VER && _MSC_VER <= 1200) // MSVC++ 6.0 do not support member templates - template gc_malloc_ignore_off_page_allocator - (const gc_malloc_ignore_off_page_allocator&) throw() { } -# endif - ~gc_malloc_ignore_off_page_allocator() throw() { } + template + gc_malloc_ignore_off_page_allocator(const gc_malloc_ignore_off_page_allocator&) throw() {} +#endif + ~gc_malloc_ignore_off_page_allocator() throw() + { + } pointer address(reference GC_x) const { return &GC_x; } const_pointer address(const_reference GC_x) const { return &GC_x; } - // GC_n is permitted to be 0. The C++ standard says nothing about what // the return value is when GC_n == 0. GC_Tp* allocate(size_type GC_n, const void* = 0) { if (sizeof(GC_Tp) * GC_n > 1024) { - return (GC_Tp *)GC_MALLOC_IGNORE_OFF_PAGE(sizeof(GC_Tp) * GC_n); + return (GC_Tp*)GC_MALLOC_IGNORE_OFF_PAGE(sizeof(GC_Tp) * GC_n); } else { - return (GC_Tp *)GC_MALLOC(sizeof(GC_Tp) * GC_n); + return (GC_Tp*)GC_MALLOC(sizeof(GC_Tp) * GC_n); } } // __p is not permitted to be a null pointer. - void deallocate(pointer __p, size_type GC_ATTR_UNUSED GC_n) - { GC_FREE(__p); } - - size_type max_size() const throw() - { return size_t(-1) / sizeof(GC_Tp); } - - void construct(pointer __p, const GC_Tp& __val) { new(__p) GC_Tp(__val); } + void deallocate(pointer __p, size_type GC_ATTR_UNUSED GC_n) { GC_FREE(__p); } + size_type max_size() const throw() { return size_t(-1) / sizeof(GC_Tp); } + void construct(pointer __p, const GC_Tp& __val) { new (__p) GC_Tp(__val); } void destroy(pointer __p) { __p->~GC_Tp(); } }; -template<> +template <> class gc_malloc_ignore_off_page_allocator { - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef void* pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef void* pointer; typedef const void* const_pointer; - typedef void value_type; + typedef void value_type; - template struct rebind { + template + struct rebind { typedef gc_malloc_ignore_off_page_allocator other; }; }; @@ -284,61 +281,60 @@ inline bool operator!=(const gc_malloc_ignore_off_page_allocator&, const template class gc_malloc_atomic_ignore_off_page_allocator { public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef GC_Tp* pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef GC_Tp* pointer; typedef const GC_Tp* const_pointer; - typedef GC_Tp& reference; + typedef GC_Tp& reference; typedef const GC_Tp& const_reference; - typedef GC_Tp value_type; + typedef GC_Tp value_type; - template struct rebind { + template + struct rebind { typedef gc_malloc_atomic_ignore_off_page_allocator other; }; - gc_malloc_atomic_ignore_off_page_allocator() throw() { } - gc_malloc_atomic_ignore_off_page_allocator(const gc_malloc_atomic_ignore_off_page_allocator&) throw() { } -# if !(GC_NO_MEMBER_TEMPLATES || 0 < _MSC_VER && _MSC_VER <= 1200) + gc_malloc_atomic_ignore_off_page_allocator() throw() {} + gc_malloc_atomic_ignore_off_page_allocator(const gc_malloc_atomic_ignore_off_page_allocator&) throw() {} +#if !(GC_NO_MEMBER_TEMPLATES || 0 < _MSC_VER && _MSC_VER <= 1200) // MSVC++ 6.0 do not support member templates - template gc_malloc_atomic_ignore_off_page_allocator - (const gc_malloc_atomic_ignore_off_page_allocator&) throw() { } -# endif - ~gc_malloc_atomic_ignore_off_page_allocator() throw() { } + template + gc_malloc_atomic_ignore_off_page_allocator(const gc_malloc_atomic_ignore_off_page_allocator&) throw() {} +#endif + ~gc_malloc_atomic_ignore_off_page_allocator() throw() + { + } pointer address(reference GC_x) const { return &GC_x; } const_pointer address(const_reference GC_x) const { return &GC_x; } - // GC_n is permitted to be 0. The C++ standard says nothing about what // the return value is when GC_n == 0. GC_Tp* allocate(size_type GC_n, const void* = 0) { if (sizeof(GC_Tp) * GC_n > 1024) { - return (GC_Tp *)GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(sizeof(GC_Tp) * GC_n); + return (GC_Tp*)GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(sizeof(GC_Tp) * GC_n); } else { - return (GC_Tp *)GC_MALLOC_ATOMIC(sizeof(GC_Tp) * GC_n); + return (GC_Tp*)GC_MALLOC_ATOMIC(sizeof(GC_Tp) * GC_n); } } // __p is not permitted to be a null pointer. - void deallocate(pointer __p, size_type GC_ATTR_UNUSED GC_n) - { GC_FREE(__p); } - - size_type max_size() const throw() - { return size_t(-1) / sizeof(GC_Tp); } - - void construct(pointer __p, const GC_Tp& __val) { new(__p) GC_Tp(__val); } + void deallocate(pointer __p, size_type GC_ATTR_UNUSED GC_n) { GC_FREE(__p); } + size_type max_size() const throw() { return size_t(-1) / sizeof(GC_Tp); } + void construct(pointer __p, const GC_Tp& __val) { new (__p) GC_Tp(__val); } void destroy(pointer __p) { __p->~GC_Tp(); } }; -template<> +template <> class gc_malloc_atomic_ignore_off_page_allocator { - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef void* pointer; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef void* pointer; typedef const void* const_pointer; - typedef void value_type; + typedef void value_type; - template struct rebind { + template + struct rebind { typedef gc_malloc_atomic_ignore_off_page_allocator other; }; }; @@ -355,12 +351,11 @@ inline bool operator!=(const gc_malloc_atomic_ignore_off_page_allocator&, { return false; } - } /* COMPILER() - the compiler being used to build the project */ -#define COMPILER(FEATURE) (defined COMPILER_##FEATURE && COMPILER_##FEATURE) +#define COMPILER(FEATURE) (defined COMPILER_##FEATURE && COMPILER_##FEATURE) /* COMPILER(MSVC) - Microsoft Visual C++ */ @@ -468,7 +463,7 @@ inline bool operator!=(const gc_malloc_atomic_ignore_off_page_allocator&, #include #undef ESCARGOT_LOG_INFO #undef ESCARGOT_LOG_ERROR -#define ESCARGOT_LOG_INFO(...) dlog_print(DLOG_INFO, "Escargot", __VA_ARGS__); +#define ESCARGOT_LOG_INFO(...) dlog_print(DLOG_INFO, "Escargot", __VA_ARGS__); #define ESCARGOT_LOG_ERROR(...) dlog_print(DLOG_ERROR, "Escargot", __VA_ARGS__); #endif @@ -482,7 +477,10 @@ inline bool operator!=(const gc_malloc_atomic_ignore_off_page_allocator&, #define ASSERT_STATIC(assertion, reason) #else #define ASSERT(assertion) assert(assertion); -#define ASSERT_NOT_REACHED() do { assert(false); } while (0) +#define ASSERT_NOT_REACHED() \ + do { \ + assert(false); \ + } while (0) #define ASSERT_STATIC(assertion, reason) static_assert(assertion, reason) #endif @@ -491,8 +489,18 @@ inline bool operator!=(const gc_malloc_atomic_ignore_off_page_allocator&, #define COMPILE_ASSERT(exp, name) static_assert((exp), #name) #endif -#define RELEASE_ASSERT(assertion) do { if (!(assertion)) { ESCARGOT_LOG_ERROR("RELEASE_ASSERT at %s (%d)\n", __FILE__, __LINE__); abort(); } } while (0); -#define RELEASE_ASSERT_NOT_REACHED() do { ESCARGOT_LOG_ERROR("RELEASE_ASSERT_NOT_REACHED at %s (%d)\n", __FILE__, __LINE__); abort(); } while (0) +#define RELEASE_ASSERT(assertion) \ + do { \ + if (!(assertion)) { \ + ESCARGOT_LOG_ERROR("RELEASE_ASSERT at %s (%d)\n", __FILE__, __LINE__); \ + abort(); \ + } \ + } while (0); +#define RELEASE_ASSERT_NOT_REACHED() \ + do { \ + ESCARGOT_LOG_ERROR("RELEASE_ASSERT_NOT_REACHED at %s (%d)\n", __FILE__, __LINE__); \ + abort(); \ + } while (0) #if !defined(WARN_UNUSED_RETURN) && COMPILER(GCC) #define WARN_UNUSED_RETURN __attribute__((__warn_unused_result__)) @@ -502,36 +510,21 @@ inline bool operator!=(const gc_malloc_atomic_ignore_off_page_allocator&, #define WARN_UNUSED_RETURN #endif -#if defined(__BYTE_ORDER__) && __BYTE_ORDER == __BIG_ENDIAN || \ - defined(__BIG_ENDIAN__) || \ - defined(__ARMEB__) || \ - defined(__THUMBEB__) || \ - defined(__AARCH64EB__) || \ - defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) +#if defined(__BYTE_ORDER__) && __BYTE_ORDER == __BIG_ENDIAN || defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) #define ESCARGOT_BIG_ENDIAN // #pragma message "big endian" -#elif defined(__BYTE_ORDER__) && __BYTE_ORDER == __LITTLE_ENDIAN || \ - defined(__LITTLE_ENDIAN__) || \ - defined(__i386) || \ - defined(_M_IX86) || \ - defined(__ia64) || \ - defined(__ia64__) || \ - defined(_M_IA64) || \ - defined(__ARMEL__) || \ - defined(__THUMBEL__) || \ - defined(__AARCH64EL__) || \ - defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) +#elif defined(__BYTE_ORDER__) && __BYTE_ORDER == __LITTLE_ENDIAN || defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(_M_IX86) || defined(__ia64) || defined(__ia64__) || defined(_M_IA64) || defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) #define ESCARGOT_LITTLE_ENDIAN // #pragma message "little endian" #else #error "I don't know what architecture this is!" #endif -#define MAKE_STACK_ALLOCATED() \ - static void *operator new (size_t) = delete; \ - static void *operator new[] (size_t) = delete; \ - static void operator delete (void*) = delete; \ - static void operator delete[](void*) = delete; +#define MAKE_STACK_ALLOCATED() \ + static void* operator new(size_t) = delete; \ + static void* operator new[](size_t) = delete; \ + static void operator delete(void*) = delete; \ + static void operator delete[](void*) = delete; #define ALLOCA(bytes, typenameWithoutPointer, ec) (typenameWithoutPointer*)alloca(bytes) diff --git a/src/interpreter/ByteCode.cpp b/src/interpreter/ByteCode.cpp index 8f95b0e63..8473a83eb 100644 --- a/src/interpreter/ByteCode.cpp +++ b/src/interpreter/ByteCode.cpp @@ -25,7 +25,7 @@ NodeLOC ByteCodeBlock::computeNodeLOCFromByteCode(ByteCode* code, CodeBlock* cb) } size_t line = cb->sourceElementStart().line; size_t column = cb->sourceElementStart().column; - for(size_t i = 0; i < code->m_loc.index; i ++) { + for (size_t i = 0; i < code->m_loc.index; i++) { char16_t c = cb->src().charAt(i); if (isLineTerminator(c)) { line++; @@ -34,5 +34,4 @@ NodeLOC ByteCodeBlock::computeNodeLOCFromByteCode(ByteCode* code, CodeBlock* cb) } return NodeLOC(line, column, code->m_loc.index); } - } diff --git a/src/interpreter/ByteCode.h b/src/interpreter/ByteCode.h index cdea6d3c6..ce7aa311f 100644 --- a/src/interpreter/ByteCode.h +++ b/src/interpreter/ByteCode.h @@ -1,79 +1,79 @@ #ifndef __EscargotByteCode__ #define __EscargotByteCode__ -#include "runtime/Value.h" -#include "runtime/String.h" +#include "interpreter/ByteCodeGenerator.h" #include "parser/CodeBlock.h" #include "parser/ast/Node.h" #include "runtime/SmallValue.h" -#include "interpreter/ByteCodeGenerator.h" +#include "runtime/String.h" +#include "runtime/Value.h" namespace Escargot { class ObjectStructure; class Node; // -#define FOR_EACH_BYTECODE_OP(F) \ - F(LoadLiteral, 1, 0) \ - F(LoadByName, 1, 0) \ - F(StoreByName, 0, 0) \ - F(LoadByStackIndex, 1, 0) \ - F(StoreByStackIndex, 0, 0) \ - F(LoadByHeapIndex, 1, 0) \ - F(StoreByHeapIndex, 0, 0) \ - F(LoadByGlobalName, 1, 0) \ - F(StoreByGlobalName, 0, 0) \ - F(DeclareVarVariable, 0, 0) \ +#define FOR_EACH_BYTECODE_OP(F) \ + F(LoadLiteral, 1, 0) \ + F(LoadByName, 1, 0) \ + F(StoreByName, 0, 0) \ + F(LoadByStackIndex, 1, 0) \ + F(StoreByStackIndex, 0, 0) \ + F(LoadByHeapIndex, 1, 0) \ + F(StoreByHeapIndex, 0, 0) \ + F(LoadByGlobalName, 1, 0) \ + F(StoreByGlobalName, 0, 0) \ + F(DeclareVarVariable, 0, 0) \ F(DeclareFunctionDeclaration, 1, 0) \ - F(DeclareFunctionExpression, 1, 0) \ - F(GetThis, 1, 0) \ - F(NewOperation, 1, 0) \ - F(BinaryPlus, 1, 2) \ - F(BinaryMinus, 1, 2) \ - F(BinaryMultiply, 1, 2) \ - F(BinaryDivision, 1, 2) \ - F(BinaryMod, 1, 2) \ - F(BinaryEqual, 1, 2) \ - F(BinaryLessThan, 1, 2) \ - F(BinaryLessThanOrEqual, 1, 2) \ - F(BinaryGreaterThan, 1, 2) \ - F(BinaryGreaterThanOrEqual, 1, 2) \ - F(BinaryNotEqual, 1, 2) \ - F(BinaryStrictEqual, 1, 2) \ - F(BinaryNotStrictEqual, 1, 2) \ - F(BinaryBitwiseAnd, 1, 2) \ - F(BinaryBitwiseOr, 1, 2) \ - F(BinaryBitwiseXor, 1, 2) \ - F(BinaryLeftShift, 1, 2) \ - F(BinarySignedRightShift, 1, 2) \ - F(BinaryUnsignedRightShift, 1, 2) \ - F(CreateObject, 1, 0) \ - F(GetObject, 1, 2) \ - F(SetObject, 0, 2) \ - F(GetObjectPreComputedCase, 1, 1) \ - F(SetObjectPreComputedCase, 0, 1) \ - F(GetGlobalObject, 1, 1) \ - F(SetGlobalObject, 0, 1) \ - F(Move, 1, 0) \ - F(Increment, 1, 1) \ - F(Decrement, 1, 1) \ - F(UnaryMinus, 1, 1) \ - F(UnaryPlus, 1, 1) \ - F(Jump, 0, 0) \ - F(JumpComplexCase, 0, 0) \ - F(JumpIfTrue, 0, 0) \ - F(JumpIfFalse, 0, 0) \ - F(CallFunction, -1, 0) \ - F(ReturnFunction, 0, 0) \ - F(ThrowOperation, 0, 0) \ - F(CallNativeFunction, 0, 0) \ - F(End, 0, 0) \ + F(DeclareFunctionExpression, 1, 0) \ + F(GetThis, 1, 0) \ + F(NewOperation, 1, 0) \ + F(BinaryPlus, 1, 2) \ + F(BinaryMinus, 1, 2) \ + F(BinaryMultiply, 1, 2) \ + F(BinaryDivision, 1, 2) \ + F(BinaryMod, 1, 2) \ + F(BinaryEqual, 1, 2) \ + F(BinaryLessThan, 1, 2) \ + F(BinaryLessThanOrEqual, 1, 2) \ + F(BinaryGreaterThan, 1, 2) \ + F(BinaryGreaterThanOrEqual, 1, 2) \ + F(BinaryNotEqual, 1, 2) \ + F(BinaryStrictEqual, 1, 2) \ + F(BinaryNotStrictEqual, 1, 2) \ + F(BinaryBitwiseAnd, 1, 2) \ + F(BinaryBitwiseOr, 1, 2) \ + F(BinaryBitwiseXor, 1, 2) \ + F(BinaryLeftShift, 1, 2) \ + F(BinarySignedRightShift, 1, 2) \ + F(BinaryUnsignedRightShift, 1, 2) \ + F(CreateObject, 1, 0) \ + F(GetObject, 1, 2) \ + F(SetObject, 0, 2) \ + F(GetObjectPreComputedCase, 1, 1) \ + F(SetObjectPreComputedCase, 0, 1) \ + F(GetGlobalObject, 1, 1) \ + F(SetGlobalObject, 0, 1) \ + F(Move, 1, 0) \ + F(Increment, 1, 1) \ + F(Decrement, 1, 1) \ + F(UnaryMinus, 1, 1) \ + F(UnaryPlus, 1, 1) \ + F(Jump, 0, 0) \ + F(JumpComplexCase, 0, 0) \ + F(JumpIfTrue, 0, 0) \ + F(JumpIfFalse, 0, 0) \ + F(CallFunction, -1, 0) \ + F(ReturnFunction, 0, 0) \ + F(ThrowOperation, 0, 0) \ + F(CallNativeFunction, 0, 0) \ + F(End, 0, 0) enum Opcode { #define DECLARE_BYTECODE(name, pushCount, popCount) name##Opcode, FOR_EACH_BYTECODE_OP(DECLARE_BYTECODE) #undef DECLARE_BYTECODE - OpcodeKindEnd + OpcodeKindEnd } __attribute__((packed)); struct OpcodeTable { @@ -89,10 +89,10 @@ inline const char* getByteCodeName(Opcode opcode) { switch (opcode) { #define RETURN_BYTECODE_NAME(name, pushCount, popCount) \ - case name##Opcode: \ + case name##Opcode: \ return #name; FOR_EACH_BYTECODE_OP(RETURN_BYTECODE_NAME) -#undef RETURN_BYTECODE_NAME +#undef RETURN_BYTECODE_NAME default: RELEASE_ASSERT_NOT_REACHED(); } @@ -102,7 +102,7 @@ inline const char* getByteCodeName(Opcode opcode) #ifndef NDEBUG inline const char* getByteCodeNameFromAddress(void* opcodeInAddress) { - for (size_t i = 0; i < OpcodeKindEnd; i ++) { + for (size_t i = 0; i < OpcodeKindEnd; i++) { if (g_opcodeTable.m_reverseTable[i].first == opcodeInAddress) return getByteCodeName(g_opcodeTable.m_reverseTable[i].second); } @@ -114,10 +114,10 @@ inline size_t getByteCodePushCount(Opcode code) { switch (code) { #define RETURN_BYTECODE_CNT(name, pushCount, popCount) \ - case name##Opcode: \ + case name##Opcode: \ return pushCount; FOR_EACH_BYTECODE_OP(RETURN_BYTECODE_CNT) -#undef RETURN_BYTECODE_CNT +#undef RETURN_BYTECODE_CNT default: RELEASE_ASSERT_NOT_REACHED(); } @@ -127,10 +127,10 @@ inline size_t getByteCodePopCount(Opcode code) { switch (code) { #define RETURN_BYTECODE_CNT(name, pushCount, popCount) \ - case name##Opcode: \ + case name##Opcode: \ return popCount; FOR_EACH_BYTECODE_OP(RETURN_BYTECODE_CNT) -#undef RETURN_BYTECODE_CNT +#undef RETURN_BYTECODE_CNT default: RELEASE_ASSERT_NOT_REACHED(); } @@ -190,7 +190,6 @@ class ByteCode : public gc { virtual void dump() { - } #endif @@ -203,7 +202,6 @@ class LoadLiteral : public ByteCode { , m_registerIndex(registerIndex) , m_value(v) { - } size_t m_registerIndex; SmallValue m_value; @@ -476,26 +474,26 @@ class NewOperation : public ByteCode { #ifdef NDEBUG #define DEFINE_BINARY_OPERATION_DUMP(name) #else -#define DEFINE_BINARY_OPERATION_DUMP(name) \ - virtual void dump() \ - { \ - printf(name" r%d <- r%d , r%d", (int)m_srcIndex0, (int)m_srcIndex0, (int)m_srcIndex1); \ - } -#endif - -#define DEFINE_BINARY_OPERATION(CodeName, HumanName) \ -class Binary##CodeName : public ByteCode { \ -public: \ - Binary##CodeName(const ByteCodeLOC& loc, const size_t& registerIndex0, const size_t& registerIndex1) \ - : ByteCode(Opcode::Binary##CodeName##Opcode, loc) \ - , m_srcIndex0(registerIndex0) \ - , m_srcIndex1(registerIndex1) \ - { \ - } \ - size_t m_srcIndex0; \ - size_t m_srcIndex1; \ - DEFINE_BINARY_OPERATION_DUMP(HumanName) \ -}; +#define DEFINE_BINARY_OPERATION_DUMP(name) \ + virtual void dump() \ + { \ + printf(name " r%d <- r%d , r%d", (int)m_srcIndex0, (int)m_srcIndex0, (int)m_srcIndex1); \ + } +#endif + +#define DEFINE_BINARY_OPERATION(CodeName, HumanName) \ + class Binary##CodeName : public ByteCode { \ + public: \ + Binary##CodeName(const ByteCodeLOC& loc, const size_t& registerIndex0, const size_t& registerIndex1) \ + : ByteCode(Opcode::Binary##CodeName##Opcode, loc) \ + , m_srcIndex0(registerIndex0) \ + , m_srcIndex1(registerIndex1) \ + { \ + } \ + size_t m_srcIndex0; \ + size_t m_srcIndex1; \ + DEFINE_BINARY_OPERATION_DUMP(HumanName) \ + }; DEFINE_BINARY_OPERATION(Plus, "plus"); DEFINE_BINARY_OPERATION(Minus, "minus"); @@ -578,7 +576,7 @@ class SetObject : public ByteCode { }; -typedef Vector > ObjectStructureChain; +typedef Vector> ObjectStructureChain; struct GetObjectInlineCacheData { GetObjectInlineCacheData() @@ -590,7 +588,7 @@ struct GetObjectInlineCacheData { }; struct GetObjectInlineCache { - Vector > m_cache; + Vector> m_cache; size_t m_executeCount; GetObjectInlineCache() { @@ -702,9 +700,9 @@ class SetGlobalObject : public ByteCode { class Move : public ByteCode { public: Move(const ByteCodeLOC& loc, const size_t& registerIndex0, const size_t& registerIndex1) // 1 <= 0 - : ByteCode(Opcode::MoveOpcode, loc) - , m_registerIndex0(registerIndex0) - , m_registerIndex1(registerIndex1) + : ByteCode(Opcode::MoveOpcode, loc), + m_registerIndex0(registerIndex0), + m_registerIndex1(registerIndex1) { } @@ -963,17 +961,17 @@ class ByteCodeBlock : public gc { template void pushCode(const CodeType& code, ByteCodeGenerateContext* context, Node* node) { - #ifndef NDEBUG +#ifndef NDEBUG { - CodeType& t = const_cast(code); + CodeType& t = const_cast(code); t.m_node = node; t.m_loc.line = computeNodeLOCFromByteCode(&t, context->m_codeBlock).line; t.m_loc.column = computeNodeLOCFromByteCode(&t, context->m_codeBlock).column; } - #endif +#endif - const_cast(code).assignOpcodeInAddress(); - char* first = (char *)&code; + const_cast(code).assignOpcodeInAddress(); + char* first = (char*)&code; m_code.insert(m_code.end(), first, first + sizeof(CodeType)); m_requiredRegisterFileSizeInValueSize = std::max(m_requiredRegisterFileSizeInValueSize, (size_t)context->m_baseRegisterCount); @@ -983,7 +981,7 @@ class ByteCodeBlock : public gc { { char* pos = m_code.data(); pos = &pos[position]; - return (CodeType *)pos; + return (CodeType*)pos; } template @@ -1002,7 +1000,6 @@ class ByteCodeBlock : public gc { ByteCodeBlockData m_code; size_t m_requiredRegisterFileSizeInValueSize; }; - } #endif diff --git a/src/interpreter/ByteCodeGenerator.cpp b/src/interpreter/ByteCodeGenerator.cpp index 93ab48c0a..367295a48 100644 --- a/src/interpreter/ByteCodeGenerator.cpp +++ b/src/interpreter/ByteCodeGenerator.cpp @@ -7,7 +7,7 @@ namespace Escargot { void ByteCodeGenerateContext::consumeLabeledContinuePositions(ByteCodeBlock* cb, size_t position, String* lbl) { - for (size_t i = 0; i < m_labeledContinueStatmentPositions.size(); i ++) { + for (size_t i = 0; i < m_labeledContinueStatmentPositions.size(); i++) { if (*m_labeledContinueStatmentPositions[i].first == *lbl) { Jump* shouldBeJump = cb->peekCode(m_labeledContinueStatmentPositions[i].second); ASSERT(shouldBeJump->m_orgOpcode == JumpOpcode); @@ -21,7 +21,7 @@ void ByteCodeGenerateContext::consumeLabeledContinuePositions(ByteCodeBlock* cb, void ByteCodeGenerateContext::consumeBreakPositions(ByteCodeBlock* cb, size_t position) { - for (size_t i = 0; i < m_breakStatementPositions.size(); i ++) { + for (size_t i = 0; i < m_breakStatementPositions.size(); i++) { Jump* shouldBeJump = cb->peekCode(m_breakStatementPositions[i]); ASSERT(shouldBeJump->m_orgOpcode == JumpOpcode); shouldBeJump->m_jumpPosition = position; @@ -33,7 +33,7 @@ void ByteCodeGenerateContext::consumeBreakPositions(ByteCodeBlock* cb, size_t po void ByteCodeGenerateContext::consumeLabeledBreakPositions(ByteCodeBlock* cb, size_t position, String* lbl) { - for (size_t i = 0; i < m_labeledBreakStatmentPositions.size(); i ++) { + for (size_t i = 0; i < m_labeledBreakStatmentPositions.size(); i++) { if (*m_labeledBreakStatmentPositions[i].first == *lbl) { Jump* shouldBeJump = cb->peekCode(m_labeledBreakStatmentPositions[i].second); ASSERT(shouldBeJump->m_orgOpcode == JumpOpcode); @@ -47,7 +47,7 @@ void ByteCodeGenerateContext::consumeLabeledBreakPositions(ByteCodeBlock* cb, si void ByteCodeGenerateContext::consumeContinuePositions(ByteCodeBlock* cb, size_t position) { - for (size_t i = 0; i < m_continueStatementPositions.size(); i ++) { + for (size_t i = 0; i < m_continueStatementPositions.size(); i++) { Jump* shouldBeJump = cb->peekCode(m_continueStatementPositions[i]); ASSERT(shouldBeJump->m_orgOpcode == JumpOpcode); shouldBeJump->m_jumpPosition = position; @@ -81,7 +81,7 @@ void ByteCodeGenerator::generateByteCode(Context* c, CodeBlock* codeBlock, Node* // generate init function decls first size_t len = codeBlock->childBlocks().size(); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { CodeBlock* b = codeBlock->childBlocks()[i]; if (b->isFunctionDeclaration()) { ctx.getRegister(); @@ -107,10 +107,10 @@ void ByteCodeGenerator::generateByteCode(Context* c, CodeBlock* codeBlock, Node* char* code = block->m_code.data(); char* end = &block->m_code.data()[block->m_code.size()]; while (&code[idx] < end) { - ByteCode* currentCode = (ByteCode *)(&code[idx]); + ByteCode* currentCode = (ByteCode*)(&code[idx]); Opcode opcode = EndOpcode; - for (size_t i = 0; i < OpcodeKindEnd; i ++) { + for (size_t i = 0; i < OpcodeKindEnd; i++) { if (g_opcodeTable.m_reverseTable[i].first == currentCode->m_opcodeInAddress) { opcode = g_opcodeTable.m_reverseTable[i].second; break; @@ -119,14 +119,14 @@ void ByteCodeGenerator::generateByteCode(Context* c, CodeBlock* codeBlock, Node* switch (opcode) { #define DUMP_BYTE_CODE(code, pushCount, popCount) \ - case code##Opcode:\ - currentCode->dumpCode(idx); \ - idx += sizeof(code); \ - continue; + case code##Opcode: \ + currentCode->dumpCode(idx); \ + idx += sizeof(code); \ + continue; - FOR_EACH_BYTECODE_OP(DUMP_BYTE_CODE) + FOR_EACH_BYTECODE_OP(DUMP_BYTE_CODE) -#undef DUMP_BYTE_CODE +#undef DUMP_BYTE_CODE default: RELEASE_ASSERT_NOT_REACHED(); break; @@ -138,5 +138,4 @@ void ByteCodeGenerator::generateByteCode(Context* c, CodeBlock* codeBlock, Node* codeBlock->m_byteCodeBlock = block; } - } diff --git a/src/interpreter/ByteCodeGenerator.h b/src/interpreter/ByteCodeGenerator.h index 0e3069910..17f137c64 100644 --- a/src/interpreter/ByteCodeGenerator.h +++ b/src/interpreter/ByteCodeGenerator.h @@ -1,9 +1,9 @@ #ifndef __EscargotByteCodeGenerator__ #define __EscargotByteCodeGenerator__ -#include "runtime/Value.h" -#include "runtime/String.h" #include "parser/CodeBlock.h" +#include "runtime/String.h" +#include "runtime/Value.h" namespace Escargot { @@ -59,7 +59,6 @@ struct ByteCodeGenerateContext { ~ByteCodeGenerateContext() { - } void propagateInformationTo(ByteCodeGenerateContext& ctx) @@ -102,38 +101,37 @@ struct ByteCodeGenerateContext { void registerJumpPositionsToComplexCase(size_t frontlimit) { ASSERT(m_tryStatementScopeCount); - for (unsigned i = 0 ; i < m_breakStatementPositions.size() ; i ++) { - if (m_breakStatementPositions[i] > (unsigned long) frontlimit) { + for (unsigned i = 0; i < m_breakStatementPositions.size(); i++) { + if (m_breakStatementPositions[i] > (unsigned long)frontlimit) { if (m_complexCaseStatementPositions.find(m_breakStatementPositions[i]) == m_complexCaseStatementPositions.end()) { m_complexCaseStatementPositions.insert(std::make_pair(m_breakStatementPositions[i], m_tryStatementScopeCount)); } } } - for (unsigned i = 0 ; i < m_continueStatementPositions.size() ; i ++) { - if (m_continueStatementPositions[i] > (unsigned long) frontlimit) { + for (unsigned i = 0; i < m_continueStatementPositions.size(); i++) { + if (m_continueStatementPositions[i] > (unsigned long)frontlimit) { if (m_complexCaseStatementPositions.find(m_continueStatementPositions[i]) == m_complexCaseStatementPositions.end()) { m_complexCaseStatementPositions.insert(std::make_pair(m_continueStatementPositions[i], m_tryStatementScopeCount)); } } } - for (unsigned i = 0 ; i < m_labeledBreakStatmentPositions.size() ; i ++) { - if (m_labeledBreakStatmentPositions[i].second > (unsigned long) frontlimit) { + for (unsigned i = 0; i < m_labeledBreakStatmentPositions.size(); i++) { + if (m_labeledBreakStatmentPositions[i].second > (unsigned long)frontlimit) { if (m_complexCaseStatementPositions.find(m_labeledBreakStatmentPositions[i].second) == m_complexCaseStatementPositions.end()) { m_complexCaseStatementPositions.insert(std::make_pair(m_labeledBreakStatmentPositions[i].second, m_tryStatementScopeCount)); } } } - for (unsigned i = 0 ; i < m_labeledContinueStatmentPositions.size() ; i ++) { - if (m_labeledContinueStatmentPositions[i].second > (unsigned long) frontlimit) { + for (unsigned i = 0; i < m_labeledContinueStatmentPositions.size(); i++) { + if (m_labeledContinueStatmentPositions[i].second > (unsigned long)frontlimit) { if (m_complexCaseStatementPositions.find(m_labeledContinueStatmentPositions[i].second) == m_complexCaseStatementPositions.end()) { m_complexCaseStatementPositions.insert(std::make_pair(m_labeledContinueStatmentPositions[i].second, m_tryStatementScopeCount)); } } } - } size_t getLastRegisterIndex() @@ -188,6 +186,7 @@ struct ByteCodeGenerateContext { class ByteCodeGenerator { MAKE_STACK_ALLOCATED(); + public: ByteCodeGenerator() { @@ -195,7 +194,6 @@ class ByteCodeGenerator { void generateByteCode(Context* c, CodeBlock* codeBlock, Node* ast); }; - } #endif diff --git a/src/interpreter/ByteCodeInterpreter.cpp b/src/interpreter/ByteCodeInterpreter.cpp index 1e21a43f8..386ab485f 100644 --- a/src/interpreter/ByteCodeInterpreter.cpp +++ b/src/interpreter/ByteCodeInterpreter.cpp @@ -14,7 +14,7 @@ namespace Escargot { NEVER_INLINE void registerOpcode(Opcode opcode, void* opcodeAddress) { - static std::unordered_set labelAddressChecker; + static std::unordered_set labelAddressChecker; if (labelAddressChecker.find(opcodeAddress) != labelAddressChecker.end()) { ESCARGOT_LOG_ERROR("%d\n", opcode); RELEASE_ASSERT_NOT_REACHED(); @@ -51,6 +51,7 @@ class ECResetter { { m_addr = nullptr; } + protected: size_t** m_addr; }; @@ -76,646 +77,591 @@ void ByteCodeInterpreter::interpret(ExecutionState& state, CodeBlock* codeBlock) programCounter = (size_t)(&codeBuffer[0]); ByteCode* currentCode; -#define NEXT_INSTRUCTION() \ - currentCode = (ByteCode *)programCounter; \ - ASSERT(((size_t)currentCode % sizeof(size_t)) == 0); \ - goto *(currentCode->m_opcodeInAddress); +#define NEXT_INSTRUCTION() \ + currentCode = (ByteCode*)programCounter; \ + ASSERT(((size_t)currentCode % sizeof(size_t)) == 0); \ + goto*(currentCode->m_opcodeInAddress); - currentCode = (ByteCode *)programCounter; + currentCode = (ByteCode*)programCounter; ASSERT(((size_t)currentCode % sizeof(size_t)) == 0); - goto *(currentCode->m_opcodeInAddress); - - LoadLiteralOpcodeLbl: - { - LoadLiteral* code = (LoadLiteral*)currentCode; - registerFile[code->m_registerIndex] = code->m_value; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + goto*(currentCode->m_opcodeInAddress); - MoveOpcodeLbl: - { - Move* code = (Move*)currentCode; - registerFile[code->m_registerIndex1] = registerFile[code->m_registerIndex0]; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + LoadLiteralOpcodeLbl : { + LoadLiteral* code = (LoadLiteral*)currentCode; + registerFile[code->m_registerIndex] = code->m_value; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - LoadByStackIndexOpcodeLbl: - { - LoadByStackIndex* code = (LoadByStackIndex*)currentCode; - registerFile[code->m_registerIndex] = stackStorage[code->m_index]; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + MoveOpcodeLbl : { + Move* code = (Move*)currentCode; + registerFile[code->m_registerIndex1] = registerFile[code->m_registerIndex0]; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - StoreByStackIndexOpcodeLbl: - { - StoreByStackIndex* code = (StoreByStackIndex*)currentCode; - stackStorage[code->m_index] = registerFile[code->m_registerIndex]; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + LoadByStackIndexOpcodeLbl : { + LoadByStackIndex* code = (LoadByStackIndex*)currentCode; + registerFile[code->m_registerIndex] = stackStorage[code->m_index]; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - LoadByHeapIndexOpcodeLbl: - { - LoadByHeapIndex* code = (LoadByHeapIndex*)currentCode; - LexicalEnvironment* upperEnv = env; - for (size_t i = 0; i < code->m_upperIndex; i ++) { - upperEnv = upperEnv->outerEnvironment(); - } - FunctionEnvironmentRecord* record = upperEnv->record()->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord(); - ASSERT(record->isFunctionEnvironmentRecordOnHeap()); - registerFile[code->m_registerIndex] = ((FunctionEnvironmentRecordOnHeap*)record)->m_heapStorage[code->m_index]; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + StoreByStackIndexOpcodeLbl : { + StoreByStackIndex* code = (StoreByStackIndex*)currentCode; + stackStorage[code->m_index] = registerFile[code->m_registerIndex]; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } + + LoadByHeapIndexOpcodeLbl : { + LoadByHeapIndex* code = (LoadByHeapIndex*)currentCode; + LexicalEnvironment* upperEnv = env; + for (size_t i = 0; i < code->m_upperIndex; i++) { + upperEnv = upperEnv->outerEnvironment(); } + FunctionEnvironmentRecord* record = upperEnv->record()->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord(); + ASSERT(record->isFunctionEnvironmentRecordOnHeap()); + registerFile[code->m_registerIndex] = ((FunctionEnvironmentRecordOnHeap*)record)->m_heapStorage[code->m_index]; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - StoreByHeapIndexOpcodeLbl: - { - StoreByHeapIndex* code = (StoreByHeapIndex*)currentCode; - LexicalEnvironment* upperEnv = env; - for (size_t i = 0; i < code->m_upperIndex; i ++) { - upperEnv = upperEnv->outerEnvironment(); - } - FunctionEnvironmentRecord* record = upperEnv->record()->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord(); - ASSERT(record->isFunctionEnvironmentRecordOnHeap()); - ((FunctionEnvironmentRecordOnHeap*)record)->m_heapStorage[code->m_index] = registerFile[code->m_registerIndex]; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + StoreByHeapIndexOpcodeLbl : { + StoreByHeapIndex* code = (StoreByHeapIndex*)currentCode; + LexicalEnvironment* upperEnv = env; + for (size_t i = 0; i < code->m_upperIndex; i++) { + upperEnv = upperEnv->outerEnvironment(); } + FunctionEnvironmentRecord* record = upperEnv->record()->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord(); + ASSERT(record->isFunctionEnvironmentRecordOnHeap()); + ((FunctionEnvironmentRecordOnHeap*)record)->m_heapStorage[code->m_index] = registerFile[code->m_registerIndex]; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - LoadByGlobalNameOpcodeLbl: - { - LoadByGlobalName* code = (LoadByGlobalName*)currentCode; - GlobalObject* g = state.context()->globalObject(); - // check cache - if (UNLIKELY(!g->hasPropertyOnIndex(state, code->m_name, code->m_cacheIndex))) { - // fill cache - code->m_cacheIndex = g->findPropertyIndex(state, code->m_name); - ASSERT(code->m_cacheIndex != SIZE_MAX); - } - registerFile[code->m_registerIndex] = g->getPropertyOnIndex(state, code->m_cacheIndex); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + LoadByGlobalNameOpcodeLbl : { + LoadByGlobalName* code = (LoadByGlobalName*)currentCode; + GlobalObject* g = state.context()->globalObject(); + // check cache + if (UNLIKELY(!g->hasPropertyOnIndex(state, code->m_name, code->m_cacheIndex))) { + // fill cache + code->m_cacheIndex = g->findPropertyIndex(state, code->m_name); + ASSERT(code->m_cacheIndex != SIZE_MAX); } + registerFile[code->m_registerIndex] = g->getPropertyOnIndex(state, code->m_cacheIndex); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - StoreByGlobalNameOpcodeLbl: - { - StoreByGlobalName* code = (StoreByGlobalName*)currentCode; - GlobalObject* g = state.context()->globalObject(); - // check cache - if (UNLIKELY(!g->hasPropertyOnIndex(state, code->m_name, code->m_cacheIndex))) { - // fill cache - code->m_cacheIndex = g->findPropertyIndex(state, code->m_name); - ASSERT(code->m_cacheIndex != SIZE_MAX); - } - if (UNLIKELY(!g->setPropertyOnIndex(state, code->m_cacheIndex, registerFile[code->m_registerIndex]))) { - if (state.inStrictMode()) { - // TODO throw execption - RELEASE_ASSERT_NOT_REACHED(); - } + StoreByGlobalNameOpcodeLbl : { + StoreByGlobalName* code = (StoreByGlobalName*)currentCode; + GlobalObject* g = state.context()->globalObject(); + // check cache + if (UNLIKELY(!g->hasPropertyOnIndex(state, code->m_name, code->m_cacheIndex))) { + // fill cache + code->m_cacheIndex = g->findPropertyIndex(state, code->m_name); + ASSERT(code->m_cacheIndex != SIZE_MAX); + } + if (UNLIKELY(!g->setPropertyOnIndex(state, code->m_cacheIndex, registerFile[code->m_registerIndex]))) { + if (state.inStrictMode()) { + // TODO throw execption + RELEASE_ASSERT_NOT_REACHED(); } - executeNextCode(programCounter); - NEXT_INSTRUCTION(); } + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - LoadByNameOpcodeLbl: - { - LoadByName* code = (LoadByName*)currentCode; - registerFile[code->m_registerIndex] = loadByName(state, env, code->m_name); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + LoadByNameOpcodeLbl : { + LoadByName* code = (LoadByName*)currentCode; + registerFile[code->m_registerIndex] = loadByName(state, env, code->m_name); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - StoreByNameOpcodeLbl: - { - StoreByName* code = (StoreByName*)currentCode; - record->setMutableBinding(state, code->m_name, registerFile[code->m_registerIndex]); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + StoreByNameOpcodeLbl : { + StoreByName* code = (StoreByName*)currentCode; + record->setMutableBinding(state, code->m_name, registerFile[code->m_registerIndex]); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - DeclareVarVariableOpcodeLbl: - { - DeclareVarVariable* code = (DeclareVarVariable*)currentCode; - record->createMutableBinding(state, code->m_name, false); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + DeclareVarVariableOpcodeLbl : { + DeclareVarVariable* code = (DeclareVarVariable*)currentCode; + record->createMutableBinding(state, code->m_name, false); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } + + DeclareFunctionExpressionOpcodeLbl : { + DeclareFunctionExpression* code = (DeclareFunctionExpression*)currentCode; + registerFile[code->m_registerIndex] = new FunctionObject(state, code->m_codeBlock); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - DeclareFunctionExpressionOpcodeLbl: - { - DeclareFunctionExpression* code = (DeclareFunctionExpression*)currentCode; - registerFile[code->m_registerIndex] = new FunctionObject(state, code->m_codeBlock); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + GetThisOpcodeLbl : { + GetThis* code = (GetThis*)currentCode; + if (UNLIKELY(thisValue.isEmpty())) { + thisValue = record->getThisBinding(); } + registerFile[code->m_registerIndex] = thisValue; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - GetThisOpcodeLbl: - { - GetThis* code = (GetThis*)currentCode; - if (UNLIKELY(thisValue.isEmpty())) { - thisValue = record->getThisBinding(); + BinaryPlusOpcodeLbl : { + BinaryPlus* code = (BinaryPlus*)currentCode; + const Value& v0 = registerFile[code->m_srcIndex0]; + const Value& v1 = registerFile[code->m_srcIndex1]; + Value ret(Value::ForceUninitialized); + if (v0.isInt32() && v1.isInt32()) { + int32_t a = v0.asInt32(); + int32_t b = v1.asInt32(); + int32_t c; + bool result = ArithmeticOperations::add(a, b, c); + if (LIKELY(result)) { + ret = Value(c); + } else { + ret = Value(Value::EncodeAsDouble, (double)a + (double)b); } - registerFile[code->m_registerIndex] = thisValue; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + } else if (v0.isNumber() && v1.isNumber()) { + ret = Value(v0.asNumber() + v1.asNumber()); + } else { + ret = plusSlowCase(state, v0, v1); } + registerFile[code->m_srcIndex0] = ret; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryPlusOpcodeLbl: - { - BinaryPlus* code = (BinaryPlus*)currentCode; - const Value& v0 = registerFile[code->m_srcIndex0]; - const Value& v1 = registerFile[code->m_srcIndex1]; - Value ret(Value::ForceUninitialized); - if (v0.isInt32() && v1.isInt32()) { - int32_t a = v0.asInt32(); - int32_t b = v1.asInt32(); - int32_t c; - bool result = ArithmeticOperations::add(a, b, c); - if (LIKELY(result)) { - ret = Value(c); - } else { - ret = Value(Value::EncodeAsDouble, (double)a + (double)b); - } - } else if (v0.isNumber() && v1.isNumber()) { - ret = Value(v0.asNumber() + v1.asNumber()); + BinaryMinusOpcodeLbl : { + BinaryMinus* code = (BinaryMinus*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + Value ret(Value::ForceUninitialized); + if (left.isInt32() && right.isInt32()) { + int32_t a = left.asInt32(); + int32_t b = right.asInt32(); + int32_t c; + bool result = ArithmeticOperations::sub(a, b, c); + if (LIKELY(result)) { + ret = Value(c); } else { - ret = plusSlowCase(state, v0, v1); + ret = Value(Value::EncodeAsDouble, (double)a - (double)b); } - registerFile[code->m_srcIndex0] = ret; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + } else { + ret = Value(left.toNumber(state) - right.toNumber(state)); } + registerFile[code->m_srcIndex0] = ret; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryMinusOpcodeLbl: - { - BinaryMinus* code = (BinaryMinus*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - Value ret(Value::ForceUninitialized); - if (left.isInt32() && right.isInt32()) { - int32_t a = left.asInt32(); - int32_t b = right.asInt32(); - int32_t c; - bool result = ArithmeticOperations::sub(a, b, c); + BinaryMultiplyOpcodeLbl : { + BinaryMultiply* code = (BinaryMultiply*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + Value ret(Value::ForceUninitialized); + if (left.isInt32() && right.isInt32()) { + int32_t a = left.asInt32(); + int32_t b = right.asInt32(); + if ((!a || !b) && (a >> 31 || b >> 31)) { // -1 * 0 should be treated as -0, not +0 + ret = Value(left.toNumber(state) * right.toNumber(state)); + } else { + int32_t c = right.asInt32(); + bool result = ArithmeticOperations::multiply(a, b, c); if (LIKELY(result)) { ret = Value(c); } else { - ret = Value(Value::EncodeAsDouble, (double)a - (double)b); + ret = Value(Value::EncodeAsDouble, left.toNumber(state) * right.toNumber(state)); } - } else { - ret = Value(left.toNumber(state) - right.toNumber(state)); } - registerFile[code->m_srcIndex0] = ret; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + } else { + ret = Value(Value::EncodeAsDouble, left.toNumber(state) * right.toNumber(state)); } + registerFile[code->m_srcIndex0] = ret; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryMultiplyOpcodeLbl: - { - BinaryMultiply* code = (BinaryMultiply*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - Value ret(Value::ForceUninitialized); - if (left.isInt32() && right.isInt32()) { - int32_t a = left.asInt32(); - int32_t b = right.asInt32(); - if ((!a || !b) && (a >> 31 || b >> 31)) { // -1 * 0 should be treated as -0, not +0 - ret = Value(left.toNumber(state) * right.toNumber(state)); - } else { - int32_t c = right.asInt32(); - bool result = ArithmeticOperations::multiply(a, b, c); - if (LIKELY(result)) { - ret = Value(c); - } else { - ret = Value(Value::EncodeAsDouble, left.toNumber(state) * right.toNumber(state)); - } - } - } else { - ret = Value(Value::EncodeAsDouble, left.toNumber(state) * right.toNumber(state)); - } - registerFile[code->m_srcIndex0] = ret; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryDivisionOpcodeLbl : { + BinaryDivision* code = (BinaryDivision*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(left.toNumber(state) / right.toNumber(state)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryDivisionOpcodeLbl: - { - BinaryDivision* code = (BinaryDivision*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(left.toNumber(state) / right.toNumber(state)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryModOpcodeLbl : { + BinaryMod* code = (BinaryMod*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = modOperation(state, left, right); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryModOpcodeLbl: - { - BinaryMod* code = (BinaryMod*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = modOperation(state, left, right); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryEqualOpcodeLbl : { + BinaryEqual* code = (BinaryEqual*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(left.abstractEqualsTo(state, right)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryEqualOpcodeLbl: - { - BinaryEqual* code = (BinaryEqual*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(left.abstractEqualsTo(state, right)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryNotEqualOpcodeLbl : { + BinaryNotEqual* code = (BinaryNotEqual*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(!left.abstractEqualsTo(state, right)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryNotEqualOpcodeLbl: - { - BinaryNotEqual* code = (BinaryNotEqual*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(!left.abstractEqualsTo(state, right)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryStrictEqualOpcodeLbl : { + BinaryStrictEqual* code = (BinaryStrictEqual*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(left.equalsTo(state, right)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryStrictEqualOpcodeLbl: - { - BinaryStrictEqual* code = (BinaryStrictEqual*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(left.equalsTo(state, right)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryNotStrictEqualOpcodeLbl : { + BinaryNotStrictEqual* code = (BinaryNotStrictEqual*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(!left.equalsTo(state, right)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryNotStrictEqualOpcodeLbl: - { - BinaryNotStrictEqual* code = (BinaryNotStrictEqual*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(!left.equalsTo(state, right)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryLessThanOpcodeLbl : { + BinaryLessThan* code = (BinaryLessThan*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(abstractRelationalComparison(state, left, right, true)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryLessThanOpcodeLbl: - { - BinaryLessThan* code = (BinaryLessThan*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(abstractRelationalComparison(state, left, right, true)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryLessThanOrEqualOpcodeLbl : { + BinaryLessThanOrEqual* code = (BinaryLessThanOrEqual*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(abstractRelationalComparisonOrEqual(state, left, right, true)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryLessThanOrEqualOpcodeLbl: - { - BinaryLessThanOrEqual* code = (BinaryLessThanOrEqual*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(abstractRelationalComparisonOrEqual(state, left, right, true)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryGreaterThanOpcodeLbl : { + BinaryGreaterThan* code = (BinaryGreaterThan*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(abstractRelationalComparison(state, right, left, false)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryGreaterThanOpcodeLbl: - { - BinaryGreaterThan* code = (BinaryGreaterThan*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(abstractRelationalComparison(state, right, left, false)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryGreaterThanOrEqualOpcodeLbl : { + BinaryGreaterThanOrEqual* code = (BinaryGreaterThanOrEqual*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(abstractRelationalComparisonOrEqual(state, right, left, false)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryGreaterThanOrEqualOpcodeLbl: - { - BinaryGreaterThanOrEqual* code = (BinaryGreaterThanOrEqual*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(abstractRelationalComparisonOrEqual(state, right, left, false)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + IncrementOpcodeLbl : { + Increment* code = (Increment*)currentCode; + const Value& val = registerFile[code->m_registerIndex]; + Value ret(Value::ForceUninitialized); + if (LIKELY(val.isInt32())) { + int32_t a = val.asInt32(); + if (UNLIKELY(a == std::numeric_limits::max())) + ret = Value(Value::EncodeAsDouble, ((double)a) + 1); + else + ret = Value(a + 1); + } else { + ret = Value(val.toNumber(state) + 1); } + registerFile[code->m_registerIndex] = ret; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - IncrementOpcodeLbl: - { - Increment* code = (Increment*)currentCode; - const Value& val = registerFile[code->m_registerIndex]; - Value ret(Value::ForceUninitialized); - if (LIKELY(val.isInt32())) { - int32_t a = val.asInt32(); - if (UNLIKELY(a == std::numeric_limits::max())) - ret = Value(Value::EncodeAsDouble, ((double)a) + 1); - else - ret = Value(a + 1); - } else { - ret = Value(val.toNumber(state) + 1); - } - registerFile[code->m_registerIndex] = ret; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + DecrementOpcodeLbl : { + Decrement* code = (Decrement*)currentCode; + const Value& val = registerFile[code->m_registerIndex]; + Value ret(Value::ForceUninitialized); + if (LIKELY(val.isInt32())) { + int32_t a = val.asInt32(); + if (UNLIKELY(a == std::numeric_limits::min())) + ret = Value(Value::EncodeAsDouble, ((double)a) - 1); + else + ret = Value(a - 1); + } else { + ret = Value(val.toNumber(state) - 1); } + registerFile[code->m_registerIndex] = ret; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - DecrementOpcodeLbl: - { - Decrement* code = (Decrement*)currentCode; - const Value& val = registerFile[code->m_registerIndex]; - Value ret(Value::ForceUninitialized); - if (LIKELY(val.isInt32())) { - int32_t a = val.asInt32(); - if (UNLIKELY(a == std::numeric_limits::min())) - ret = Value(Value::EncodeAsDouble, ((double)a) - 1); - else - ret = Value(a - 1); - } else { - ret = Value(val.toNumber(state) - 1); - } - registerFile[code->m_registerIndex] = ret; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + UnaryMinusOpcodeLbl : { + UnaryMinus* code = (UnaryMinus*)currentCode; + const Value& val = registerFile[code->m_registerIndex]; + registerFile[code->m_registerIndex] = Value(-val.toNumber(state)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - UnaryMinusOpcodeLbl: - { - UnaryMinus* code = (UnaryMinus*)currentCode; - const Value& val = registerFile[code->m_registerIndex]; - registerFile[code->m_registerIndex] = Value(-val.toNumber(state)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + UnaryPlusOpcodeLbl : { + UnaryPlus* code = (UnaryPlus*)currentCode; + const Value& val = registerFile[code->m_registerIndex]; + registerFile[code->m_registerIndex] = Value(val.toNumber(state)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - UnaryPlusOpcodeLbl: - { - UnaryPlus* code = (UnaryPlus*)currentCode; - const Value& val = registerFile[code->m_registerIndex]; - registerFile[code->m_registerIndex] = Value(val.toNumber(state)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + GetObjectOpcodeLbl : { + GetObject* code = (GetObject*)currentCode; + const Value& willBeObject = registerFile[code->m_objectRegisterIndex]; + const Value& property = registerFile[code->m_objectRegisterIndex + 1]; + registerFile[code->m_objectRegisterIndex] = willBeObject.toObject(state)->get(state, ObjectPropertyName(state, property)).value(); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - GetObjectOpcodeLbl: - { - GetObject* code = (GetObject*)currentCode; - const Value& willBeObject = registerFile[code->m_objectRegisterIndex]; - const Value& property = registerFile[code->m_objectRegisterIndex + 1]; - registerFile[code->m_objectRegisterIndex] = willBeObject.toObject(state)->get(state, ObjectPropertyName(state, property)).value(); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + SetObjectOpcodeLbl : { + SetObject* code = (SetObject*)currentCode; + const Value& willBeObject = registerFile[code->m_objectRegisterIndex]; + const Value& property = registerFile[code->m_propertyRegisterIndex]; + Object* obj = willBeObject.toObject(state); + obj->setThrowsExceptionWhenStrictMode(state, ObjectPropertyName(state, property), registerFile[code->m_loadRegisterIndex], obj); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - SetObjectOpcodeLbl: - { - SetObject* code = (SetObject*)currentCode; - const Value& willBeObject = registerFile[code->m_objectRegisterIndex]; - const Value& property = registerFile[code->m_propertyRegisterIndex]; - Object* obj = willBeObject.toObject(state); - obj->setThrowsExceptionWhenStrictMode(state, ObjectPropertyName(state, property), registerFile[code->m_loadRegisterIndex], obj); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + GetObjectPreComputedCaseOpcodeLbl : { + GetObjectPreComputedCase* code = (GetObjectPreComputedCase*)currentCode; + const Value& willBeObject = registerFile[code->m_objectRegisterIndex]; + registerFile[code->m_objectRegisterIndex] = getObjectPrecomputedCaseOperation(state, willBeObject, code->m_propertyName, code->m_inlineCache).second; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - GetObjectPreComputedCaseOpcodeLbl: - { - GetObjectPreComputedCase* code = (GetObjectPreComputedCase*)currentCode; - const Value& willBeObject = registerFile[code->m_objectRegisterIndex]; - registerFile[code->m_objectRegisterIndex] = getObjectPrecomputedCaseOperation(state, willBeObject, code->m_propertyName, code->m_inlineCache).second; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + SetObjectPreComputedCaseOpcodeLbl : { + SetObjectPreComputedCase* code = (SetObjectPreComputedCase*)currentCode; + const Value& willBeObject = registerFile[code->m_objectRegisterIndex]; + setObjectPreComputedCaseOperation(state, willBeObject, code->m_propertyName, registerFile[code->m_loadRegisterIndex], code->m_inlineCache); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - SetObjectPreComputedCaseOpcodeLbl: - { - SetObjectPreComputedCase* code = (SetObjectPreComputedCase*)currentCode; - const Value& willBeObject = registerFile[code->m_objectRegisterIndex]; - setObjectPreComputedCaseOperation(state, willBeObject, code->m_propertyName, registerFile[code->m_loadRegisterIndex], code->m_inlineCache); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); + GetGlobalObjectOpcodeLbl : { + GetGlobalObject* code = (GetGlobalObject*)currentCode; + auto result = getObjectPrecomputedCaseOperation(state, state.context()->globalObject(), code->m_propertyName, code->m_inlineCache); + if (UNLIKELY(!result.first)) { + ErrorObject::throwBuiltinError(state, ErrorObject::ReferenceError, code->m_propertyName.string(), false, String::emptyString, errorMessage_IsNotDefined); } + registerFile[code->m_registerIndex] = result.second; + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - GetGlobalObjectOpcodeLbl: - { - GetGlobalObject* code = (GetGlobalObject*)currentCode; - auto result = getObjectPrecomputedCaseOperation(state, state.context()->globalObject(), code->m_propertyName, code->m_inlineCache); - if (UNLIKELY(!result.first)) { - ErrorObject::throwBuiltinError(state, ErrorObject::ReferenceError, code->m_propertyName.string(), false, String::emptyString, errorMessage_IsNotDefined); - } - registerFile[code->m_registerIndex] = result.second; - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + SetGlobalObjectOpcodeLbl : { + SetGlobalObject* code = (SetGlobalObject*)currentCode; + setObjectPreComputedCaseOperation(state, state.context()->globalObject(), code->m_propertyName, registerFile[code->m_registerIndex], code->m_inlineCache); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - SetGlobalObjectOpcodeLbl: - { - SetGlobalObject* code = (SetGlobalObject*)currentCode; - setObjectPreComputedCaseOperation(state, state.context()->globalObject(), code->m_propertyName, registerFile[code->m_registerIndex], code->m_inlineCache); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + JumpOpcodeLbl : { + Jump* code = (Jump*)currentCode; + ASSERT(code->m_jumpPosition != SIZE_MAX); + programCounter = jumpTo(codeBuffer, code->m_jumpPosition); + NEXT_INSTRUCTION(); + } - JumpOpcodeLbl: - { - Jump* code = (Jump *)currentCode; - ASSERT(code->m_jumpPosition != SIZE_MAX); + JumpIfTrueOpcodeLbl : { + JumpIfTrue* code = (JumpIfTrue*)currentCode; + ASSERT(code->m_jumpPosition != SIZE_MAX); + if (registerFile[code->m_registerIndex].toBoolean(state)) { programCounter = jumpTo(codeBuffer, code->m_jumpPosition); - NEXT_INSTRUCTION(); - } - - JumpIfTrueOpcodeLbl: - { - JumpIfTrue* code = (JumpIfTrue*)currentCode; - ASSERT(code->m_jumpPosition != SIZE_MAX); - if (registerFile[code->m_registerIndex].toBoolean(state)) { - programCounter = jumpTo(codeBuffer, code->m_jumpPosition); - } else { - executeNextCode(programCounter); - } - NEXT_INSTRUCTION(); + } else { + executeNextCode(programCounter); } + NEXT_INSTRUCTION(); + } - JumpIfFalseOpcodeLbl: - { - JumpIfFalse* code = (JumpIfFalse*)currentCode; - ASSERT(code->m_jumpPosition != SIZE_MAX); - if (!registerFile[code->m_registerIndex].toBoolean(state)) { - programCounter = jumpTo(codeBuffer, code->m_jumpPosition); - } else { - executeNextCode(programCounter); - } - NEXT_INSTRUCTION(); + JumpIfFalseOpcodeLbl : { + JumpIfFalse* code = (JumpIfFalse*)currentCode; + ASSERT(code->m_jumpPosition != SIZE_MAX); + if (!registerFile[code->m_registerIndex].toBoolean(state)) { + programCounter = jumpTo(codeBuffer, code->m_jumpPosition); + } else { + executeNextCode(programCounter); } + NEXT_INSTRUCTION(); + } - CallFunctionOpcodeLbl: - { - CallFunction* code = (CallFunction*)currentCode; - const Value& receiver = registerFile[code->m_registerIndex]; - const Value& callee = registerFile[code->m_registerIndex + 1]; - registerFile[code->m_registerIndex] = FunctionObject::call(callee, state, receiver, code->m_argumentCount, ®isterFile[code->m_registerIndex + 2]); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + CallFunctionOpcodeLbl : { + CallFunction* code = (CallFunction*)currentCode; + const Value& receiver = registerFile[code->m_registerIndex]; + const Value& callee = registerFile[code->m_registerIndex + 1]; + registerFile[code->m_registerIndex] = FunctionObject::call(callee, state, receiver, code->m_argumentCount, ®isterFile[code->m_registerIndex + 2]); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - DeclareFunctionDeclarationOpcodeLbl: - { - DeclareFunctionDeclaration* code = (DeclareFunctionDeclaration*)currentCode; - registerFile[0] = new FunctionObject(state, code->m_codeBlock); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + DeclareFunctionDeclarationOpcodeLbl : { + DeclareFunctionDeclaration* code = (DeclareFunctionDeclaration*)currentCode; + registerFile[0] = new FunctionObject(state, code->m_codeBlock); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - ReturnFunctionOpcodeLbl: - { - ReturnFunction* code = (ReturnFunction*)currentCode; - if (code->m_registerIndex != SIZE_MAX) - *state.exeuctionResult() = registerFile[code->m_registerIndex]; - else - *state.exeuctionResult() = Value(); - return; - } + ReturnFunctionOpcodeLbl : { + ReturnFunction* code = (ReturnFunction*)currentCode; + if (code->m_registerIndex != SIZE_MAX) + *state.exeuctionResult() = registerFile[code->m_registerIndex]; + else + *state.exeuctionResult() = Value(); + return; + } - BinaryBitwiseAndOpcodeLbl: - { - BinaryBitwiseAnd* code = (BinaryBitwiseAnd*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(left.toInt32(state) & right.toInt32(state)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryBitwiseAndOpcodeLbl : { + BinaryBitwiseAnd* code = (BinaryBitwiseAnd*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(left.toInt32(state) & right.toInt32(state)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryBitwiseOrOpcodeLbl: - { - BinaryBitwiseOr* code = (BinaryBitwiseOr*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(left.toInt32(state) | right.toInt32(state)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryBitwiseOrOpcodeLbl : { + BinaryBitwiseOr* code = (BinaryBitwiseOr*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(left.toInt32(state) | right.toInt32(state)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryBitwiseXorOpcodeLbl: - { - BinaryBitwiseXor* code = (BinaryBitwiseXor*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - registerFile[code->m_srcIndex0] = Value(left.toInt32(state) ^ right.toInt32(state)); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryBitwiseXorOpcodeLbl : { + BinaryBitwiseXor* code = (BinaryBitwiseXor*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + registerFile[code->m_srcIndex0] = Value(left.toInt32(state) ^ right.toInt32(state)); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryLeftShiftOpcodeLbl: - { - BinaryLeftShift* code = (BinaryLeftShift*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - int32_t lnum = left.toInt32(state); - int32_t rnum = right.toInt32(state); - lnum <<= ((unsigned int)rnum) & 0x1F; - registerFile[code->m_srcIndex0] = Value(lnum); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryLeftShiftOpcodeLbl : { + BinaryLeftShift* code = (BinaryLeftShift*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + int32_t lnum = left.toInt32(state); + int32_t rnum = right.toInt32(state); + lnum <<= ((unsigned int)rnum) & 0x1F; + registerFile[code->m_srcIndex0] = Value(lnum); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinarySignedRightShiftOpcodeLbl: - { - BinarySignedRightShift* code = (BinarySignedRightShift*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - int32_t lnum = left.toInt32(state); - int32_t rnum = right.toInt32(state); - lnum >>= ((unsigned int)rnum) & 0x1F; - registerFile[code->m_srcIndex0] = Value(lnum); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinarySignedRightShiftOpcodeLbl : { + BinarySignedRightShift* code = (BinarySignedRightShift*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + int32_t lnum = left.toInt32(state); + int32_t rnum = right.toInt32(state); + lnum >>= ((unsigned int)rnum) & 0x1F; + registerFile[code->m_srcIndex0] = Value(lnum); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - BinaryUnsignedRightShiftOpcodeLbl: - { - BinaryUnsignedRightShift* code = (BinaryUnsignedRightShift*)currentCode; - const Value& left = registerFile[code->m_srcIndex0]; - const Value& right = registerFile[code->m_srcIndex1]; - uint32_t lnum = left.toUint32(state); - uint32_t rnum = right.toUint32(state); - lnum = (lnum) >> ((rnum) & 0x1F); - registerFile[code->m_srcIndex0] = Value(lnum); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + BinaryUnsignedRightShiftOpcodeLbl : { + BinaryUnsignedRightShift* code = (BinaryUnsignedRightShift*)currentCode; + const Value& left = registerFile[code->m_srcIndex0]; + const Value& right = registerFile[code->m_srcIndex1]; + uint32_t lnum = left.toUint32(state); + uint32_t rnum = right.toUint32(state); + lnum = (lnum) >> ((rnum)&0x1F); + registerFile[code->m_srcIndex0] = Value(lnum); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - ThrowOperationOpcodeLbl: - { - ThrowOperation* code = (ThrowOperation*)currentCode; - state.context()->throwException(state, registerFile[code->m_registerIndex]); - } + ThrowOperationOpcodeLbl : { + ThrowOperation* code = (ThrowOperation*)currentCode; + state.context()->throwException(state, registerFile[code->m_registerIndex]); + } - JumpComplexCaseOpcodeLbl: - { - JumpComplexCase* code = (JumpComplexCase*)currentCode; - ASSERT(code->m_jumpPosition != SIZE_MAX); - programCounter = jumpTo(codeBuffer, code->m_jumpPosition); - // TODO - RELEASE_ASSERT_NOT_REACHED(); - NEXT_INSTRUCTION(); - } + JumpComplexCaseOpcodeLbl : { + JumpComplexCase* code = (JumpComplexCase*)currentCode; + ASSERT(code->m_jumpPosition != SIZE_MAX); + programCounter = jumpTo(codeBuffer, code->m_jumpPosition); + // TODO + RELEASE_ASSERT_NOT_REACHED(); + NEXT_INSTRUCTION(); + } - CreateObjectOpcodeLbl: - { - CreateObject* code = (CreateObject*)currentCode; - registerFile[code->m_registerIndex] = new Object(state); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + CreateObjectOpcodeLbl : { + CreateObject* code = (CreateObject*)currentCode; + registerFile[code->m_registerIndex] = new Object(state); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - NewOperationOpcodeLbl: - { - NewOperation* code = (NewOperation*)currentCode; - registerFile[code->m_registerIndex] = newOperation(state, registerFile[code->m_registerIndex], code->m_argumentCount, ®isterFile[code->m_registerIndex + 1]); - executeNextCode(programCounter); - NEXT_INSTRUCTION(); - } + NewOperationOpcodeLbl : { + NewOperation* code = (NewOperation*)currentCode; + registerFile[code->m_registerIndex] = newOperation(state, registerFile[code->m_registerIndex], code->m_argumentCount, ®isterFile[code->m_registerIndex + 1]); + executeNextCode(programCounter); + NEXT_INSTRUCTION(); + } - EndOpcodeLbl: - { - ASSERT(codeBlock->isGlobalScopeCodeBlock()); - *state.exeuctionResult() = registerFile[0]; - return; - } + EndOpcodeLbl : { + ASSERT(codeBlock->isGlobalScopeCodeBlock()); + *state.exeuctionResult() = registerFile[0]; + return; + } - CallNativeFunctionOpcodeLbl: - { - CallNativeFunction* code = (CallNativeFunction*)currentCode; - Value* argv = record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->argv(); - size_t argc = record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->argc(); - if (argc < record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->functionObject()->codeBlock()->parametersInfomation().size()) { - size_t len = record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->functionObject()->codeBlock()->parametersInfomation().size(); - Value* newArgv = ALLOCA(sizeof(Value)*len, Value, state); - for (size_t i = 0; i < argc; i ++) { - newArgv[i] = argv[i]; - } - for (size_t i = argc; i < len; i ++) { - newArgv[i] = Value(); - } - argv = newArgv; - argc = record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->functionObject()->codeBlock()->parametersInfomation().size(); + CallNativeFunctionOpcodeLbl : { + CallNativeFunction* code = (CallNativeFunction*)currentCode; + Value* argv = record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->argv(); + size_t argc = record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->argc(); + if (argc < record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->functionObject()->codeBlock()->parametersInfomation().size()) { + size_t len = record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->functionObject()->codeBlock()->parametersInfomation().size(); + Value* newArgv = ALLOCA(sizeof(Value) * len, Value, state); + for (size_t i = 0; i < argc; i++) { + newArgv[i] = argv[i]; } - *state.exeuctionResult() = code->m_fn(state, record->getThisBinding(), argc, argv, record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->isNewExpression()); - return; + for (size_t i = argc; i < len; i++) { + newArgv[i] = Value(); + } + argv = newArgv; + argc = record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->functionObject()->codeBlock()->parametersInfomation().size(); } + *state.exeuctionResult() = code->m_fn(state, record->getThisBinding(), argc, argv, record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->isNewExpression()); + return; + } } - FillOpcodeTable: - { +FillOpcodeTable : { #define REGISTER_TABLE(opcode, pushCount, popCount) \ - registerOpcode(opcode##Opcode, &&opcode##OpcodeLbl); - FOR_EACH_BYTECODE_OP(REGISTER_TABLE); + registerOpcode(opcode##Opcode, &&opcode##OpcodeLbl); + FOR_EACH_BYTECODE_OP(REGISTER_TABLE); #undef REGISTER_TABLE - } +} return; } @@ -912,15 +858,15 @@ inline std::pair ByteCodeInterpreter::getObjectPrecomputedCaseOpera if (LIKELY(willBeObject.isPointerValue())) { if (LIKELY(willBeObject.asPointerValue()->isObject())) { targetObj = obj = willBeObject.asObject(); -GetObjectPreComputedCaseInlineCacheOperation: + GetObjectPreComputedCaseInlineCacheOperation: unsigned currentCacheIndex = 0; const size_t cacheFillCount = inlineCache.m_cache.size(); - for (;currentCacheIndex < cacheFillCount ; currentCacheIndex++) { + for (; currentCacheIndex < cacheFillCount; currentCacheIndex++) { const GetObjectInlineCacheData& data = inlineCache.m_cache[currentCacheIndex]; - const ObjectStructureChain * const cachedHiddenClassChain = &data.m_cachedhiddenClassChain; + const ObjectStructureChain* const cachedHiddenClassChain = &data.m_cachedhiddenClassChain; const size_t& cachedIndex = data.m_cachedIndex; const size_t cSiz = cachedHiddenClassChain->size() - 1; - for (size_t i = 0; i < cSiz; i ++) { + for (size_t i = 0; i < cSiz; i++) { if (UNLIKELY((*cachedHiddenClassChain)[i] != obj->structure())) { goto GetObjecPreComputedCacheMiss; } @@ -937,12 +883,14 @@ inline std::pair ByteCodeInterpreter::getObjectPrecomputedCaseOpera } else { return std::make_pair(false, Value()); } - } GetObjecPreComputedCacheMiss: { } + } + GetObjecPreComputedCacheMiss : { + } } // cache miss. inlineCache.m_executeCount++; - if (inlineCache.m_executeCount <= 3/* || UNLIKELY(willBeObject->toObject()->hasPropertyInterceptor())*/) { + if (inlineCache.m_executeCount <= 3 /* || UNLIKELY(willBeObject->toObject()->hasPropertyInterceptor())*/) { auto result = willBeObject.toObject(state)->get(state, ObjectPropertyName(state, name)); return std::make_pair(result.hasValue(), result.value()); } @@ -1014,7 +962,7 @@ inline void ByteCodeInterpreter::setObjectPreComputedCaseOperation(ExecutionStat } else if (inlineCache.m_hiddenClassWillBe) { int cSiz = inlineCache.m_cachedhiddenClassChain.size(); bool miss = false; - for (int i = 0; i < cSiz - 1; i ++) { + for (int i = 0; i < cSiz - 1; i++) { if (inlineCache.m_cachedhiddenClassChain[i] != obj->structure()) { miss = true; break; @@ -1081,5 +1029,4 @@ inline void ByteCodeInterpreter::setObjectPreComputedCaseOperation(ExecutionStat Object* obj = willBeObject.toObject(state); obj->setThrowsExceptionWhenStrictMode(state, ObjectPropertyName(state, name), value, obj); } - } diff --git a/src/interpreter/ByteCodeInterpreter.h b/src/interpreter/ByteCodeInterpreter.h index 4d2be92d2..5df08dbc6 100644 --- a/src/interpreter/ByteCodeInterpreter.h +++ b/src/interpreter/ByteCodeInterpreter.h @@ -1,10 +1,10 @@ #ifndef __EscargotByteCodeInterpreter__ #define __EscargotByteCodeInterpreter__ -#include "runtime/Value.h" -#include "runtime/String.h" -#include "runtime/ExecutionState.h" #include "parser/CodeBlock.h" +#include "runtime/ExecutionState.h" +#include "runtime/String.h" +#include "runtime/Value.h" namespace Escargot { @@ -29,7 +29,6 @@ class ByteCodeInterpreter { static inline std::pair getObjectPrecomputedCaseOperation(ExecutionState& state, const Value& willBeObject, const PropertyName& name, GetObjectInlineCache& inlineCache); static inline void setObjectPreComputedCaseOperation(ExecutionState& state, const Value& willBeObject, const PropertyName& name, const Value& value, SetObjectInlineCache& inlineCache); }; - } #endif diff --git a/src/parser/CodeBlock.cpp b/src/parser/CodeBlock.cpp index cbc6f149a..4721373e6 100644 --- a/src/parser/CodeBlock.cpp +++ b/src/parser/CodeBlock.cpp @@ -42,7 +42,7 @@ CodeBlock::CodeBlock(Context* ctx, const NativeFunctionInfo& info) m_byteCodeBlock = new ByteCodeBlock(); CallNativeFunction code(info.m_nativeFunction); code.assignOpcodeInAddress(); - char* first = (char *)&code; + char* first = (char*)&code; m_byteCodeBlock->m_code.insert(m_byteCodeBlock->m_code.end(), first, first + sizeof(CallNativeFunction)); } @@ -76,7 +76,7 @@ CodeBlock::CodeBlock(Context* ctx, Script* script, StringView src, bool isStrict m_canAllocateEnvironmentOnStack = false; m_needsComplexParameterCopy = false; - for (size_t i = 0; i < innerIdentifiers.size(); i ++) { + for (size_t i = 0; i < innerIdentifiers.size(); i++) { IdentifierInfo info; info.m_name = innerIdentifiers[i]; info.m_needToAllocateOnStack = false; @@ -86,7 +86,7 @@ CodeBlock::CodeBlock(Context* ctx, Script* script, StringView src, bool isStrict } CodeBlock::CodeBlock(Context* ctx, Script* script, StringView src, NodeLOC sourceElementStart, bool isStrict, size_t astNodeStartIndex, AtomicString functionName, const AtomicStringVector& parameterNames, const AtomicStringVector& innerIdentifiers, - CodeBlock* parentBlock, CodeBlockInitFlag initFlags) + CodeBlock* parentBlock, CodeBlockInitFlag initFlags) : m_context(ctx) , m_script(script) , m_src(src) @@ -147,7 +147,7 @@ CodeBlock::CodeBlock(Context* ctx, Script* script, StringView src, NodeLOC sourc m_canAllocateEnvironmentOnStack = false; } - for (size_t i = 0; i < innerIdentifiers.size(); i ++) { + for (size_t i = 0; i < innerIdentifiers.size(); i++) { IdentifierInfo info; info.m_name = innerIdentifiers[i]; info.m_needToAllocateOnStack = m_canUseIndexedVariableStorage; @@ -160,7 +160,7 @@ CodeBlock::CodeBlock(Context* ctx, Script* script, StringView src, NodeLOC sourc bool CodeBlock::tryCaptureIdentifiersFromChildCodeBlock(AtomicString name) { - for (size_t i = 0; i < m_identifierInfos.size(); i ++) { + for (size_t i = 0; i < m_identifierInfos.size(); i++) { if (m_identifierInfos[i].m_name == name) { m_canAllocateEnvironmentOnStack = false; m_identifierInfos[i].m_needToAllocateOnStack = false; @@ -201,7 +201,7 @@ bool CodeBlock::hasNonConfiguableNameOnGlobal(const AtomicString& name) void CodeBlock::computeVariables() { if (m_functionName.string()->length()) { - for (size_t i = 0; i < m_identifierInfos.size(); i ++) { + for (size_t i = 0; i < m_identifierInfos.size(); i++) { if (m_identifierInfos[i].m_name == m_functionName) { m_functionNameIndex = i; break; @@ -212,7 +212,7 @@ void CodeBlock::computeVariables() if (canUseIndexedVariableStorage()) { size_t s = 0; size_t h = 0; - for (size_t i = 0; i < m_identifierInfos.size(); i ++) { + for (size_t i = 0; i < m_identifierInfos.size(); i++) { if (m_identifierInfos[i].m_name == m_functionName) { m_functionNameSaveInfo.m_isAllocatedOnStack = m_identifierInfos[i].m_needToAllocateOnStack; if (m_identifierInfos[i].m_needToAllocateOnStack) { @@ -238,7 +238,7 @@ void CodeBlock::computeVariables() m_parametersInfomation.resizeWithUninitializedValues(siz); size_t heapCount = 0; size_t stackCount = 0; - for (size_t i = 0; i < siz; i ++) { + for (size_t i = 0; i < siz; i++) { bool isHeap = !m_identifierInfos[i].m_needToAllocateOnStack; m_parametersInfomation[i].m_isHeapAllocated = isHeap; if (isHeap) { @@ -251,5 +251,4 @@ void CodeBlock::computeVariables() } } } - } diff --git a/src/parser/CodeBlock.h b/src/parser/CodeBlock.h index ce87fff37..6e64dbdee 100644 --- a/src/parser/CodeBlock.h +++ b/src/parser/CodeBlock.h @@ -1,10 +1,10 @@ #ifndef __EscargotCodeBlock__ #define __EscargotCodeBlock__ -#include "runtime/String.h" -#include "runtime/AtomicString.h" #include "parser/ast/Node.h" +#include "runtime/AtomicString.h" #include "runtime/ExecutionState.h" +#include "runtime/String.h" namespace Escargot { @@ -54,6 +54,7 @@ class CodeBlock : public gc { friend class ScriptParser; friend class ByteCodeGenerator; friend class FunctionObject; + public: // init native CodeBlock CodeBlock(Context* ctx, const NativeFunctionInfo& info); @@ -119,7 +120,7 @@ class CodeBlock : public gc { bool hasName(const AtomicString& name) { - for (size_t i = 0; i < m_identifierInfos.size(); i ++) { + for (size_t i = 0; i < m_identifierInfos.size(); i++) { if (m_identifierInfos[i].m_name == name) { return true; } @@ -129,7 +130,7 @@ class CodeBlock : public gc { size_t findName(const AtomicString& name) { - for (size_t i = 0; i < m_identifierInfos.size(); i ++) { + for (size_t i = 0; i < m_identifierInfos.size(); i++) { if (m_identifierInfos[i].m_name == name) { return i; } @@ -320,7 +321,7 @@ class CodeBlock : public gc { size_t m_identifierOnStackCount; size_t m_identifierOnHeapCount; size_t m_functionNameIndex; - struct FunctionNameSaveInfo{ + struct FunctionNameSaveInfo { bool m_isAllocatedOnStack; size_t m_index; } m_functionNameSaveInfo; @@ -344,7 +345,6 @@ class CodeBlock : public gc { ASTScopeContext* m_scopeContext; #endif }; - } #endif diff --git a/src/parser/Script.cpp b/src/parser/Script.cpp index 196f6a2e8..08300e4a5 100644 --- a/src/parser/Script.cpp +++ b/src/parser/Script.cpp @@ -42,7 +42,7 @@ Script::ScriptExecuteResult Script::execute(Context* ctx) result.result = sandBoxResult.result; result.error.errorValue = sandBoxResult.error; if (!sandBoxResult.error.isEmpty()) { - for (size_t i = 0; i < sandBoxResult.stackTraceData.size(); i ++) { + for (size_t i = 0; i < sandBoxResult.stackTraceData.size(); i++) { ScriptExecuteResult::Error::StackTrace t; t.fileName = sandBoxResult.stackTraceData[i].fileName; t.line = sandBoxResult.stackTraceData[i].loc.line; @@ -52,5 +52,4 @@ Script::ScriptExecuteResult Script::execute(Context* ctx) } return result; } - } diff --git a/src/parser/Script.h b/src/parser/Script.h index 56afa24b3..7ff84528c 100644 --- a/src/parser/Script.h +++ b/src/parser/Script.h @@ -15,6 +15,7 @@ class Script : public gc { , m_topCodeBlock(nullptr) { } + public: struct ScriptExecuteResult { MAKE_STACK_ALLOCATED(); @@ -34,11 +35,11 @@ class Script : public gc { { return m_fileName; } + protected: String* m_fileName; CodeBlock* m_topCodeBlock; }; - } #endif diff --git a/src/parser/ScriptParser.cpp b/src/parser/ScriptParser.cpp index f16bef701..5bb7a168f 100644 --- a/src/parser/ScriptParser.cpp +++ b/src/parser/ScriptParser.cpp @@ -21,16 +21,10 @@ CodeBlock* ScriptParser::generateCodeBlockTreeFromASTWalker(Context* ctx, String codeBlock = new CodeBlock(ctx, script, source, scopeCtx->m_isStrict, scopeCtx->m_locStart, scopeCtx->m_names); } else { codeBlock = new CodeBlock(ctx, script, StringView(source, scopeCtx->m_locStart.index, scopeCtx->m_locEnd.index), - scopeCtx->m_locStart, - scopeCtx->m_isStrict, scopeCtx->m_nodeStartIndex, - scopeCtx->m_functionName, scopeCtx->m_parameters, scopeCtx->m_names, parentCodeBlock, - (CodeBlock::CodeBlockInitFlag) - ((scopeCtx->m_hasEval ? CodeBlock::CodeBlockHasEval : 0) | - (scopeCtx->m_hasWith ? CodeBlock::CodeBlockHasWith : 0) | - (scopeCtx->m_hasYield ? CodeBlock::CodeBlockHasYield : 0) | - (scopeCtx->m_associateNode->type() == FunctionExpression ? CodeBlock::CodeBlockIsFunctionExpression : 0) | - (scopeCtx->m_associateNode->type() == FunctionDeclaration ? CodeBlock::CodeBlockIsFunctionDeclaration : 0) - )); + scopeCtx->m_locStart, + scopeCtx->m_isStrict, scopeCtx->m_nodeStartIndex, + scopeCtx->m_functionName, scopeCtx->m_parameters, scopeCtx->m_names, parentCodeBlock, + (CodeBlock::CodeBlockInitFlag)((scopeCtx->m_hasEval ? CodeBlock::CodeBlockHasEval : 0) | (scopeCtx->m_hasWith ? CodeBlock::CodeBlockHasWith : 0) | (scopeCtx->m_hasYield ? CodeBlock::CodeBlockHasYield : 0) | (scopeCtx->m_associateNode->type() == FunctionExpression ? CodeBlock::CodeBlockIsFunctionExpression : 0) | (scopeCtx->m_associateNode->type() == FunctionDeclaration ? CodeBlock::CodeBlockIsFunctionDeclaration : 0))); } #ifndef NDEBUG @@ -48,7 +42,7 @@ CodeBlock* ScriptParser::generateCodeBlockTreeFromASTWalker(Context* ctx, String } } - for (size_t i = 0; i < scopeCtx->m_usingNames.size(); i ++) { + for (size_t i = 0; i < scopeCtx->m_usingNames.size(); i++) { AtomicString uname = scopeCtx->m_usingNames[i]; if (!codeBlock->hasName(uname)) { CodeBlock* c = codeBlock->parentCodeBlock(); @@ -61,7 +55,7 @@ CodeBlock* ScriptParser::generateCodeBlockTreeFromASTWalker(Context* ctx, String } } - for (size_t i = 0 ; i < scopeCtx->m_childScopes.size(); i ++) { + for (size_t i = 0; i < scopeCtx->m_childScopes.size(); i++) { codeBlock->appendChildBlock(generateCodeBlockTreeFromASTWalker(ctx, source, script, scopeCtx->m_childScopes[i], codeBlock)); } @@ -90,40 +84,42 @@ ScriptParser::ScriptParserResult ScriptParser::parse(StringView scriptSource, St topCodeBlock->m_cachedASTNode = program; script->m_topCodeBlock = topCodeBlock; - // dump Code Block +// dump Code Block #ifndef NDEBUG if (getenv("DUMP_CODEBLOCK_TREE") && strlen(getenv("DUMP_CODEBLOCK_TREE"))) { + std::function fn = [&](CodeBlock* cb, size_t depth) { - std::function fn = [&](CodeBlock* cb, size_t depth) { - -#define PRINT_TAB() for (size_t i = 0; i < depth; i ++) { printf(" "); } +#define PRINT_TAB() \ + for (size_t i = 0; i < depth; i++) { \ + printf(" "); \ + } PRINT_TAB() printf("CodeBlock %s (%d:%d -> %d:%d)(%s, %s) (E:%d, W:%d, Y:%d)\n", cb->m_functionName.string()->toUTF8StringData().data(), - (int)cb->m_locStart.line, - (int)cb->m_locStart.column, - (int)cb->m_locEnd.line, - (int)cb->m_locEnd.column, - cb->m_canAllocateEnvironmentOnStack ? "Stack" : "Heap", - cb->m_canUseIndexedVariableStorage ? "Indexed" : "Named", - (int)cb->m_hasEval, (int)cb->m_hasWith, (int)cb->m_hasYield); + (int)cb->m_locStart.line, + (int)cb->m_locStart.column, + (int)cb->m_locEnd.line, + (int)cb->m_locEnd.column, + cb->m_canAllocateEnvironmentOnStack ? "Stack" : "Heap", + cb->m_canUseIndexedVariableStorage ? "Indexed" : "Named", + (int)cb->m_hasEval, (int)cb->m_hasWith, (int)cb->m_hasYield); PRINT_TAB() printf("Names: "); - for (size_t i = 0; i < cb->m_identifierInfos.size(); i ++) { + for (size_t i = 0; i < cb->m_identifierInfos.size(); i++) { printf("%s(%s, %d), ", cb->m_identifierInfos[i].m_name.string()->toUTF8StringData().data(), - cb->m_identifierInfos[i].m_needToAllocateOnStack ? "Stack" : "Heap", (int)cb->m_identifierInfos[i].m_indexForIndexedStorage); + cb->m_identifierInfos[i].m_needToAllocateOnStack ? "Stack" : "Heap", (int)cb->m_identifierInfos[i].m_indexForIndexedStorage); } puts(""); PRINT_TAB() printf("Using Names: "); - for (size_t i = 0; i < cb->m_scopeContext->m_usingNames.size(); i ++) { + for (size_t i = 0; i < cb->m_scopeContext->m_usingNames.size(); i++) { printf("%s, ", cb->m_scopeContext->m_usingNames[i].string()->toUTF8StringData().data()); } puts(""); - for (size_t i = 0; i < cb->m_childBlocks.size(); i ++) { + for (size_t i = 0; i < cb->m_childBlocks.size(); i++) { fn(cb->m_childBlocks[i], depth + 1); } @@ -132,7 +128,7 @@ ScriptParser::ScriptParserResult ScriptParser::parse(StringView scriptSource, St } #endif - } catch(esprima::Error* orgError) { + } catch (esprima::Error* orgError) { script = nullptr; error = new ScriptParseError(); error->column = orgError->column; @@ -152,10 +148,9 @@ Node* ScriptParser::parseFunction(CodeBlock* codeBlock) try { Node* body = esprima::parseSingleFunction(m_context, codeBlock); return body; - } catch(esprima::Error* orgError) { + } catch (esprima::Error* orgError) { // RELEASE_ASSERT_NOT_REACHED(); } } - } diff --git a/src/parser/ScriptParser.h b/src/parser/ScriptParser.h index d4ac18e0a..909bfe11b 100644 --- a/src/parser/ScriptParser.h +++ b/src/parser/ScriptParser.h @@ -1,8 +1,8 @@ #ifndef __EscargotScriptParser__ #define __EscargotScriptParser__ -#include "runtime/String.h" #include "parser/Script.h" +#include "runtime/String.h" namespace Escargot { @@ -49,7 +49,6 @@ class ScriptParser : public gc { Context* m_context; }; - } #endif diff --git a/src/parser/ast/AST.h b/src/parser/ast/AST.h index a897ef33a..e63856ee3 100644 --- a/src/parser/ast/AST.h +++ b/src/parser/ast/AST.h @@ -18,7 +18,6 @@ #define AST_h #include "ArrayExpressionNode.h" -#include "AssignmentExpressionSimpleNode.h" #include "AssignmentExpressionBitwiseAndNode.h" #include "AssignmentExpressionBitwiseOrNode.h" #include "AssignmentExpressionBitwiseXorNode.h" @@ -29,8 +28,8 @@ #include "AssignmentExpressionMultiplyNode.h" #include "AssignmentExpressionPlusNode.h" #include "AssignmentExpressionSignedRightShiftNode.h" +#include "AssignmentExpressionSimpleNode.h" #include "AssignmentExpressionUnsignedRightShiftNode.h" -#include "Node.h" #include "BinaryExpressionBitwiseAndNode.h" #include "BinaryExpressionBitwiseOrNode.h" #include "BinaryExpressionBitwiseXorNode.h" @@ -54,49 +53,47 @@ #include "BinaryExpressionSignedRightShiftNode.h" #include "BinaryExpressionStrictEqualNode.h" #include "BinaryExpressionUnsignedRightShiftNode.h" -#include "UpdateExpressionDecrementPostfixNode.h" -#include "UpdateExpressionDecrementPrefixNode.h" -#include "UpdateExpressionIncrementPostfixNode.h" -#include "UpdateExpressionIncrementPrefixNode.h" #include "BlockStatementNode.h" -#include "BreakStatementNode.h" #include "BreakLabelStatementNode.h" +#include "BreakStatementNode.h" #include "CallExpressionNode.h" #include "CatchClauseNode.h" #include "ConditionalExpressionNode.h" -#include "ContinueStatementNode.h" #include "ContinueLabelStatementNode.h" +#include "ContinueStatementNode.h" +#include "DirectiveNode.h" +#include "DoWhileStatementNode.h" #include "EmptyNode.h" #include "EmptyStatementNode.h" #include "ExpressionNode.h" -#include "SequenceExpressionNode.h" #include "ExpressionStatementNode.h" +#include "ForInStatementNode.h" +#include "ForStatementNode.h" #include "FunctionDeclarationNode.h" #include "FunctionExpressionNode.h" #include "FunctionNode.h" #include "IdentifierNode.h" #include "IfStatementNode.h" -#include "ForInStatementNode.h" -#include "ForStatementNode.h" -#include "WhileStatementNode.h" -#include "DoWhileStatementNode.h" #include "LabeledStatementNode.h" #include "LiteralNode.h" -#include "DirectiveNode.h" -#include "RegExpLiteralNode.h" -#include "RestElementNode.h" #include "MemberExpressionNode.h" #include "NewExpressionNode.h" #include "Node.h" +#include "Node.h" #include "ObjectExpressionNode.h" #include "PatternNode.h" #include "ProgramNode.h" +#include "RegExpLiteralNode.h" +#include "RestElementNode.h" #include "ReturnStatmentNode.h" -#include "StatementNode.h" +#include "SequenceExpressionNode.h" #include "SpreadElementNode.h" -#include "SwitchStatementNode.h" +#include "StatementNode.h" #include "SwitchCaseNode.h" +#include "SwitchStatementNode.h" #include "ThisExpressionNode.h" +#include "ThrowStatementNode.h" +#include "TryStatementNode.h" #include "UnaryExpressionBitwiseNotNode.h" #include "UnaryExpressionDeleteNode.h" #include "UnaryExpressionLogicalNotNode.h" @@ -104,9 +101,12 @@ #include "UnaryExpressionPlusNode.h" #include "UnaryExpressionTypeOfNode.h" #include "UnaryExpressionVoidNode.h" +#include "UpdateExpressionDecrementPostfixNode.h" +#include "UpdateExpressionDecrementPrefixNode.h" +#include "UpdateExpressionIncrementPostfixNode.h" +#include "UpdateExpressionIncrementPrefixNode.h" #include "VariableDeclarationNode.h" #include "VariableDeclaratorNode.h" -#include "TryStatementNode.h" -#include "ThrowStatementNode.h" +#include "WhileStatementNode.h" #endif diff --git a/src/parser/ast/ArrayExpressionNode.h b/src/parser/ast/ArrayExpressionNode.h index 2c182bebe..e9d5d3218 100644 --- a/src/parser/ast/ArrayExpressionNode.h +++ b/src/parser/ast/ArrayExpressionNode.h @@ -34,7 +34,6 @@ class ArrayExpressionNode : public ExpressionNode { protected: ExpressionNodeVector m_elements; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionBitwiseAndNode.h b/src/parser/ast/AssignmentExpressionBitwiseAndNode.h index 84f61a606..7e6fd432d 100644 --- a/src/parser/ast/AssignmentExpressionBitwiseAndNode.h +++ b/src/parser/ast/AssignmentExpressionBitwiseAndNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionBitwiseAndNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -46,11 +46,11 @@ class AssignmentExpressionBitwiseAndNode : public ExpressionNode { codeBlock->pushCode(BinaryBitwiseAnd(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionBitwiseOrNode.h b/src/parser/ast/AssignmentExpressionBitwiseOrNode.h index 7ef953b99..051970b1d 100644 --- a/src/parser/ast/AssignmentExpressionBitwiseOrNode.h +++ b/src/parser/ast/AssignmentExpressionBitwiseOrNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionBitwiseOrNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -46,11 +46,11 @@ class AssignmentExpressionBitwiseOrNode : public ExpressionNode { codeBlock->pushCode(BinaryBitwiseOr(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionBitwiseXorNode.h b/src/parser/ast/AssignmentExpressionBitwiseXorNode.h index 949f044a0..96e7d22e1 100644 --- a/src/parser/ast/AssignmentExpressionBitwiseXorNode.h +++ b/src/parser/ast/AssignmentExpressionBitwiseXorNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionBitwiseXorNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -46,11 +46,11 @@ class AssignmentExpressionBitwiseXorNode : public ExpressionNode { codeBlock->pushCode(BinaryBitwiseXor(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionDivisionNode.h b/src/parser/ast/AssignmentExpressionDivisionNode.h index 4152bdf8d..61d00e0b7 100644 --- a/src/parser/ast/AssignmentExpressionDivisionNode.h +++ b/src/parser/ast/AssignmentExpressionDivisionNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionDivisionNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -46,11 +46,11 @@ class AssignmentExpressionDivisionNode : public ExpressionNode { codeBlock->pushCode(BinaryDivision(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionLeftShiftNode.h b/src/parser/ast/AssignmentExpressionLeftShiftNode.h index 4abd109b1..e8b1481aa 100644 --- a/src/parser/ast/AssignmentExpressionLeftShiftNode.h +++ b/src/parser/ast/AssignmentExpressionLeftShiftNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionLeftShiftNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -46,11 +46,11 @@ class AssignmentExpressionLeftShiftNode : public ExpressionNode { codeBlock->pushCode(BinaryLeftShift(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionMinusNode.h b/src/parser/ast/AssignmentExpressionMinusNode.h index b68064b9a..9d909201e 100644 --- a/src/parser/ast/AssignmentExpressionMinusNode.h +++ b/src/parser/ast/AssignmentExpressionMinusNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionMinusNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -46,11 +46,11 @@ class AssignmentExpressionMinusNode : public ExpressionNode { codeBlock->pushCode(BinaryMinus(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionModNode.h b/src/parser/ast/AssignmentExpressionModNode.h index 0e00b63ad..b4c9a84fa 100644 --- a/src/parser/ast/AssignmentExpressionModNode.h +++ b/src/parser/ast/AssignmentExpressionModNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionModNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -46,11 +46,11 @@ class AssignmentExpressionModNode : public ExpressionNode { codeBlock->pushCode(BinaryMod(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionMultiplyNode.h b/src/parser/ast/AssignmentExpressionMultiplyNode.h index 3795daa8f..80341f169 100644 --- a/src/parser/ast/AssignmentExpressionMultiplyNode.h +++ b/src/parser/ast/AssignmentExpressionMultiplyNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionMultiplyNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -51,7 +51,6 @@ class AssignmentExpressionMultiplyNode : public ExpressionNode { Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionPlusNode.h b/src/parser/ast/AssignmentExpressionPlusNode.h index 77cb558e5..467da7618 100644 --- a/src/parser/ast/AssignmentExpressionPlusNode.h +++ b/src/parser/ast/AssignmentExpressionPlusNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionPlusNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -46,11 +46,11 @@ class AssignmentExpressionPlusNode : public ExpressionNode { codeBlock->pushCode(BinaryPlus(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionSignedRightShiftNode.h b/src/parser/ast/AssignmentExpressionSignedRightShiftNode.h index 6a78cde85..39c93c84e 100644 --- a/src/parser/ast/AssignmentExpressionSignedRightShiftNode.h +++ b/src/parser/ast/AssignmentExpressionSignedRightShiftNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionSignedRightShiftNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -46,11 +46,11 @@ class AssignmentExpressionSignedRightShiftNode : public ExpressionNode { codeBlock->pushCode(BinarySignedRightShift(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionSimpleNode.h b/src/parser/ast/AssignmentExpressionSimpleNode.h index 0d5fc158a..24e9983b5 100644 --- a/src/parser/ast/AssignmentExpressionSimpleNode.h +++ b/src/parser/ast/AssignmentExpressionSimpleNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionSimpleNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" // #include "MemberExpressionNode.h" namespace Escargot { @@ -42,7 +42,6 @@ class AssignmentExpressionSimpleNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::AssignmentExpressionSimple; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_right->generateExpressionByteCode(codeBlock, context); @@ -53,7 +52,6 @@ class AssignmentExpressionSimpleNode : public ExpressionNode { Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/AssignmentExpressionUnsignedRightShiftNode.h b/src/parser/ast/AssignmentExpressionUnsignedRightShiftNode.h index a4c552dfc..8cdcfcb5f 100644 --- a/src/parser/ast/AssignmentExpressionUnsignedRightShiftNode.h +++ b/src/parser/ast/AssignmentExpressionUnsignedRightShiftNode.h @@ -18,8 +18,8 @@ #define AssignmentExpressionUnsignedRightShiftNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "IdentifierNode.h" +#include "PatternNode.h" namespace Escargot { @@ -45,11 +45,11 @@ class AssignmentExpressionUnsignedShiftNode : public ExpressionNode { codeBlock->pushCode(BinaryUnsignedRightShift(ByteCodeLOC(m_loc.index), src0, src1), context, this); m_left->generateStoreByteCode(codeBlock, context); } + protected: Node* m_left; // left: Pattern; Node* m_right; // right: Expression; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionBitwiseAndNode.h b/src/parser/ast/BinaryExpressionBitwiseAndNode.h index 68a5d8730..970b333f8 100644 --- a/src/parser/ast/BinaryExpressionBitwiseAndNode.h +++ b/src/parser/ast/BinaryExpressionBitwiseAndNode.h @@ -21,11 +21,11 @@ namespace Escargot { -class BinaryExpressionBitwiseAndNode: public ExpressionNode { +class BinaryExpressionBitwiseAndNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionBitwiseAndNode(Node *left, Node* right) + BinaryExpressionBitwiseAndNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionBitwiseAndNode: public ExpressionNode { codeBlock->pushCode(BinaryBitwiseAnd(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionBitwiseOrNode.h b/src/parser/ast/BinaryExpressionBitwiseOrNode.h index f6cfa2ea7..5948162d4 100644 --- a/src/parser/ast/BinaryExpressionBitwiseOrNode.h +++ b/src/parser/ast/BinaryExpressionBitwiseOrNode.h @@ -21,11 +21,11 @@ namespace Escargot { -class BinaryExpressionBitwiseOrNode: public ExpressionNode { +class BinaryExpressionBitwiseOrNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionBitwiseOrNode(Node *left, Node* right) + BinaryExpressionBitwiseOrNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionBitwiseOrNode: public ExpressionNode { codeBlock->pushCode(BinaryBitwiseOr(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionBitwiseXorNode.h b/src/parser/ast/BinaryExpressionBitwiseXorNode.h index 57f18acd2..170c70211 100644 --- a/src/parser/ast/BinaryExpressionBitwiseXorNode.h +++ b/src/parser/ast/BinaryExpressionBitwiseXorNode.h @@ -21,11 +21,11 @@ namespace Escargot { -class BinaryExpressionBitwiseXorNode: public ExpressionNode { +class BinaryExpressionBitwiseXorNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionBitwiseXorNode(Node *left, Node* right) + BinaryExpressionBitwiseXorNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionBitwiseXorNode: public ExpressionNode { codeBlock->pushCode(BinaryBitwiseXor(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionDivisionNode.h b/src/parser/ast/BinaryExpressionDivisionNode.h index 72b9f9728..f8d3de1de 100644 --- a/src/parser/ast/BinaryExpressionDivisionNode.h +++ b/src/parser/ast/BinaryExpressionDivisionNode.h @@ -25,7 +25,7 @@ class BinaryExpressionDivisionNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionDivisionNode(Node *left, Node* right) + BinaryExpressionDivisionNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -33,7 +33,6 @@ class BinaryExpressionDivisionNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::BinaryExpressionDivison; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_left->generateExpressionByteCode(codeBlock, context); @@ -45,11 +44,11 @@ class BinaryExpressionDivisionNode : public ExpressionNode { codeBlock->pushCode(BinaryDivision(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionEqualNode.h b/src/parser/ast/BinaryExpressionEqualNode.h index ef6cb524a..74f68cc3e 100644 --- a/src/parser/ast/BinaryExpressionEqualNode.h +++ b/src/parser/ast/BinaryExpressionEqualNode.h @@ -25,7 +25,7 @@ class BinaryExpressionEqualNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionEqualNode(Node *left, Node* right) + BinaryExpressionEqualNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -33,7 +33,6 @@ class BinaryExpressionEqualNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::BinaryExpressionEqual; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_left->generateExpressionByteCode(codeBlock, context); @@ -45,11 +44,11 @@ class BinaryExpressionEqualNode : public ExpressionNode { codeBlock->pushCode(BinaryEqual(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionGreaterThanNode.h b/src/parser/ast/BinaryExpressionGreaterThanNode.h index 2c126e968..232fafd78 100644 --- a/src/parser/ast/BinaryExpressionGreaterThanNode.h +++ b/src/parser/ast/BinaryExpressionGreaterThanNode.h @@ -25,7 +25,7 @@ class BinaryExpressionGreaterThanNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionGreaterThanNode(Node *left, Node* right) + BinaryExpressionGreaterThanNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionGreaterThanNode : public ExpressionNode { codeBlock->pushCode(BinaryGreaterThan(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionGreaterThanOrEqualNode.h b/src/parser/ast/BinaryExpressionGreaterThanOrEqualNode.h index 28dbe4e41..3d8f95890 100644 --- a/src/parser/ast/BinaryExpressionGreaterThanOrEqualNode.h +++ b/src/parser/ast/BinaryExpressionGreaterThanOrEqualNode.h @@ -25,7 +25,7 @@ class BinaryExpressionGreaterThanOrEqualNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionGreaterThanOrEqualNode(Node *left, Node* right) + BinaryExpressionGreaterThanOrEqualNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionGreaterThanOrEqualNode : public ExpressionNode { codeBlock->pushCode(BinaryGreaterThanOrEqual(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionInNode.h b/src/parser/ast/BinaryExpressionInNode.h index ddf6d6173..8cb24b710 100644 --- a/src/parser/ast/BinaryExpressionInNode.h +++ b/src/parser/ast/BinaryExpressionInNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionInNode : public ExpressionNode { public: - BinaryExpressionInNode(Node *left, Node* right) + BinaryExpressionInNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -31,12 +31,10 @@ class BinaryExpressionInNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::BinaryExpressionIn; } - protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionInstanceOfNode.h b/src/parser/ast/BinaryExpressionInstanceOfNode.h index 41e5c6bc7..83e70fcf2 100644 --- a/src/parser/ast/BinaryExpressionInstanceOfNode.h +++ b/src/parser/ast/BinaryExpressionInstanceOfNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionInstanceOfNode : public ExpressionNode { public: - BinaryExpressionInstanceOfNode(Node *left, Node* right) + BinaryExpressionInstanceOfNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -31,12 +31,10 @@ class BinaryExpressionInstanceOfNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::BinaryExpressionInstanceOf; } - protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionLeftShiftNode.h b/src/parser/ast/BinaryExpressionLeftShiftNode.h index 3005cf74d..1366d3f40 100644 --- a/src/parser/ast/BinaryExpressionLeftShiftNode.h +++ b/src/parser/ast/BinaryExpressionLeftShiftNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionLeftShiftNode : public ExpressionNode { public: - BinaryExpressionLeftShiftNode(Node *left, Node* right) + BinaryExpressionLeftShiftNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -42,11 +42,11 @@ class BinaryExpressionLeftShiftNode : public ExpressionNode { codeBlock->pushCode(BinaryLeftShift(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionLessThanNode.h b/src/parser/ast/BinaryExpressionLessThanNode.h index b0fdb4508..a9943dd91 100644 --- a/src/parser/ast/BinaryExpressionLessThanNode.h +++ b/src/parser/ast/BinaryExpressionLessThanNode.h @@ -25,7 +25,7 @@ class BinaryExpressionLessThanNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionLessThanNode(Node *left, Node* right) + BinaryExpressionLessThanNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionLessThanNode : public ExpressionNode { codeBlock->pushCode(BinaryLessThan(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionLessThanOrEqualNode.h b/src/parser/ast/BinaryExpressionLessThanOrEqualNode.h index 86bd19b26..1bf2853b2 100644 --- a/src/parser/ast/BinaryExpressionLessThanOrEqualNode.h +++ b/src/parser/ast/BinaryExpressionLessThanOrEqualNode.h @@ -25,7 +25,7 @@ class BinaryExpressionLessThanOrEqualNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionLessThanOrEqualNode(Node *left, Node* right) + BinaryExpressionLessThanOrEqualNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionLessThanOrEqualNode : public ExpressionNode { codeBlock->pushCode(BinaryLessThanOrEqual(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionLogicalAndNode.h b/src/parser/ast/BinaryExpressionLogicalAndNode.h index 446bec025..71d4da43f 100644 --- a/src/parser/ast/BinaryExpressionLogicalAndNode.h +++ b/src/parser/ast/BinaryExpressionLogicalAndNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionLogicalAndNode : public ExpressionNode { public: - BinaryExpressionLogicalAndNode(Node *left, Node* right) + BinaryExpressionLogicalAndNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -31,7 +31,6 @@ class BinaryExpressionLogicalAndNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::BinaryExpressionLogicalAnd; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_left->generateExpressionByteCode(codeBlock, context); @@ -42,11 +41,11 @@ class BinaryExpressionLogicalAndNode : public ExpressionNode { m_right->generateExpressionByteCode(codeBlock, context); codeBlock->peekCode(pos)->m_jumpPosition = codeBlock->currentCodeSize(); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionLogicalOrNode.h b/src/parser/ast/BinaryExpressionLogicalOrNode.h index 6d138c8fc..d8455b8ce 100644 --- a/src/parser/ast/BinaryExpressionLogicalOrNode.h +++ b/src/parser/ast/BinaryExpressionLogicalOrNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionLogicalOrNode : public ExpressionNode { public: - BinaryExpressionLogicalOrNode(Node *left, Node* right) + BinaryExpressionLogicalOrNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -31,7 +31,6 @@ class BinaryExpressionLogicalOrNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::BinaryExpressionLogicalOr; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_left->generateExpressionByteCode(codeBlock, context); @@ -41,11 +40,11 @@ class BinaryExpressionLogicalOrNode : public ExpressionNode { m_right->generateExpressionByteCode(codeBlock, context); codeBlock->peekCode(pos)->m_jumpPosition = codeBlock->currentCodeSize(); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionMinusNode.h b/src/parser/ast/BinaryExpressionMinusNode.h index f5d2ffce4..91b140531 100644 --- a/src/parser/ast/BinaryExpressionMinusNode.h +++ b/src/parser/ast/BinaryExpressionMinusNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionMinusNode : public ExpressionNode { public: - BinaryExpressionMinusNode(Node *left, Node* right) + BinaryExpressionMinusNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -31,7 +31,6 @@ class BinaryExpressionMinusNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::BinaryExpressionMinus; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_left->generateExpressionByteCode(codeBlock, context); @@ -43,11 +42,11 @@ class BinaryExpressionMinusNode : public ExpressionNode { codeBlock->pushCode(BinaryMinus(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionModNode.h b/src/parser/ast/BinaryExpressionModNode.h index 7ddcd080d..646e95d8d 100644 --- a/src/parser/ast/BinaryExpressionModNode.h +++ b/src/parser/ast/BinaryExpressionModNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionModNode : public ExpressionNode { public: - BinaryExpressionModNode(Node *left, Node* right) + BinaryExpressionModNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -42,11 +42,11 @@ class BinaryExpressionModNode : public ExpressionNode { codeBlock->pushCode(BinaryMod(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionMultiplyNode.h b/src/parser/ast/BinaryExpressionMultiplyNode.h index c7e342b3c..c791f9366 100644 --- a/src/parser/ast/BinaryExpressionMultiplyNode.h +++ b/src/parser/ast/BinaryExpressionMultiplyNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionMultiplyNode : public ExpressionNode { public: - BinaryExpressionMultiplyNode(Node *left, Node* right) + BinaryExpressionMultiplyNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -31,7 +31,6 @@ class BinaryExpressionMultiplyNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::BinaryExpressionMultiply; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_left->generateExpressionByteCode(codeBlock, context); @@ -43,11 +42,11 @@ class BinaryExpressionMultiplyNode : public ExpressionNode { codeBlock->pushCode(BinaryMultiply(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionNotEqualNode.h b/src/parser/ast/BinaryExpressionNotEqualNode.h index c15c3fa06..fa1c1bfb4 100644 --- a/src/parser/ast/BinaryExpressionNotEqualNode.h +++ b/src/parser/ast/BinaryExpressionNotEqualNode.h @@ -25,7 +25,7 @@ class BinaryExpressionNotEqualNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionNotEqualNode(Node *left, Node* right) + BinaryExpressionNotEqualNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionNotEqualNode : public ExpressionNode { codeBlock->pushCode(BinaryNotEqual(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionNotStrictEqualNode.h b/src/parser/ast/BinaryExpressionNotStrictEqualNode.h index 7695fbf9e..39b370c7e 100644 --- a/src/parser/ast/BinaryExpressionNotStrictEqualNode.h +++ b/src/parser/ast/BinaryExpressionNotStrictEqualNode.h @@ -25,7 +25,7 @@ class BinaryExpressionNotStrictEqualNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionNotStrictEqualNode(Node *left, Node* right) + BinaryExpressionNotStrictEqualNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionNotStrictEqualNode : public ExpressionNode { codeBlock->pushCode(BinaryNotStrictEqual(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionPlusNode.h b/src/parser/ast/BinaryExpressionPlusNode.h index d00f94497..c7197f40f 100644 --- a/src/parser/ast/BinaryExpressionPlusNode.h +++ b/src/parser/ast/BinaryExpressionPlusNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionPlusNode : public ExpressionNode { public: - BinaryExpressionPlusNode(Node *left, Node* right) + BinaryExpressionPlusNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -31,7 +31,6 @@ class BinaryExpressionPlusNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::BinaryExpressionPlus; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_left->generateExpressionByteCode(codeBlock, context); @@ -43,11 +42,11 @@ class BinaryExpressionPlusNode : public ExpressionNode { codeBlock->pushCode(BinaryPlus(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionSignedRightShiftNode.h b/src/parser/ast/BinaryExpressionSignedRightShiftNode.h index e38aff02e..4523fed2a 100644 --- a/src/parser/ast/BinaryExpressionSignedRightShiftNode.h +++ b/src/parser/ast/BinaryExpressionSignedRightShiftNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionSignedRightShiftNode : public ExpressionNode { public: - BinaryExpressionSignedRightShiftNode(Node *left, Node* right) + BinaryExpressionSignedRightShiftNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -42,11 +42,11 @@ class BinaryExpressionSignedRightShiftNode : public ExpressionNode { codeBlock->pushCode(BinarySignedRightShift(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionStrictEqualNode.h b/src/parser/ast/BinaryExpressionStrictEqualNode.h index 9abdd7532..3eb17325c 100644 --- a/src/parser/ast/BinaryExpressionStrictEqualNode.h +++ b/src/parser/ast/BinaryExpressionStrictEqualNode.h @@ -25,7 +25,7 @@ class BinaryExpressionStrictEqualNode : public ExpressionNode { public: friend class ScriptParser; - BinaryExpressionStrictEqualNode(Node *left, Node* right) + BinaryExpressionStrictEqualNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -44,11 +44,11 @@ class BinaryExpressionStrictEqualNode : public ExpressionNode { codeBlock->pushCode(BinaryStrictEqual(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BinaryExpressionUnsignedRightShiftNode.h b/src/parser/ast/BinaryExpressionUnsignedRightShiftNode.h index b27cfa40e..b18835088 100644 --- a/src/parser/ast/BinaryExpressionUnsignedRightShiftNode.h +++ b/src/parser/ast/BinaryExpressionUnsignedRightShiftNode.h @@ -23,7 +23,7 @@ namespace Escargot { class BinaryExpressionUnsignedRightShiftNode : public ExpressionNode { public: - BinaryExpressionUnsignedRightShiftNode(Node *left, Node* right) + BinaryExpressionUnsignedRightShiftNode(Node* left, Node* right) : ExpressionNode() { m_left = (ExpressionNode*)left; @@ -42,11 +42,11 @@ class BinaryExpressionUnsignedRightShiftNode : public ExpressionNode { codeBlock->pushCode(BinaryUnsignedRightShift(ByteCodeLOC(m_loc.index), src0, src1), context, this); } + protected: ExpressionNode* m_left; ExpressionNode* m_right; }; - } #endif diff --git a/src/parser/ast/BlockStatementNode.h b/src/parser/ast/BlockStatementNode.h index 4e302855c..1fc80dd70 100644 --- a/src/parser/ast/BlockStatementNode.h +++ b/src/parser/ast/BlockStatementNode.h @@ -33,11 +33,10 @@ class BlockStatementNode : public StatementNode { virtual ASTNodeType type() { return ASTNodeType::BlockStatement; } size_t size() { return m_body.size(); } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { size_t len = m_body.size(); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { m_body[i]->generateStatementByteCode(codeBlock, context); } } @@ -45,8 +44,6 @@ class BlockStatementNode : public StatementNode { protected: StatementNodeVector m_body; // body: [ Statement ]; }; - - } #endif diff --git a/src/parser/ast/BreakLabelStatementNode.h b/src/parser/ast/BreakLabelStatementNode.h index 2e61d9b90..0d6b9ac94 100644 --- a/src/parser/ast/BreakLabelStatementNode.h +++ b/src/parser/ast/BreakLabelStatementNode.h @@ -31,11 +31,9 @@ class BreakLabelStatementNode : public StatementNode { } virtual ASTNodeType type() { return ASTNodeType::BreakLabelStatement; } - protected: String* m_label; }; - } #endif diff --git a/src/parser/ast/BreakStatementNode.h b/src/parser/ast/BreakStatementNode.h index 38f4910c1..e16bbfbb1 100644 --- a/src/parser/ast/BreakStatementNode.h +++ b/src/parser/ast/BreakStatementNode.h @@ -30,9 +30,7 @@ class BreakStatementNode : public StatementNode { } virtual ASTNodeType type() { return ASTNodeType::BreakStatement; } - }; - } #endif diff --git a/src/parser/ast/CallExpressionNode.h b/src/parser/ast/CallExpressionNode.h index 746d9752e..be2cf0b82 100644 --- a/src/parser/ast/CallExpressionNode.h +++ b/src/parser/ast/CallExpressionNode.h @@ -18,8 +18,8 @@ #define CallExpressionNode_h #include "ExpressionNode.h" -#include "PatternNode.h" #include "MemberExpressionNode.h" +#include "PatternNode.h" namespace Escargot { @@ -35,7 +35,6 @@ class CallExpressionNode : public ExpressionNode { Node* callee() { return m_callee; } virtual ASTNodeType type() { return ASTNodeType::CallExpression; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { if (m_callee->isIdentifier() && m_callee->asIdentifier()->name().string()->equals("eval")) { @@ -56,10 +55,10 @@ class CallExpressionNode : public ExpressionNode { size_t baseRegister = context->getLastRegisterIndex() - 1; context->m_inCallingExpressionScope = false; - for (size_t i = 0; i < m_arguments.size(); i ++) { + for (size_t i = 0; i < m_arguments.size(); i++) { m_arguments[i]->generateExpressionByteCode(codeBlock, context); } - for (size_t i = 0; i < m_arguments.size(); i ++) { + for (size_t i = 0; i < m_arguments.size(); i++) { context->giveUpRegister(); } @@ -74,7 +73,6 @@ class CallExpressionNode : public ExpressionNode { Node* m_callee; // callee: Expression; ArgumentVector m_arguments; // arguments: [ Expression ]; }; - } #endif diff --git a/src/parser/ast/CatchClauseNode.h b/src/parser/ast/CatchClauseNode.h index a5e0f74e3..ddb7e6a50 100644 --- a/src/parser/ast/CatchClauseNode.h +++ b/src/parser/ast/CatchClauseNode.h @@ -17,10 +17,10 @@ #ifndef CatchClauseNode_h #define CatchClauseNode_h -#include "Node.h" +#include "BlockStatementNode.h" #include "ExpressionNode.h" #include "IdentifierNode.h" -#include "BlockStatementNode.h" +#include "Node.h" namespace Escargot { @@ -31,21 +31,19 @@ class CatchClauseNode : public Node { CatchClauseNode(Node *param, Node *guard, Node *body) : Node() { - m_param = (IdentifierNode*) param; - m_guard = (ExpressionNode*) guard; - m_body = (BlockStatementNode*) body; + m_param = (IdentifierNode *)param; + m_guard = (ExpressionNode *)guard; + m_body = (BlockStatementNode *)body; } virtual ASTNodeType type() { return ASTNodeType::CatchClause; } - protected: - IdentifierNode* m_param; - ExpressionNode* m_guard; - BlockStatementNode* m_body; + IdentifierNode *m_param; + ExpressionNode *m_guard; + BlockStatementNode *m_body; }; typedef Vector> CatchClauseNodeVector; - } #endif diff --git a/src/parser/ast/ConditionalExpressionNode.h b/src/parser/ast/ConditionalExpressionNode.h index df5b69acd..b8abb31eb 100644 --- a/src/parser/ast/ConditionalExpressionNode.h +++ b/src/parser/ast/ConditionalExpressionNode.h @@ -24,22 +24,20 @@ namespace Escargot { class ConditionalExpressionNode : public ExpressionNode { public: friend class ScriptParser; - ConditionalExpressionNode(Node *test, Node *consequente, Node *alternate) + ConditionalExpressionNode(Node* test, Node* consequente, Node* alternate) : ExpressionNode() { - m_test = (ExpressionNode*) test; - m_consequente = (ExpressionNode*) consequente; - m_alternate = (ExpressionNode*) alternate; + m_test = (ExpressionNode*)test; + m_consequente = (ExpressionNode*)consequente; + m_alternate = (ExpressionNode*)alternate; } virtual ASTNodeType type() { return ASTNodeType::ConditionalExpression; } - protected: ExpressionNode* m_test; ExpressionNode* m_consequente; ExpressionNode* m_alternate; }; - } #endif diff --git a/src/parser/ast/ContinueLabelStatementNode.h b/src/parser/ast/ContinueLabelStatementNode.h index 672c25764..0253cbb49 100644 --- a/src/parser/ast/ContinueLabelStatementNode.h +++ b/src/parser/ast/ContinueLabelStatementNode.h @@ -31,11 +31,9 @@ class ContinueLabelStatementNode : public StatementNode { } virtual ASTNodeType type() { return ASTNodeType::ContinueLabelStatement; } - protected: String* m_label; }; - } #endif diff --git a/src/parser/ast/ContinueStatementNode.h b/src/parser/ast/ContinueStatementNode.h index 8e16aced5..9dd908764 100644 --- a/src/parser/ast/ContinueStatementNode.h +++ b/src/parser/ast/ContinueStatementNode.h @@ -30,9 +30,7 @@ class ContinueStatementNode : public StatementNode { } virtual ASTNodeType type() { return ASTNodeType::ContinueStatement; } - }; - } #endif diff --git a/src/parser/ast/DeclarationNode.h b/src/parser/ast/DeclarationNode.h index 199887aec..b06ba31d7 100644 --- a/src/parser/ast/DeclarationNode.h +++ b/src/parser/ast/DeclarationNode.h @@ -28,9 +28,9 @@ class DeclarationNode : public StatementNode { : StatementNode() { } + protected: }; - } diff --git a/src/parser/ast/DirectiveNode.h b/src/parser/ast/DirectiveNode.h index 85e449ce8..89173171c 100644 --- a/src/parser/ast/DirectiveNode.h +++ b/src/parser/ast/DirectiveNode.h @@ -17,8 +17,8 @@ #ifndef DirectiveNode_h #define DirectiveNode_h -#include "Node.h" #include "ExpressionNode.h" +#include "Node.h" namespace Escargot { @@ -37,7 +37,6 @@ class DirectiveNode : public Node { ExpressionNode* m_expr; StringView m_value; }; - } #endif diff --git a/src/parser/ast/DoWhileStatementNode.h b/src/parser/ast/DoWhileStatementNode.h index b33f5880e..cbff9bfb8 100644 --- a/src/parser/ast/DoWhileStatementNode.h +++ b/src/parser/ast/DoWhileStatementNode.h @@ -17,8 +17,8 @@ #ifndef DoWhileStatementNode_h #define DoWhileStatementNode_h -#include "StatementNode.h" #include "ExpressionNode.h" +#include "StatementNode.h" namespace Escargot { @@ -28,17 +28,15 @@ class DoWhileStatementNode : public StatementNode { DoWhileStatementNode(Node *test, Node *body) : StatementNode() { - m_test = (ExpressionNode*) test; - m_body = (StatementNode*) body; + m_test = (ExpressionNode *)test; + m_body = (StatementNode *)body; } virtual ASTNodeType type() { return ASTNodeType::DoWhileStatement; } - protected: ExpressionNode *m_test; StatementNode *m_body; }; - } #endif diff --git a/src/parser/ast/EmptyNode.h b/src/parser/ast/EmptyNode.h index 8ad3bc484..69edbaa74 100644 --- a/src/parser/ast/EmptyNode.h +++ b/src/parser/ast/EmptyNode.h @@ -29,10 +29,8 @@ class EmptyNode : public Node { } virtual ASTNodeType type() { return ASTNodeType::Empty; } - protected: }; - } #endif diff --git a/src/parser/ast/EmptyStatementNode.h b/src/parser/ast/EmptyStatementNode.h index da01360de..f977138d9 100644 --- a/src/parser/ast/EmptyStatementNode.h +++ b/src/parser/ast/EmptyStatementNode.h @@ -30,10 +30,8 @@ class EmptyStatementNode : public StatementNode { } virtual ASTNodeType type() { return ASTNodeType::EmptyStatement; } - protected: }; - } #endif diff --git a/src/parser/ast/ExpressionNode.h b/src/parser/ast/ExpressionNode.h index df249eb88..ab257f17d 100644 --- a/src/parser/ast/ExpressionNode.h +++ b/src/parser/ast/ExpressionNode.h @@ -35,9 +35,9 @@ class ExpressionNode : public Node { { return true; } + protected: }; - } #endif diff --git a/src/parser/ast/ExpressionStatementNode.h b/src/parser/ast/ExpressionStatementNode.h index f87a5ffd6..2f001862d 100644 --- a/src/parser/ast/ExpressionStatementNode.h +++ b/src/parser/ast/ExpressionStatementNode.h @@ -32,9 +32,7 @@ class ExpressionStatementNode : public StatementNode { } virtual ASTNodeType type() { return ASTNodeType::ExpressionStatement; } - Node* expression() { return m_expression; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { #ifndef NDEBUG @@ -45,10 +43,10 @@ class ExpressionStatementNode : public StatementNode { context->giveUpRegister(); ASSERT(context->m_baseRegisterCount == before); } + protected: Node* m_expression; // expression: Expression; }; - } #endif diff --git a/src/parser/ast/ForInStatementNode.h b/src/parser/ast/ForInStatementNode.h index a59f8a3d1..19476ddd0 100644 --- a/src/parser/ast/ForInStatementNode.h +++ b/src/parser/ast/ForInStatementNode.h @@ -17,8 +17,8 @@ #ifndef ForInStatementNode_h #define ForInStatementNode_h -#include "StatementNode.h" #include "ExpressionNode.h" +#include "StatementNode.h" namespace Escargot { @@ -28,21 +28,19 @@ class ForInStatementNode : public StatementNode { ForInStatementNode(Node *left, Node *right, Node *body, bool each) : StatementNode() { - m_left = (ExpressionNode*) left; - m_right = (ExpressionNode*) right; - m_body = (StatementNode*) body; + m_left = (ExpressionNode *)left; + m_right = (ExpressionNode *)right; + m_body = (StatementNode *)body; m_each = each; } virtual ASTNodeType type() { return ASTNodeType::ForInStatement; } - protected: ExpressionNode *m_left; ExpressionNode *m_right; StatementNode *m_body; bool m_each; }; - } #endif diff --git a/src/parser/ast/ForStatementNode.h b/src/parser/ast/ForStatementNode.h index 9abebf137..352494a7a 100644 --- a/src/parser/ast/ForStatementNode.h +++ b/src/parser/ast/ForStatementNode.h @@ -17,8 +17,8 @@ #ifndef ForStatementNode_h #define ForStatementNode_h -#include "StatementNode.h" #include "ExpressionNode.h" +#include "StatementNode.h" namespace Escargot { @@ -28,14 +28,14 @@ class ForStatementNode : public StatementNode { ForStatementNode(Node *init, Node *test, Node *update, Node *body) : StatementNode() { - m_init = (ExpressionNode*) init; - m_test = (ExpressionNode*) test; - m_update = (ExpressionNode*) update; - m_body = (StatementNode*) body; + m_init = (ExpressionNode *)init; + m_test = (ExpressionNode *)test; + m_update = (ExpressionNode *)update; + m_body = (StatementNode *)body; } virtual ASTNodeType type() { return ASTNodeType::ForStatement; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) + virtual void generateStatementByteCode(ByteCodeBlock *codeBlock, ByteCodeGenerateContext *context) { ByteCodeGenerateContext newContext(*context); @@ -71,13 +71,13 @@ class ForStatementNode : public StatementNode { newContext.m_positionToContinue = updatePosition; newContext.propagateInformationTo(*context); } + protected: ExpressionNode *m_init; ExpressionNode *m_test; ExpressionNode *m_update; StatementNode *m_body; }; - } #endif diff --git a/src/parser/ast/FunctionDeclarationNode.h b/src/parser/ast/FunctionDeclarationNode.h index c3362a266..a7544f897 100644 --- a/src/parser/ast/FunctionDeclarationNode.h +++ b/src/parser/ast/FunctionDeclarationNode.h @@ -30,7 +30,6 @@ class FunctionDeclarationNode : public StatementNode { } virtual ASTNodeType type() { return ASTNodeType::FunctionDeclaration; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { // do nothing @@ -39,7 +38,6 @@ class FunctionDeclarationNode : public StatementNode { protected: FunctionNode m_function; }; - } #endif diff --git a/src/parser/ast/FunctionExpressionNode.h b/src/parser/ast/FunctionExpressionNode.h index 706b8c0f5..41119aaaf 100644 --- a/src/parser/ast/FunctionExpressionNode.h +++ b/src/parser/ast/FunctionExpressionNode.h @@ -33,7 +33,7 @@ class FunctionExpressionNode : public ExpressionNode { virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { CodeBlock* blk = nullptr; - for (size_t i = 0; i < context->m_codeBlock->childBlocks().size(); i ++) { + for (size_t i = 0; i < context->m_codeBlock->childBlocks().size(); i++) { CodeBlock* c = context->m_codeBlock->childBlocks()[i]; if (c->isFunctionExpression() && c->astNodeStartIndex() == m_loc.index) { blk = c; @@ -43,12 +43,12 @@ class FunctionExpressionNode : public ExpressionNode { ASSERT(blk); codeBlock->pushCode(DeclareFunctionExpression(ByteCodeLOC(m_loc.index), context->getRegister(), blk), context, this); } + protected: FunctionNode m_function; // defaults: [ Expression ]; // rest: Identifier | null; }; - } #endif diff --git a/src/parser/ast/FunctionNode.h b/src/parser/ast/FunctionNode.h index e01bd1384..2ff898a0b 100644 --- a/src/parser/ast/FunctionNode.h +++ b/src/parser/ast/FunctionNode.h @@ -17,8 +17,8 @@ #ifndef FunctionNode_h #define FunctionNode_h -#include "StatementNode.h" #include "ExpressionNode.h" +#include "StatementNode.h" namespace Escargot { @@ -38,7 +38,6 @@ class FunctionNode { inline Node* body() { return m_body; } inline const AtomicString& id() { return m_id; } ASTScopeContext* scopeContext() { return m_scopeContext; } - protected: bool m_isGenerator; AtomicString m_id; // id: Identifier; @@ -46,7 +45,6 @@ class FunctionNode { Node* m_body; ASTScopeContext* m_scopeContext; }; - } #endif diff --git a/src/parser/ast/IdentifierNode.h b/src/parser/ast/IdentifierNode.h index 8f97aca8b..1a6843d73 100644 --- a/src/parser/ast/IdentifierNode.h +++ b/src/parser/ast/IdentifierNode.h @@ -17,8 +17,8 @@ #ifndef IdentifierNode_h #define IdentifierNode_h -#include "Node.h" #include "ExpressionNode.h" +#include "Node.h" #include "PatternNode.h" namespace Escargot { @@ -34,7 +34,6 @@ class IdentifierNode : public Node { } virtual ASTNodeType type() { return ASTNodeType::Identifier; } - AtomicString name() { return m_name; @@ -83,10 +82,10 @@ class IdentifierNode : public Node { } } } + protected: AtomicString m_name; }; - } #endif diff --git a/src/parser/ast/IfStatementNode.h b/src/parser/ast/IfStatementNode.h index e74f3f475..97424696d 100644 --- a/src/parser/ast/IfStatementNode.h +++ b/src/parser/ast/IfStatementNode.h @@ -24,16 +24,15 @@ namespace Escargot { class IfStatementNode : public StatementNode { public: friend class ScriptParser; - IfStatementNode(Node *test, Node *consequente, Node *alternate) + IfStatementNode(Node* test, Node* consequente, Node* alternate) : StatementNode() { - m_test = (ExpressionNode*) test; - m_consequente = (StatementNode*) consequente; - m_alternate = (StatementNode*) alternate; + m_test = (ExpressionNode*)test; + m_consequente = (StatementNode*)consequente; + m_alternate = (StatementNode*)alternate; } virtual ASTNodeType type() { return ASTNodeType::IfStatement; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { if (!m_alternate) { @@ -69,11 +68,10 @@ class IfStatementNode : public StatementNode { } protected: - ExpressionNode *m_test; - StatementNode *m_consequente; - StatementNode *m_alternate; + ExpressionNode* m_test; + StatementNode* m_consequente; + StatementNode* m_alternate; }; - } #endif diff --git a/src/parser/ast/LabeledStatementNode.h b/src/parser/ast/LabeledStatementNode.h index 929d396fa..0cd0f7bc1 100644 --- a/src/parser/ast/LabeledStatementNode.h +++ b/src/parser/ast/LabeledStatementNode.h @@ -32,12 +32,10 @@ class LabeledStatementNode : public StatementNode { } virtual ASTNodeType type() { return ASTNodeType::LabeledStatement; } - protected: StatementNode* m_statementNode; String* m_label; }; - } #endif diff --git a/src/parser/ast/LiteralNode.h b/src/parser/ast/LiteralNode.h index 1d627a07c..f12fee202 100644 --- a/src/parser/ast/LiteralNode.h +++ b/src/parser/ast/LiteralNode.h @@ -31,17 +31,15 @@ class LiteralNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::Literal; } - const Value& value() { return m_value; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { codeBlock->pushCode(LoadLiteral(ByteCodeLOC(m_loc.index), context->getRegister(), m_value), context, this); } + protected: Value m_value; }; - } #endif diff --git a/src/parser/ast/MemberExpressionNode.h b/src/parser/ast/MemberExpressionNode.h index dca3edea7..332958d14 100644 --- a/src/parser/ast/MemberExpressionNode.h +++ b/src/parser/ast/MemberExpressionNode.h @@ -34,7 +34,6 @@ class MemberExpressionNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::MemberExpression; } - bool isPreComputedCase() { return m_computed; @@ -43,7 +42,7 @@ class MemberExpressionNode : public ExpressionNode { AtomicString propertyName() { ASSERT(isPreComputedCase()); - return ((IdentifierNode *)m_property)->name(); + return ((IdentifierNode*)m_property)->name(); } virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) @@ -100,7 +99,6 @@ class MemberExpressionNode : public ExpressionNode { bool m_computed; }; - } #endif diff --git a/src/parser/ast/NewExpressionNode.h b/src/parser/ast/NewExpressionNode.h index 896e9e8b5..df67569b5 100644 --- a/src/parser/ast/NewExpressionNode.h +++ b/src/parser/ast/NewExpressionNode.h @@ -37,21 +37,21 @@ class NewExpressionNode : public ExpressionNode { m_callee->generateExpressionByteCode(codeBlock, context); size_t base = context->getLastRegisterIndex(); - for (size_t i = 0; i < m_arguments.size(); i ++) { + for (size_t i = 0; i < m_arguments.size(); i++) { m_arguments[i]->generateExpressionByteCode(codeBlock, context); } codeBlock->pushCode(NewOperation(ByteCodeLOC(m_loc.index), base, m_arguments.size()), context, this); - for (size_t i = 0; i < m_arguments.size(); i ++) { + for (size_t i = 0; i < m_arguments.size(); i++) { context->giveUpRegister(); } } + protected: Node* m_callee; ArgumentVector m_arguments; }; - } #endif diff --git a/src/parser/ast/Node.h b/src/parser/ast/Node.h index 71c942ebd..385b5aaa4 100644 --- a/src/parser/ast/Node.h +++ b/src/parser/ast/Node.h @@ -17,8 +17,8 @@ #ifndef Node_h #define Node_h -#include "runtime/Value.h" #include "runtime/AtomicString.h" +#include "runtime/Value.h" namespace Escargot { @@ -144,15 +144,16 @@ class IdentifierNode; class Node : public gc { friend class ScriptParser; + protected: Node() : m_loc(SIZE_MAX, SIZE_MAX, SIZE_MAX) { } + public: virtual ~Node() { - } virtual ASTNodeType type() = 0; @@ -162,10 +163,10 @@ class Node : public gc { return type() == ASTNodeType::Identifier; } - IdentifierNode* asIdentifier() + IdentifierNode *asIdentifier() { ASSERT(isIdentifier()); - return (IdentifierNode*)this; + return (IdentifierNode *)this; } bool isLiteral() @@ -193,17 +194,17 @@ class Node : public gc { return m_loc; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) + virtual void generateStatementByteCode(ByteCodeBlock *codeBlock, ByteCodeGenerateContext *context) { RELEASE_ASSERT_NOT_REACHED(); } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) + virtual void generateExpressionByteCode(ByteCodeBlock *codeBlock, ByteCodeGenerateContext *context) { RELEASE_ASSERT_NOT_REACHED(); } - virtual void generateStoreByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) + virtual void generateStoreByteCode(ByteCodeBlock *codeBlock, ByteCodeGenerateContext *context) { RELEASE_ASSERT_NOT_REACHED(); // TODO @@ -215,7 +216,6 @@ class Node : public gc { class Pattern { public: - }; struct ASTScopeContext : public gc { @@ -223,13 +223,13 @@ struct ASTScopeContext : public gc { bool m_hasEval; bool m_hasWith; bool m_hasYield; - ASTScopeContext* m_parentContext; - Node* m_associateNode; + ASTScopeContext *m_parentContext; + Node *m_associateNode; AtomicStringVector m_names; AtomicStringVector m_usingNames; AtomicStringVector m_parameters; AtomicString m_functionName; - Vector> m_childScopes; + Vector> m_childScopes; NodeLOC m_locStart; NodeLOC m_locEnd; size_t m_nodeStartIndex; @@ -248,7 +248,7 @@ struct ASTScopeContext : public gc { } } - ASTScopeContext(bool isStrict, ASTScopeContext* parentContext) + ASTScopeContext(bool isStrict, ASTScopeContext *parentContext) : m_locStart(SIZE_MAX, SIZE_MAX, SIZE_MAX) , m_locEnd(SIZE_MAX, SIZE_MAX, SIZE_MAX) , m_nodeStartIndex(SIZE_MAX) diff --git a/src/parser/ast/ObjectExpressionNode.h b/src/parser/ast/ObjectExpressionNode.h index 5d34acac6..da82c07b6 100644 --- a/src/parser/ast/ObjectExpressionNode.h +++ b/src/parser/ast/ObjectExpressionNode.h @@ -33,12 +33,11 @@ class ObjectExpressionNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::ObjectExpression; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { codeBlock->pushCode(CreateObject(ByteCodeLOC(m_loc.index), context->getRegister()), context, this); size_t objIndex = context->getLastRegisterIndex(); - for (unsigned i = 0; i < m_properties.size() ; i ++) { + for (unsigned i = 0; i < m_properties.size(); i++) { PropertyNode* p = m_properties[i]; AtomicString propertyAtomicName; if (p->key()->isIdentifier()) { @@ -73,10 +72,10 @@ class ObjectExpressionNode : public ExpressionNode { } ASSERT(objIndex == context->getLastRegisterIndex()); } + protected: PropertiesNodeVector m_properties; }; - } #endif diff --git a/src/parser/ast/PatternNode.h b/src/parser/ast/PatternNode.h index b7338cfeb..b36b8c89f 100644 --- a/src/parser/ast/PatternNode.h +++ b/src/parser/ast/PatternNode.h @@ -27,9 +27,9 @@ class PatternNode : public Node { : Node() { } + protected: }; - } #endif diff --git a/src/parser/ast/ProgramNode.h b/src/parser/ast/ProgramNode.h index ea55485b8..bcc559583 100644 --- a/src/parser/ast/ProgramNode.h +++ b/src/parser/ast/ProgramNode.h @@ -35,20 +35,19 @@ class ProgramNode : public Node { virtual ASTNodeType type() { return ASTNodeType::Program; } ASTScopeContext* scopeContext() { return m_scopeContext; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { size_t len = m_body.size(); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { m_body[i]->generateStatementByteCode(codeBlock, context); } } + protected: StatementNodeVector m_body; // body: [ Statement ]; ASTScopeContext* m_scopeContext; }; - } #endif diff --git a/src/parser/ast/PropertyNode.h b/src/parser/ast/PropertyNode.h index ce30e6065..019aec186 100644 --- a/src/parser/ast/PropertyNode.h +++ b/src/parser/ast/PropertyNode.h @@ -26,7 +26,9 @@ class PropertyNode : public Node { public: friend class ScriptParser; enum Kind { - Init, Get, Set + Init, + Get, + Set }; PropertyNode(Node* key, Node* value, Kind kind) @@ -38,7 +40,6 @@ class PropertyNode : public Node { } virtual ASTNodeType type() { return ASTNodeType::Property; } - Node* key() { return m_key; @@ -64,7 +65,6 @@ class PropertyNode : public Node { Node* m_key; // key: Literal | Identifier; Node* m_value; // value: Expression; }; - } #endif diff --git a/src/parser/ast/RegExpLiteralNode.h b/src/parser/ast/RegExpLiteralNode.h index 8fb31f7fc..81b8e6651 100644 --- a/src/parser/ast/RegExpLiteralNode.h +++ b/src/parser/ast/RegExpLiteralNode.h @@ -41,7 +41,6 @@ class RegExpLiteralNode : public Node { Escargot::ESRegExpObject::Option m_flag; }; */ - } #endif diff --git a/src/parser/ast/RestElementNode.h b/src/parser/ast/RestElementNode.h index 5dab8c419..2b06b300b 100644 --- a/src/parser/ast/RestElementNode.h +++ b/src/parser/ast/RestElementNode.h @@ -17,8 +17,8 @@ #ifndef RestElementNode_h #define RestElementNode_h -#include "Node.h" #include "IdentifierNode.h" +#include "Node.h" namespace Escargot { @@ -31,7 +31,6 @@ class RestElementNode : public Node { } virtual ASTNodeType type() { return ASTNodeType::RestElement; } - IdentifierNode* argument() { return m_argument; @@ -40,7 +39,6 @@ class RestElementNode : public Node { protected: IdentifierNode* m_argument; }; - } #endif diff --git a/src/parser/ast/ReturnStatmentNode.h b/src/parser/ast/ReturnStatmentNode.h index 26b64bce8..1767a9c3b 100644 --- a/src/parser/ast/ReturnStatmentNode.h +++ b/src/parser/ast/ReturnStatmentNode.h @@ -31,7 +31,6 @@ class ReturnStatmentNode : public StatementNode { } virtual ASTNodeType type() { return ASTNodeType::ReturnStatement; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { if (m_argument) { @@ -42,10 +41,10 @@ class ReturnStatmentNode : public StatementNode { codeBlock->pushCode(ReturnFunction(ByteCodeLOC(m_loc.index), SIZE_MAX), context, this); } } + protected: Node* m_argument; }; - } #endif diff --git a/src/parser/ast/SequenceExpressionNode.h b/src/parser/ast/SequenceExpressionNode.h index 21af78cbe..aa5b54805 100644 --- a/src/parser/ast/SequenceExpressionNode.h +++ b/src/parser/ast/SequenceExpressionNode.h @@ -32,13 +32,10 @@ class SequenceExpressionNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::SequenceExpression; } - const ExpressionNodeVector& expressions() { return m_expressions; } - protected: ExpressionNodeVector m_expressions; // expression: Expression; }; - } #endif diff --git a/src/parser/ast/SpreadElementNode.h b/src/parser/ast/SpreadElementNode.h index c97480c12..404f26444 100644 --- a/src/parser/ast/SpreadElementNode.h +++ b/src/parser/ast/SpreadElementNode.h @@ -33,10 +33,10 @@ class SpreadElementNode : public Node { { return SpreadElement; } + protected: Node* m_arg; }; - } #endif diff --git a/src/parser/ast/StatementNode.h b/src/parser/ast/StatementNode.h index 4309312d2..5f8947d35 100644 --- a/src/parser/ast/StatementNode.h +++ b/src/parser/ast/StatementNode.h @@ -35,7 +35,6 @@ class StatementNode : public Node { protected: }; - } #endif diff --git a/src/parser/ast/SwitchCaseNode.h b/src/parser/ast/SwitchCaseNode.h index 35fe39e11..e5ad5a0cd 100644 --- a/src/parser/ast/SwitchCaseNode.h +++ b/src/parser/ast/SwitchCaseNode.h @@ -17,8 +17,8 @@ #ifndef SwitchCaseNode_h #define SwitchCaseNode_h -#include "StatementNode.h" #include "ExpressionNode.h" +#include "StatementNode.h" namespace Escargot { @@ -29,12 +29,11 @@ class SwitchCaseNode : public StatementNode { SwitchCaseNode(Node* test, StatementNodeVector&& consequent) : StatementNode() { - m_test = (ExpressionNode*) test; + m_test = (ExpressionNode*)test; m_consequent = consequent; } virtual ASTNodeType type() { return ASTNodeType::SwitchCase; } - bool isDefaultNode() { return !m_test; @@ -44,7 +43,6 @@ class SwitchCaseNode : public StatementNode { ExpressionNode* m_test; StatementNodeVector m_consequent; }; - } #endif diff --git a/src/parser/ast/SwitchStatementNode.h b/src/parser/ast/SwitchStatementNode.h index 82394ecb0..05d28b909 100644 --- a/src/parser/ast/SwitchStatementNode.h +++ b/src/parser/ast/SwitchStatementNode.h @@ -17,8 +17,8 @@ #ifndef SwitchStatementNode_h #define SwitchStatementNode_h -#include "StatementNode.h" #include "ExpressionNode.h" +#include "StatementNode.h" #include "SwitchCaseNode.h" namespace Escargot { @@ -29,15 +29,14 @@ class SwitchStatementNode : public StatementNode { SwitchStatementNode(Node* discriminant, StatementNodeVector&& casesA, Node* deflt, StatementNodeVector&& casesB, bool lexical) : StatementNode() { - m_discriminant = (ExpressionNode*) discriminant; + m_discriminant = (ExpressionNode*)discriminant; m_casesA = casesA; - m_default = (StatementNode*) deflt; + m_default = (StatementNode*)deflt; m_casesB = casesB; m_lexical = lexical; } virtual ASTNodeType type() { return ASTNodeType::SwitchStatement; } - protected: ExpressionNode* m_discriminant; StatementNodeVector m_casesA; @@ -45,7 +44,6 @@ class SwitchStatementNode : public StatementNode { StatementNodeVector m_casesB; bool m_lexical; }; - } #endif diff --git a/src/parser/ast/ThisExpressionNode.h b/src/parser/ast/ThisExpressionNode.h index 62765b977..6ce855ccf 100644 --- a/src/parser/ast/ThisExpressionNode.h +++ b/src/parser/ast/ThisExpressionNode.h @@ -24,16 +24,18 @@ namespace Escargot { class ThisExpressionNode : public ExpressionNode { public: ThisExpressionNode() - : ExpressionNode() { } + : ExpressionNode() + { + } virtual ASTNodeType type() { return ASTNodeType::ThisExpression; } virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { codeBlock->pushCode(GetThis(ByteCodeLOC(m_loc.index), context->getRegister()), context, this); } + protected: }; - } #endif diff --git a/src/parser/ast/ThrowStatementNode.h b/src/parser/ast/ThrowStatementNode.h index a89525bc9..8386862af 100644 --- a/src/parser/ast/ThrowStatementNode.h +++ b/src/parser/ast/ThrowStatementNode.h @@ -25,24 +25,23 @@ namespace Escargot { class ThrowStatementNode : public StatementNode { public: friend class ScriptParser; - ThrowStatementNode(Node *argument) + ThrowStatementNode(Node* argument) : StatementNode() { m_argument = argument; } virtual ASTNodeType type() { return ASTNodeType::ThrowStatement; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_argument->generateExpressionByteCode(codeBlock, context); codeBlock->pushCode(ThrowOperation(ByteCodeLOC(m_loc.index), context->getLastRegisterIndex()), context, this); context->giveUpRegister(); } + protected: Node* m_argument; }; - } #endif diff --git a/src/parser/ast/TryStatementNode.h b/src/parser/ast/TryStatementNode.h index a145e0669..7f8ed789b 100644 --- a/src/parser/ast/TryStatementNode.h +++ b/src/parser/ast/TryStatementNode.h @@ -17,33 +17,31 @@ #ifndef TryStatementNode_h #define TryStatementNode_h +#include "CatchClauseNode.h" #include "StatementNode.h" #include "runtime/ExecutionContext.h" -#include "CatchClauseNode.h" namespace Escargot { class TryStatementNode : public StatementNode { public: friend class ScriptParser; - TryStatementNode(Node *block, Node *handler, CatchClauseNodeVector&& guardedHandlers, Node *finalizer) + TryStatementNode(Node *block, Node *handler, CatchClauseNodeVector &&guardedHandlers, Node *finalizer) : StatementNode() { - m_block = (BlockStatementNode*) block; - m_handler = (CatchClauseNode*) handler; + m_block = (BlockStatementNode *)block; + m_handler = (CatchClauseNode *)handler; m_guardedHandlers = guardedHandlers; - m_finalizer = (BlockStatementNode*) finalizer; + m_finalizer = (BlockStatementNode *)finalizer; } virtual ASTNodeType type() { return ASTNodeType::TryStatement; } - protected: BlockStatementNode *m_block; CatchClauseNode *m_handler; CatchClauseNodeVector m_guardedHandlers; BlockStatementNode *m_finalizer; }; - } #endif diff --git a/src/parser/ast/UnaryExpressionBitwiseNotNode.h b/src/parser/ast/UnaryExpressionBitwiseNotNode.h index 6b42c00c8..5e1b9c305 100644 --- a/src/parser/ast/UnaryExpressionBitwiseNotNode.h +++ b/src/parser/ast/UnaryExpressionBitwiseNotNode.h @@ -31,11 +31,9 @@ class UnaryExpressionBitwiseNotNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::UnaryExpressionBitwiseNot; } - protected: Node* m_argument; }; - } #endif diff --git a/src/parser/ast/UnaryExpressionDeleteNode.h b/src/parser/ast/UnaryExpressionDeleteNode.h index c9bca0015..c3b7c7757 100644 --- a/src/parser/ast/UnaryExpressionDeleteNode.h +++ b/src/parser/ast/UnaryExpressionDeleteNode.h @@ -27,15 +27,13 @@ class UnaryExpressionDeleteNode : public ExpressionNode { UnaryExpressionDeleteNode(Node* argument) : ExpressionNode() { - m_argument = (ExpressionNode*) argument; + m_argument = (ExpressionNode*)argument; } virtual ASTNodeType type() { return ASTNodeType::UnaryExpressionDelete; } - protected: ExpressionNode* m_argument; }; - } #endif diff --git a/src/parser/ast/UnaryExpressionLogicalNotNode.h b/src/parser/ast/UnaryExpressionLogicalNotNode.h index 6e4251122..6a36d7b43 100644 --- a/src/parser/ast/UnaryExpressionLogicalNotNode.h +++ b/src/parser/ast/UnaryExpressionLogicalNotNode.h @@ -31,11 +31,9 @@ class UnaryExpressionLogicalNotNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::UnaryExpressionLogicalNot; } - protected: Node* m_argument; }; - } #endif diff --git a/src/parser/ast/UnaryExpressionMinusNode.h b/src/parser/ast/UnaryExpressionMinusNode.h index 397794fb1..986929422 100644 --- a/src/parser/ast/UnaryExpressionMinusNode.h +++ b/src/parser/ast/UnaryExpressionMinusNode.h @@ -36,10 +36,10 @@ class UnaryExpressionMinusNode : public ExpressionNode { m_argument->generateExpressionByteCode(codeBlock, context); codeBlock->pushCode(UnaryMinus(ByteCodeLOC(m_loc.index), context->getLastRegisterIndex()), context, this); } + protected: Node* m_argument; }; - } #endif diff --git a/src/parser/ast/UnaryExpressionPlusNode.h b/src/parser/ast/UnaryExpressionPlusNode.h index 647cd11bb..6b7b2ec90 100644 --- a/src/parser/ast/UnaryExpressionPlusNode.h +++ b/src/parser/ast/UnaryExpressionPlusNode.h @@ -36,10 +36,10 @@ class UnaryExpressionPlusNode : public ExpressionNode { m_argument->generateExpressionByteCode(codeBlock, context); codeBlock->pushCode(UnaryPlus(ByteCodeLOC(m_loc.index), context->getLastRegisterIndex()), context, this); } + protected: Node* m_argument; }; - } #endif diff --git a/src/parser/ast/UnaryExpressionTypeOfNode.h b/src/parser/ast/UnaryExpressionTypeOfNode.h index bfe1b8168..6a5e556d0 100644 --- a/src/parser/ast/UnaryExpressionTypeOfNode.h +++ b/src/parser/ast/UnaryExpressionTypeOfNode.h @@ -31,11 +31,9 @@ class UnaryExpressionTypeOfNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::UnaryExpressionTypeOf; } - protected: Node* m_argument; }; - } #endif diff --git a/src/parser/ast/UnaryExpressionVoidNode.h b/src/parser/ast/UnaryExpressionVoidNode.h index 7ab26e363..8bc8de554 100644 --- a/src/parser/ast/UnaryExpressionVoidNode.h +++ b/src/parser/ast/UnaryExpressionVoidNode.h @@ -31,11 +31,9 @@ class UnaryExpressionVoidNode : public ExpressionNode { } virtual ASTNodeType type() { return ASTNodeType::UnaryExpressionVoid; } - protected: Node* m_argument; }; - } #endif diff --git a/src/parser/ast/UpdateExpressionDecrementPostfixNode.h b/src/parser/ast/UpdateExpressionDecrementPostfixNode.h index f4a64075a..860031b14 100644 --- a/src/parser/ast/UpdateExpressionDecrementPostfixNode.h +++ b/src/parser/ast/UpdateExpressionDecrementPostfixNode.h @@ -25,14 +25,13 @@ class UpdateExpressionDecrementPostfixNode : public ExpressionNode { public: friend class ScriptParser; - UpdateExpressionDecrementPostfixNode(Node *argument) + UpdateExpressionDecrementPostfixNode(Node* argument) : ExpressionNode() { m_argument = (ExpressionNode*)argument; } virtual ASTNodeType type() { return ASTNodeType::UpdateExpressionDecrementPostfix; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_argument->generateExpressionByteCode(codeBlock, context); @@ -43,10 +42,10 @@ class UpdateExpressionDecrementPostfixNode : public ExpressionNode { m_argument->generateStoreByteCode(codeBlock, context); context->giveUpRegister(); } + protected: ExpressionNode* m_argument; }; - } #endif diff --git a/src/parser/ast/UpdateExpressionDecrementPrefixNode.h b/src/parser/ast/UpdateExpressionDecrementPrefixNode.h index f6acf02ca..8ba944cdd 100644 --- a/src/parser/ast/UpdateExpressionDecrementPrefixNode.h +++ b/src/parser/ast/UpdateExpressionDecrementPrefixNode.h @@ -25,24 +25,23 @@ class UpdateExpressionDecrementPrefixNode : public ExpressionNode { public: friend class ScriptParser; - UpdateExpressionDecrementPrefixNode(Node *argument) + UpdateExpressionDecrementPrefixNode(Node* argument) : ExpressionNode() { m_argument = (ExpressionNode*)argument; } virtual ASTNodeType type() { return ASTNodeType::UpdateExpressionDecrementPrefix; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_argument->generateExpressionByteCode(codeBlock, context); codeBlock->pushCode(Decrement(ByteCodeLOC(m_loc.index), context->getLastRegisterIndex()), context, this); m_argument->generateStoreByteCode(codeBlock, context); } + protected: ExpressionNode* m_argument; }; - } #endif diff --git a/src/parser/ast/UpdateExpressionIncrementPostfixNode.h b/src/parser/ast/UpdateExpressionIncrementPostfixNode.h index b87157193..99bd44968 100644 --- a/src/parser/ast/UpdateExpressionIncrementPostfixNode.h +++ b/src/parser/ast/UpdateExpressionIncrementPostfixNode.h @@ -25,14 +25,13 @@ class UpdateExpressionIncrementPostfixNode : public ExpressionNode { public: friend class ScriptParser; - UpdateExpressionIncrementPostfixNode(Node *argument) + UpdateExpressionIncrementPostfixNode(Node* argument) : ExpressionNode() { m_argument = (ExpressionNode*)argument; } virtual ASTNodeType type() { return ASTNodeType::UpdateExpressionIncrementPostfix; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_argument->generateExpressionByteCode(codeBlock, context); @@ -43,10 +42,10 @@ class UpdateExpressionIncrementPostfixNode : public ExpressionNode { m_argument->generateStoreByteCode(codeBlock, context); context->giveUpRegister(); } + protected: ExpressionNode* m_argument; }; - } #endif diff --git a/src/parser/ast/UpdateExpressionIncrementPrefixNode.h b/src/parser/ast/UpdateExpressionIncrementPrefixNode.h index 30f42b0ba..0be4e2c19 100644 --- a/src/parser/ast/UpdateExpressionIncrementPrefixNode.h +++ b/src/parser/ast/UpdateExpressionIncrementPrefixNode.h @@ -25,24 +25,23 @@ class UpdateExpressionIncrementPrefixNode : public ExpressionNode { public: friend class ScriptParser; - UpdateExpressionIncrementPrefixNode(Node *argument) + UpdateExpressionIncrementPrefixNode(Node* argument) : ExpressionNode() { m_argument = (ExpressionNode*)argument; } virtual ASTNodeType type() { return ASTNodeType::UpdateExpressionIncrementPrefix; } - virtual void generateExpressionByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { m_argument->generateExpressionByteCode(codeBlock, context); codeBlock->pushCode(Increment(ByteCodeLOC(m_loc.index), context->getLastRegisterIndex()), context, this); m_argument->generateStoreByteCode(codeBlock, context); } + protected: ExpressionNode* m_argument; }; - } #endif diff --git a/src/parser/ast/VariableDeclarationNode.h b/src/parser/ast/VariableDeclarationNode.h index dbd89a666..40754fb2e 100644 --- a/src/parser/ast/VariableDeclarationNode.h +++ b/src/parser/ast/VariableDeclarationNode.h @@ -33,11 +33,10 @@ class VariableDeclarationNode : public DeclarationNode { virtual ASTNodeType type() { return ASTNodeType::VariableDeclaration; } VariableDeclaratorVector& declarations() { return m_declarations; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { size_t len = m_declarations.size(); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { m_declarations[i]->generateStatementByteCode(codeBlock, context); } } @@ -46,7 +45,6 @@ class VariableDeclarationNode : public DeclarationNode { VariableDeclaratorVector m_declarations; // declarations: [ VariableDeclarator ]; // kind: "var" | "let" | "const"; }; - } #endif diff --git a/src/parser/ast/VariableDeclaratorNode.h b/src/parser/ast/VariableDeclaratorNode.h index 5ace5caf4..a7cf3f5c1 100644 --- a/src/parser/ast/VariableDeclaratorNode.h +++ b/src/parser/ast/VariableDeclaratorNode.h @@ -17,10 +17,10 @@ #ifndef VariableDeclaratorNode_h #define VariableDeclaratorNode_h -#include "Node.h" -#include "PatternNode.h" #include "ExpressionNode.h" #include "IdentifierNode.h" +#include "Node.h" +#include "PatternNode.h" namespace Escargot { @@ -37,7 +37,6 @@ class VariableDeclaratorNode : public Node { virtual ASTNodeType type() { return ASTNodeType::VariableDeclarator; } Node* id() { return m_id; } Node* init() { return m_init; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) { ASSERT(m_id->isIdentifier()); @@ -55,8 +54,6 @@ class VariableDeclaratorNode : public Node { Node* m_id; // id: Pattern; Node* m_init; // init: Expression | null; }; - - } #endif diff --git a/src/parser/ast/WhileStatementNode.h b/src/parser/ast/WhileStatementNode.h index fc5656e64..1e17d18bc 100644 --- a/src/parser/ast/WhileStatementNode.h +++ b/src/parser/ast/WhileStatementNode.h @@ -17,8 +17,8 @@ #ifndef WhileStatementNode_h #define WhileStatementNode_h -#include "StatementNode.h" #include "ExpressionNode.h" +#include "StatementNode.h" namespace Escargot { @@ -28,13 +28,13 @@ class WhileStatementNode : public StatementNode { WhileStatementNode(Node *test, Node *body) : StatementNode() { - m_test = (ExpressionNode*) test; - m_body = (StatementNode*) body; + m_test = (ExpressionNode *)test; + m_body = (StatementNode *)body; } virtual ASTNodeType type() { return ASTNodeType::WhileStatement; } - virtual void generateStatementByteCode(ByteCodeBlock* codeBlock, ByteCodeGenerateContext* context) + virtual void generateStatementByteCode(ByteCodeBlock *codeBlock, ByteCodeGenerateContext *context) { ByteCodeGenerateContext newContext(*context); @@ -59,7 +59,6 @@ class WhileStatementNode : public StatementNode { ExpressionNode *m_test; StatementNode *m_body; }; - } #endif diff --git a/src/parser/esprima_cpp/esprima.cpp b/src/parser/esprima_cpp/esprima.cpp index 8b0395d16..2699951bf 100644 --- a/src/parser/esprima_cpp/esprima.cpp +++ b/src/parser/esprima_cpp/esprima.cpp @@ -167,10 +167,10 @@ ALWAYS_INLINE uint8_t toHexNumericValue(char16_t ch) ALWAYS_INLINE bool isWhiteSpace(char16_t ch) { return (ch == 0x20) || (ch == 0x09) || (ch == 0x0B) || (ch == 0x0C) || (ch == 0xA0) - || (ch >= 0x1680 && (ch == 0x1680 || ch == 0x180E || ch == 0x2000 || ch == 0x2001 - || ch == 0x2002 || ch == 0x2003 || ch == 0x2004 || ch == 0x2005 || ch == 0x2006 - || ch == 0x2007 || ch == 0x2008 || ch == 0x2009 || ch == 0x200A || ch == 0x202F - || ch == 0x205F || ch == 0x3000 || ch == 0xFEFF)); + || (ch >= 0x1680 && (ch == 0x1680 || ch == 0x180E || ch == 0x2000 || ch == 0x2001 + || ch == 0x2002 || ch == 0x2003 || ch == 0x2004 || ch == 0x2005 || ch == 0x2006 + || ch == 0x2007 || ch == 0x2008 || ch == 0x2009 || ch == 0x200A || ch == 0x202F + || ch == 0x205F || ch == 0x3000 || ch == 0xFEFF)); } // ECMA-262 11.3 Line Terminators @@ -255,7 +255,7 @@ ALWAYS_INLINE bool isIdentifierStart(char32_t ch) struct Curly { char m_curly[4]; - Curly() { } + Curly() {} Curly(const char curly[4]) { m_curly[0] = curly[0]; @@ -448,7 +448,8 @@ class ErrorHandler : public gc { // errors: Error[]; // tolerant: boolean; - ErrorHandler() { + ErrorHandler() + { // this->errors = []; // this->tolerant = false; } @@ -476,7 +477,7 @@ class ErrorHandler : public gc { // try { // throw error; // } catch (base) { - /* istanbul ignore else */ + /* istanbul ignore else */ // if (Object.create && Object.defineProperty) { // error = Object.create(base); // Object.defineProperty(error, 'column', { value: column }); @@ -550,11 +551,11 @@ class Scanner { return index >= length; } - void throwUnexpectedToken(const char *message = Messages::UnexpectedTokenIllegal) + void throwUnexpectedToken(const char* message = Messages::UnexpectedTokenIllegal) { this->errorHandler->throwError(this->index, this->lineNumber, this->index - this->lineStart + 1, new ASCIIString(message)); } -/* + /* tolerateUnexpectedToken() { this->errorHandler.tolerateError(this->index, this->lineNumber, this->index - this->lineStart + 1, Messages.UnexpectedTokenIllegal); @@ -742,7 +743,7 @@ class Scanner { */ this->skipSingleLineComment(2); start = true; - } else if (ch == 0x2A) { // U+002A is '*' + } else if (ch == 0x2A) { // U+002A is '*' this->index += 2; /* const comment = this->skipMultiLineComment(); @@ -1508,7 +1509,7 @@ class Scanner { if (ch != '0' && ch != '1') { break; } - number = (number << 1) + ch - '0'; + number = (number << 1) + ch - '0'; this->index++; scanned = true; } @@ -1577,7 +1578,7 @@ class Scanner { const size_t start = this->index; char16_t ch = this->source.charAt(start); ASSERT(isDecimalDigit(ch) || (ch == '.')); - // 'Numeric literal must start with a decimal digit or a decimal point'); + // 'Numeric literal must start with a decimal digit or a decimal point'); std::string number; number.reserve(32); @@ -1647,9 +1648,10 @@ class Scanner { int length = number.length(); int length_dummy; double_conversion::StringToDoubleConverter converter(double_conversion::StringToDoubleConverter::ALLOW_HEX - | double_conversion::StringToDoubleConverter::ALLOW_LEADING_SPACES - | double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES, 0.0, double_conversion::Double::NaN(), - "Infinity", "NaN"); + | double_conversion::StringToDoubleConverter::ALLOW_LEADING_SPACES + | double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES, + 0.0, double_conversion::Double::NaN(), + "Infinity", "NaN"); double ll = converter.StringToDouble(number.data(), length, &length_dummy); return new ScannerResult(Token::NumericLiteralToken, ll, this->lineNumber, this->lineStart, start, this->index); @@ -1663,7 +1665,7 @@ class Scanner { const size_t start = this->index; char16_t quote = this->source.charAt(start); ASSERT((quote == '\'' || quote == '"')); - // 'String literal must starts with a quote'); + // 'String literal must starts with a quote'); ++this->index; bool octal = false; @@ -1673,12 +1675,12 @@ class Scanner { UTF16StringDataNonGCStd stringUTF16; StringView str; -#define CONVERT_UNPLAIN_CASE_IF_NEEDED() \ - if (isPlainCase) { \ - auto temp = str.toUTF16StringData(); \ - stringUTF16 = UTF16StringDataNonGCStd(temp.data(), temp.length()); \ - isPlainCase = false; \ - } \ +#define CONVERT_UNPLAIN_CASE_IF_NEEDED() \ + if (isPlainCase) { \ + auto temp = str.toUTF16StringData(); \ + stringUTF16 = UTF16StringDataNonGCStd(temp.data(), temp.length()); \ + isPlainCase = false; \ + } while (!this->eof()) { char16_t ch = this->source.charAt(this->index++); @@ -1691,55 +1693,55 @@ class Scanner { if (!ch || !isLineTerminator(ch)) { CONVERT_UNPLAIN_CASE_IF_NEEDED() switch (ch) { - case 'u': - case 'x': - if (this->source.charAt(this->index) == '{') { - ++this->index; - ParserCharPiece piece(this->scanUnicodeCodePointEscape()); - stringUTF16 += piece.data; - } else { - const char32_t unescaped = this->scanHexEscape(ch); - if (!unescaped) { - this->throwUnexpectedToken(); - } - ParserCharPiece piece(unescaped); - stringUTF16 += piece.data; + case 'u': + case 'x': + if (this->source.charAt(this->index) == '{') { + ++this->index; + ParserCharPiece piece(this->scanUnicodeCodePointEscape()); + stringUTF16 += piece.data; + } else { + const char32_t unescaped = this->scanHexEscape(ch); + if (!unescaped) { + this->throwUnexpectedToken(); } - break; - case 'n': - stringUTF16 += '\n'; - break; - case 'r': - stringUTF16 += '\r'; - break; - case 't': - stringUTF16 += '\t'; - break; - case 'b': - stringUTF16 += '\b'; - break; - case 'f': - stringUTF16 += '\f'; - break; - case 'v': - stringUTF16 += '\x0B'; - break; - case '8': - case '9': - stringUTF16 += ch; - this->tolerateUnexpectedToken(); - break; + ParserCharPiece piece(unescaped); + stringUTF16 += piece.data; + } + break; + case 'n': + stringUTF16 += '\n'; + break; + case 'r': + stringUTF16 += '\r'; + break; + case 't': + stringUTF16 += '\t'; + break; + case 'b': + stringUTF16 += '\b'; + break; + case 'f': + stringUTF16 += '\f'; + break; + case 'v': + stringUTF16 += '\x0B'; + break; + case '8': + case '9': + stringUTF16 += ch; + this->tolerateUnexpectedToken(); + break; - default: - if (ch && isOctalDigit(ch)) { - OctalToDecimalResult octToDec = this->octalToDecimal(ch); + default: + if (ch && isOctalDigit(ch)) { + OctalToDecimalResult octToDec = this->octalToDecimal(ch); - octal = octToDec.octal || octal; - stringUTF16 += octToDec.code; - } else { - stringUTF16 += ch; - } - break; + octal = octToDec.octal || octal; + stringUTF16 += octToDec.code; + } else { + stringUTF16 += ch; + } + break; } } else { ++this->lineNumber; @@ -1766,10 +1768,10 @@ class Scanner { ScannerResult* ret; if (isPlainCase) { - ret = new ScannerResult(Token::StringLiteralToken, str, /*octal, */this->lineNumber, this->lineStart, start, this->index); + ret = new ScannerResult(Token::StringLiteralToken, str, /*octal, */ this->lineNumber, this->lineStart, start, this->index); } else { String* newStr = new UTF16String(stringUTF16.data(), stringUTF16.length()); - ret = new ScannerResult(Token::StringLiteralToken, StringView(newStr, 0, newStr->length()), /*octal, */this->lineNumber, this->lineStart, start, this->index); + ret = new ScannerResult(Token::StringLiteralToken, StringView(newStr, 0, newStr->length()), /*octal, */ this->lineNumber, this->lineStart, start, this->index); } ret->octal = octal; @@ -1810,56 +1812,56 @@ class Scanner { ch = this->source.charAt(this->index++); if (!isLineTerminator(ch)) { switch (ch) { - case 'n': - cooked += '\n'; - break; - case 'r': - cooked += '\r'; - break; - case 't': - cooked += '\t'; - break; - case 'u': - case 'x': - if (this->source.charAt(this->index) == '{') { - ++this->index; - cooked += this->scanUnicodeCodePointEscape(); + case 'n': + cooked += '\n'; + break; + case 'r': + cooked += '\r'; + break; + case 't': + cooked += '\t'; + break; + case 'u': + case 'x': + if (this->source.charAt(this->index) == '{') { + ++this->index; + cooked += this->scanUnicodeCodePointEscape(); + } else { + const size_t restore = this->index; + const char32_t unescaped = this->scanHexEscape(ch); + if (unescaped) { + ParserCharPiece piece(unescaped); + cooked += piece.data; } else { - const size_t restore = this->index; - const char32_t unescaped = this->scanHexEscape(ch); - if (unescaped) { - ParserCharPiece piece(unescaped); - cooked += piece.data; - } else { - this->index = restore; - cooked += ch; - } + this->index = restore; + cooked += ch; } - break; - case 'b': - cooked += '\b'; - break; - case 'f': - cooked += '\f'; - break; - case 'v': - cooked += '\v'; - break; + } + break; + case 'b': + cooked += '\b'; + break; + case 'f': + cooked += '\f'; + break; + case 'v': + cooked += '\v'; + break; - default: - if (ch == '0') { - if (isDecimalDigit(this->source.charAt(this->index))) { - // Illegal: \01 \02 and so on - this->throwUnexpectedToken(Messages::TemplateOctalLiteral); - } - cooked += (char16_t)'\0'; - } else if (isOctalDigit(ch)) { - // Illegal: \1 \2 + default: + if (ch == '0') { + if (isDecimalDigit(this->source.charAt(this->index))) { + // Illegal: \01 \02 and so on this->throwUnexpectedToken(Messages::TemplateOctalLiteral); - } else { - cooked += ch; } - break; + cooked += (char16_t)'\0'; + } else if (isOctalDigit(ch)) { + // Illegal: \1 \2 + this->throwUnexpectedToken(Messages::TemplateOctalLiteral); + } else { + cooked += ch; + } + break; } } else { ++this->lineNumber; @@ -1899,7 +1901,7 @@ class Scanner { } // ECMA-262 11.8.5 Regular Expression Literals -/* + /* testRegExp(pattern: string, flags: string) { // The BMP character to use as a replacement for astral symbols when // translating an ES6 "u"-flagged pattern to an ES5-compatible @@ -2121,7 +2123,6 @@ class Scanner { } return this->scanPunctuator(); } - }; struct Config : public gc { @@ -2178,10 +2179,12 @@ class Parser : public gc { ErrorHandler* errorHandler; std::unique_ptr scanner; std::unordered_map, std::equal_to, gc_malloc_ignore_off_page_allocator>> nodeExtraInfo; + std::hash, std::equal_to, gc_malloc_ignore_off_page_allocator>> + nodeExtraInfo; enum SourceType { - Script, Module + Script, + Module }; SourceType sourceType; ScannerResult* lookahead; @@ -2205,7 +2208,7 @@ class Parser : public gc { void extractNamesFromFunctionParams(const PatternNodeVector& vector) { - for (size_t i = 0 ; i < vector.size(); i ++) { + for (size_t i = 0; i < vector.size(); i++) { ASSERT(vector[i]->isIdentifier()); IdentifierNode* id = (IdentifierNode*)vector[i]; scopeContexts.back()->insertName(id->name()); @@ -2217,7 +2220,7 @@ class Parser : public gc { auto parentContext = scopeContexts.back(); scopeContexts.push_back(new ASTScopeContext(this->context->strict, scopeContexts.back())); scopeContexts.back()->m_functionName = functionName; - for (size_t i = 0 ; i < params.size(); i ++) { + for (size_t i = 0; i < params.size(); i++) { ASSERT(params[i]->isIdentifier()); IdentifierNode* id = (IdentifierNode*)params[i]; scopeContexts.back()->m_parameters.pushBack(id->name()); @@ -2227,7 +2230,7 @@ class Parser : public gc { } } - Parser(::Escargot::Context* escargotContext, StringView code, ParserASTNodeHandler delegate, size_t startLine = 0, size_t startColumn = 0/*, options: any = {}, delegate*/) + Parser(::Escargot::Context* escargotContext, StringView code, ParserASTNodeHandler delegate, size_t startLine = 0, size_t startColumn = 0 /*, options: any = {}, delegate*/) { this->escargotContext = escargotContext; trackUsingNames = true; @@ -2320,10 +2323,10 @@ class Parser : public gc { void replaceAll(UTF16StringDataNonGCStd& str, const UTF16StringDataNonGCStd& from, const UTF16StringDataNonGCStd& to) { - if(from.empty()) + if (from.empty()) return; size_t start_pos = 0; - while((start_pos = str.find(from, start_pos)) != std::string::npos) { + while ((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); } @@ -2341,12 +2344,7 @@ class Parser : public gc { String* value; if (token) { if (!msg) { - msg = (token->type == Token::EOFToken) ? Messages::UnexpectedEOS : - (token->type == Token::IdentifierToken) ? Messages::UnexpectedIdentifier : - (token->type == Token::NumericLiteralToken) ? Messages::UnexpectedNumber : - (token->type == Token::StringLiteralToken) ? Messages::UnexpectedString : - (token->type == Token::TemplateToken) ? Messages::UnexpectedTemplate : - Messages::UnexpectedToken; + msg = (token->type == Token::EOFToken) ? Messages::UnexpectedEOS : (token->type == Token::IdentifierToken) ? Messages::UnexpectedIdentifier : (token->type == Token::NumericLiteralToken) ? Messages::UnexpectedNumber : (token->type == Token::StringLiteralToken) ? Messages::UnexpectedString : (token->type == Token::TemplateToken) ? Messages::UnexpectedTemplate : Messages::UnexpectedToken; if (token->type == Token::KeywordToken) { if (this->scanner->isFutureReservedWord(token->valueString)) { @@ -2533,7 +2531,7 @@ class Parser : public gc { if (type == CallExpression) { CallExpressionNode* c = (CallExpressionNode*)node; if (c->callee()->isIdentifier()) { - if (((IdentifierNode*)c->callee())->name().string()->equals("eval")){ + if (((IdentifierNode*)c->callee())->name().string()->equals("eval")) { scopeContexts.back()->m_hasEval = true; } } @@ -2546,7 +2544,7 @@ class Parser : public gc { node->m_loc = NodeLOC(meta.line, meta.column, meta.index); if (this->delegate) { this->delegate(node, NodeLOC(meta.line, meta.column, meta.index), - NodeLOC(this->lastMarker.lineNumber, this->lastMarker.index - this->lastMarker.lineStart, this->lastMarker.index)); + NodeLOC(this->lastMarker.lineNumber, this->lastMarker.index - this->lastMarker.lineStart, this->lastMarker.index)); } return node; @@ -2734,13 +2732,14 @@ class Parser : public gc { return ret; } -#define DEFINE_AS_NODE(TypeName) \ +#define DEFINE_AS_NODE(TypeName) \ TypeName##Node* as##TypeName##Node(Node* n) \ - { \ - if (!n) return (TypeName##Node*)n; \ - ASSERT(n->is##TypeName##Node()); \ - return (TypeName##Node*)n; \ - } \ + { \ + if (!n) \ + return (TypeName##Node*)n; \ + ASSERT(n->is##TypeName##Node()); \ + return (TypeName##Node*)n; \ + } DEFINE_AS_NODE(Expression); DEFINE_AS_NODE(Statement); @@ -2756,109 +2755,108 @@ class Parser : public gc { ScannerResult* token; switch (this->lookahead->type) { - case Token::IdentifierToken: - if (this->sourceType == SourceType::Module && this->lookahead->valueKeywordKind == KeywordKind::Await) { - this->tolerateUnexpectedToken(this->lookahead); - } - expr = this->finalize(node, finishIdentifier(this->nextToken(), true)); - break; + case Token::IdentifierToken: + if (this->sourceType == SourceType::Module && this->lookahead->valueKeywordKind == KeywordKind::Await) { + this->tolerateUnexpectedToken(this->lookahead); + } + expr = this->finalize(node, finishIdentifier(this->nextToken(), true)); + break; - case Token::NumericLiteralToken: - case Token::StringLiteralToken: - if (this->context->strict && this->lookahead->octal) { - this->tolerateUnexpectedToken(this->lookahead, Messages::StrictOctalLiteral); - } - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - token = this->nextToken(); - // raw = this->getTokenRaw(token); - if (token->type == Token::NumericLiteralToken) - expr = this->finalize(node, new LiteralNode(Value(token->valueNumber))); - else - expr = this->finalize(node, new LiteralNode(Value(new StringView(token->valueString)))); - break; + case Token::NumericLiteralToken: + case Token::StringLiteralToken: + if (this->context->strict && this->lookahead->octal) { + this->tolerateUnexpectedToken(this->lookahead, Messages::StrictOctalLiteral); + } + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + token = this->nextToken(); + // raw = this->getTokenRaw(token); + if (token->type == Token::NumericLiteralToken) + expr = this->finalize(node, new LiteralNode(Value(token->valueNumber))); + else + expr = this->finalize(node, new LiteralNode(Value(new StringView(token->valueString)))); + break; - case Token::BooleanLiteralToken: - this->context->isAssignmentTarget = false; + case Token::BooleanLiteralToken: + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + token = this->nextToken(); + // token.value = (token.value === 'true'); + // raw = this->getTokenRaw(token); + { + bool value = token->valueString == "true"; + expr = this->finalize(node, new LiteralNode(Value(value))); + } + break; + + case Token::NullLiteralToken: + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + token = this->nextToken(); + // token.value = null; + // raw = this->getTokenRaw(token); + expr = this->finalize(node, new LiteralNode(Value(Value::Null))); + break; + + case Token::TemplateToken: + expr = this->parseTemplateLiteral(); + break; + + case Token::PunctuatorToken: { + PunctuatorsKind value = this->lookahead->valuePunctuatorsKind; + switch (value) { + case LeftParenthesis: this->context->isBindingElement = false; - token = this->nextToken(); - // token.value = (token.value === 'true'); - // raw = this->getTokenRaw(token); - { - bool value = token->valueString == "true"; - expr = this->finalize(node, new LiteralNode(Value(value))); - } + expr = this->inheritCoverGrammar(&Parser::parseGroupExpression); break; - - case Token::NullLiteralToken: + case LeftSquareBracket: + expr = this->inheritCoverGrammar(&Parser::parseArrayInitializer); + break; + case LeftBrace: + expr = this->inheritCoverGrammar(&Parser::parseObjectInitializer); + break; + case Divide: + case DivideEqual: this->context->isAssignmentTarget = false; this->context->isBindingElement = false; - token = this->nextToken(); - // token.value = null; + this->scanner->index = this->startMarker.index; + token = this->nextRegexToken(); // raw = this->getTokenRaw(token); - expr = this->finalize(node, new LiteralNode(Value(Value::Null))); - break; - - case Token::TemplateToken: - expr = this->parseTemplateLiteral(); - break; - - case Token::PunctuatorToken: - { - PunctuatorsKind value = this->lookahead->valuePunctuatorsKind; - switch (value) { - case LeftParenthesis: - this->context->isBindingElement = false; - expr = this->inheritCoverGrammar(&Parser::parseGroupExpression); - break; - case LeftSquareBracket: - expr = this->inheritCoverGrammar(&Parser::parseArrayInitializer); - break; - case LeftBrace: - expr = this->inheritCoverGrammar(&Parser::parseObjectInitializer); - break; - case Divide: - case DivideEqual: - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - this->scanner->index = this->startMarker.index; - token = this->nextRegexToken(); - // raw = this->getTokenRaw(token); - // TODO - RELEASE_ASSERT_NOT_REACHED(); - // expr = this->finalize(node, new Node.RegexLiteral(token.value, raw, token.regex)); - break; - default: - this->throwUnexpectedToken(this->nextToken()); - } + // TODO + RELEASE_ASSERT_NOT_REACHED(); + // expr = this->finalize(node, new Node.RegexLiteral(token.value, raw, token.regex)); break; + default: + this->throwUnexpectedToken(this->nextToken()); } + break; + } - case Token::KeywordToken: - if (!this->context->strict && this->context->allowYield && this->matchKeyword(KeywordKind::Yield)) { - expr = this->parseIdentifierName(); - } else if (!this->context->strict && this->matchKeyword(KeywordKind::Let)) { - expr = this->finalize(node, finishIdentifier(this->nextToken(), true)); + case Token::KeywordToken: + if (!this->context->strict && this->context->allowYield && this->matchKeyword(KeywordKind::Yield)) { + expr = this->parseIdentifierName(); + } else if (!this->context->strict && this->matchKeyword(KeywordKind::Let)) { + expr = this->finalize(node, finishIdentifier(this->nextToken(), true)); + } else { + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + if (this->matchKeyword(KeywordKind::Function)) { + expr = this->parseFunctionExpression(); + } else if (this->matchKeyword(KeywordKind::This)) { + this->nextToken(); + expr = this->finalize(node, new ThisExpressionNode()); + } else if (this->matchKeyword(KeywordKind::Class)) { + // TODO + RELEASE_ASSERT_NOT_REACHED(); + // expr = this->parseClassExpression(); } else { - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - if (this->matchKeyword(KeywordKind::Function)) { - expr = this->parseFunctionExpression(); - } else if (this->matchKeyword(KeywordKind::This)) { - this->nextToken(); - expr = this->finalize(node, new ThisExpressionNode()); - } else if (this->matchKeyword(KeywordKind::Class)) { - // TODO - RELEASE_ASSERT_NOT_REACHED(); - // expr = this->parseClassExpression(); - } else { - this->throwUnexpectedToken(this->nextToken()); - } + this->throwUnexpectedToken(this->nextToken()); } - break; + } + break; - default: - this->throwUnexpectedToken(this->nextToken()); + default: + this->throwUnexpectedToken(this->nextToken()); } return expr; @@ -3067,28 +3065,28 @@ class Parser : public gc { // ECMA-262 12.2.6 Object Initializer - Node* parsePropertyMethod(ParseFormalParametersResult& params) - { - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - - pushScopeContext(params.params, AtomicString()); - extractNamesFromFunctionParams(params.params); - const bool previousStrict = this->context->strict; - Node* body = this->isolateCoverGrammar(&Parser::parseFunctionSourceElements); - if (this->context->strict && params.firstRestricted) { - this->tolerateUnexpectedToken(params.firstRestricted, params.message); - } - if (this->context->strict && params.stricted) { - this->tolerateUnexpectedToken(params.stricted, params.message); - } - this->context->strict = previousStrict; + Node* parsePropertyMethod(ParseFormalParametersResult& params) + { + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; - return body; - } + pushScopeContext(params.params, AtomicString()); + extractNamesFromFunctionParams(params.params); + const bool previousStrict = this->context->strict; + Node* body = this->isolateCoverGrammar(&Parser::parseFunctionSourceElements); + if (this->context->strict && params.firstRestricted) { + this->tolerateUnexpectedToken(params.firstRestricted, params.message); + } + if (this->context->strict && params.stricted) { + this->tolerateUnexpectedToken(params.stricted, params.message); + } + this->context->strict = previousStrict; + + return body; + } - FunctionExpressionNode* parsePropertyMethodFunction() - { + FunctionExpressionNode* parsePropertyMethodFunction() + { const bool isGenerator = false; MetaNode node = this->createNode(); @@ -3099,195 +3097,195 @@ class Parser : public gc { this->context->allowYield = previousAllowYield; return this->finalize(node, new FunctionExpressionNode(AtomicString(), std::move(params.params), method, popScopeContext(node), isGenerator)); - } + } - Node* parseObjectPropertyKey() - { - MetaNode node = this->createNode(); - ScannerResult* token = this->nextToken(); - - Node* key = nullptr; - switch (token->type) { - case Token::NumericLiteralToken: - case Token::StringLiteralToken: - if (this->context->strict && token->octal) { - this->tolerateUnexpectedToken(token, Messages::StrictOctalLiteral); - } - // const raw = this->getTokenRaw(token); - { - Value v; - if (token->type == Token::NumericLiteralToken) { - v = Value(token->valueNumber); - } else { - v = Value(new StringView(token->valueString)); - } - key = this->finalize(node, new LiteralNode(v)); - } - break; + Node* parseObjectPropertyKey() + { + MetaNode node = this->createNode(); + ScannerResult* token = this->nextToken(); - case Token::IdentifierToken: - case Token::BooleanLiteralToken: - case Token::NullLiteralToken: - case Token::KeywordToken: - key = this->finalize(node, finishIdentifier(token, false)); - break; + Node* key = nullptr; + switch (token->type) { + case Token::NumericLiteralToken: + case Token::StringLiteralToken: + if (this->context->strict && token->octal) { + this->tolerateUnexpectedToken(token, Messages::StrictOctalLiteral); + } + // const raw = this->getTokenRaw(token); + { + Value v; + if (token->type == Token::NumericLiteralToken) { + v = Value(token->valueNumber); + } else { + v = Value(new StringView(token->valueString)); + } + key = this->finalize(node, new LiteralNode(v)); + } + break; - case Token::PunctuatorToken: - if (token->valuePunctuatorsKind == LeftSquareBracket) { - key = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); - this->expect(RightSquareBracket); - } else { - this->throwUnexpectedToken(token); - } - break; + case Token::IdentifierToken: + case Token::BooleanLiteralToken: + case Token::NullLiteralToken: + case Token::KeywordToken: + key = this->finalize(node, finishIdentifier(token, false)); + break; - default: - this->throwUnexpectedToken(token); - } + case Token::PunctuatorToken: + if (token->valuePunctuatorsKind == LeftSquareBracket) { + key = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); + this->expect(RightSquareBracket); + } else { + this->throwUnexpectedToken(token); + } + break; - return key; - } + default: + this->throwUnexpectedToken(token); + } - bool qualifiedPropertyName(ScannerResult* token) - { - switch (token->type) { - case Token::IdentifierToken: - case Token::StringLiteralToken: - case Token::BooleanLiteralToken: - case Token::NullLiteralToken: - case Token::NumericLiteralToken: - case Token::KeywordToken: - return true; - case Token::PunctuatorToken: - return token->valuePunctuatorsKind == LeftSquareBracket; - default: - return false; - } - } + return key; + } + bool qualifiedPropertyName(ScannerResult* token) + { + switch (token->type) { + case Token::IdentifierToken: + case Token::StringLiteralToken: + case Token::BooleanLiteralToken: + case Token::NullLiteralToken: + case Token::NumericLiteralToken: + case Token::KeywordToken: + return true; + case Token::PunctuatorToken: + return token->valuePunctuatorsKind == LeftSquareBracket; + default: + return false; + } + } - bool isPropertyKey(Node* key, const char* value) - { - if (key->type() == Identifier) { - return ((IdentifierNode*)key)->name() == value; - } else if (key->type() == Literal) { - if (((LiteralNode*)key)->value().isString()) { - return ((LiteralNode*)key)->value().asString()->equals(value); - } - } - return false; - } + bool isPropertyKey(Node* key, const char* value) + { + if (key->type() == Identifier) { + return ((IdentifierNode*)key)->name() == value; + } else if (key->type() == Literal) { + if (((LiteralNode*)key)->value().isString()) { + return ((LiteralNode*)key)->value().asString()->equals(value); + } + } + + return false; + } - PropertyNode* parseObjectProperty(bool& hasProto)//: Node.Property - { - MetaNode node = this->createNode(); - ScannerResult* token = this->lookahead; + PropertyNode* parseObjectProperty(bool& hasProto) //: Node.Property + { + MetaNode node = this->createNode(); + ScannerResult* token = this->lookahead; - PropertyNode::Kind kind; - Node* key; //'': Node.PropertyKey; - Node* value; //: Node.PropertyValue; + PropertyNode::Kind kind; + Node* key; //'': Node.PropertyKey; + Node* value; //: Node.PropertyValue; - bool computed = false; - bool method = false; - bool shorthand = false; + bool computed = false; + bool method = false; + bool shorthand = false; - if (token->type == Token::IdentifierToken) { - this->nextToken(); - key = this->finalize(node, finishIdentifier(token, true)); - } else if (this->match(PunctuatorsKind::Multiply)) { - this->nextToken(); - } else { - computed = this->match(LeftSquareBracket); - key = this->parseObjectPropertyKey(); - } + if (token->type == Token::IdentifierToken) { + this->nextToken(); + key = this->finalize(node, finishIdentifier(token, true)); + } else if (this->match(PunctuatorsKind::Multiply)) { + this->nextToken(); + } else { + computed = this->match(LeftSquareBracket); + key = this->parseObjectPropertyKey(); + } - bool lookaheadPropertyKey = this->qualifiedPropertyName(this->lookahead); - if (token->type == Token::IdentifierToken && token->valueString == "get" && lookaheadPropertyKey) { - kind = PropertyNode::Kind::Get; - computed = this->match(LeftSquareBracket); - key = this->parseObjectPropertyKey(); - this->context->allowYield = false; - value = this->parseGetterMethod(); - - } else if (token->type == Token::IdentifierToken && token->valueString == "set" && lookaheadPropertyKey) { - kind = PropertyNode::Kind::Set; - computed = this->match(LeftSquareBracket); - key = this->parseObjectPropertyKey(); - value = this->parseSetterMethod(); - - } else if (token->type == Token::PunctuatorToken && token->valueString == "*" && lookaheadPropertyKey) { - kind = PropertyNode::Kind::Init; - computed = this->match(LeftSquareBracket); - key = this->parseObjectPropertyKey(); - value = this->parseGeneratorMethod(); - method = true; + bool lookaheadPropertyKey = this->qualifiedPropertyName(this->lookahead); + if (token->type == Token::IdentifierToken && token->valueString == "get" && lookaheadPropertyKey) { + kind = PropertyNode::Kind::Get; + computed = this->match(LeftSquareBracket); + key = this->parseObjectPropertyKey(); + this->context->allowYield = false; + value = this->parseGetterMethod(); - } else { - if (!key) { - this->throwUnexpectedToken(this->lookahead); - } + } else if (token->type == Token::IdentifierToken && token->valueString == "set" && lookaheadPropertyKey) { + kind = PropertyNode::Kind::Set; + computed = this->match(LeftSquareBracket); + key = this->parseObjectPropertyKey(); + value = this->parseSetterMethod(); - kind = PropertyNode::Kind::Init; - if (this->match(PunctuatorsKind::Colon)) { - if (!computed && this->isPropertyKey(key, "__proto__")) { - if (hasProto) { - this->tolerateError(Messages::DuplicateProtoProperty); - } - hasProto = true; - } - this->nextToken(); - value = this->inheritCoverGrammar(&Parser::parseAssignmentExpression); - - } else if (this->match(LeftParenthesis)) { - value = this->parsePropertyMethodFunction(); - method = true; - - } else if (token->type == Token::IdentifierToken) { - Node* id = this->finalize(node, finishIdentifier(token, true)); - if (this->match(Substitution)) { - this->context->firstCoverInitializedNameError = this->lookahead; - this->nextToken(); - shorthand = true; - Node* init = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); - value = this->finalize(node, new AssignmentExpressionSimpleNode(id, init)); - } else { - shorthand = true; - value = id; - } - } else { - this->throwUnexpectedToken(this->nextToken()); - } - } + } else if (token->type == Token::PunctuatorToken && token->valueString == "*" && lookaheadPropertyKey) { + kind = PropertyNode::Kind::Init; + computed = this->match(LeftSquareBracket); + key = this->parseObjectPropertyKey(); + value = this->parseGeneratorMethod(); + method = true; - // return this->finalize(node, new PropertyNode(kind, key, computed, value, method, shorthand)); - return this->finalize(node, new PropertyNode(key, value, kind)); - } + } else { + if (!key) { + this->throwUnexpectedToken(this->lookahead); + } - Node* parseObjectInitializer() - { - MetaNode node = this->createNode(); - - this->expect(LeftBrace); - PropertiesNodeVector properties; - bool hasProto = false; - while (!this->match(RightBrace)) { - properties.push_back(this->parseObjectProperty(hasProto)); - if (!this->match(RightBrace)) { - this->expectCommaSeparator(); - } - } - this->expect(RightBrace); + kind = PropertyNode::Kind::Init; + if (this->match(PunctuatorsKind::Colon)) { + if (!computed && this->isPropertyKey(key, "__proto__")) { + if (hasProto) { + this->tolerateError(Messages::DuplicateProtoProperty); + } + hasProto = true; + } + this->nextToken(); + value = this->inheritCoverGrammar(&Parser::parseAssignmentExpression); - return this->finalize(node, new ObjectExpressionNode(std::move(properties))); - } + } else if (this->match(LeftParenthesis)) { + value = this->parsePropertyMethodFunction(); + method = true; - // ECMA-262 12.2.9 Template Literals - Node* parseTemplateLiteral() - { - RELEASE_ASSERT_NOT_REACHED(); - } -/* + } else if (token->type == Token::IdentifierToken) { + Node* id = this->finalize(node, finishIdentifier(token, true)); + if (this->match(Substitution)) { + this->context->firstCoverInitializedNameError = this->lookahead; + this->nextToken(); + shorthand = true; + Node* init = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); + value = this->finalize(node, new AssignmentExpressionSimpleNode(id, init)); + } else { + shorthand = true; + value = id; + } + } else { + this->throwUnexpectedToken(this->nextToken()); + } + } + + // return this->finalize(node, new PropertyNode(kind, key, computed, value, method, shorthand)); + return this->finalize(node, new PropertyNode(key, value, kind)); + } + + Node* parseObjectInitializer() + { + MetaNode node = this->createNode(); + + this->expect(LeftBrace); + PropertiesNodeVector properties; + bool hasProto = false; + while (!this->match(RightBrace)) { + properties.push_back(this->parseObjectProperty(hasProto)); + if (!this->match(RightBrace)) { + this->expectCommaSeparator(); + } + } + this->expect(RightBrace); + + return this->finalize(node, new ObjectExpressionNode(std::move(properties))); + } + + // ECMA-262 12.2.9 Template Literals + Node* parseTemplateLiteral() + { + RELEASE_ASSERT_NOT_REACHED(); + } + /* parseTemplateHead(): Node.TemplateElement { assert(this->lookahead.head, 'Template literal must start with a template head'); @@ -3481,343 +3479,338 @@ class Parser : public gc { return expr; } */ - Node* parseGroupExpression() - { - Node* expr; - - this->expect(LeftParenthesis); - if (this->match(RightParenthesis)) { - RELEASE_ASSERT_NOT_REACHED(); - } else { - ScannerResult* startToken = this->lookahead; - this->context->isBindingElement = true; - expr = this->inheritCoverGrammar(&Parser::parseAssignmentExpression); + Node* parseGroupExpression() + { + Node* expr; - if (this->match(Comma)) { - ExpressionNodeVector expressions; + this->expect(LeftParenthesis); + if (this->match(RightParenthesis)) { + RELEASE_ASSERT_NOT_REACHED(); + } else { + ScannerResult* startToken = this->lookahead; + this->context->isBindingElement = true; + expr = this->inheritCoverGrammar(&Parser::parseAssignmentExpression); - this->context->isAssignmentTarget = false; - expressions.push_back(expr); - while (this->startMarker.index < this->scanner->length) { - if (!this->match(Comma)) { - break; - } - this->nextToken(); + if (this->match(Comma)) { + ExpressionNodeVector expressions; - expressions.push_back(this->inheritCoverGrammar(&Parser::parseAssignmentExpression)); - } - expr = this->finalize(this->startNode(startToken), new SequenceExpressionNode(std::move(expressions))); - } - } - this->expect(RightParenthesis); + this->context->isAssignmentTarget = false; + expressions.push_back(expr); + while (this->startMarker.index < this->scanner->length) { + if (!this->match(Comma)) { + break; + } + this->nextToken(); - return expr; - } - // ECMA-262 12.3 Left-Hand-Side Expressions - - ArgumentVector parseArguments() - { - this->expect(LeftParenthesis); - ArgumentVector args; - if (!this->match(RightParenthesis)) { - while (true) { - Node* expr = this->match(PeriodPeriodPeriod) ? this->parseSpreadElement() : - this->isolateCoverGrammar(&Parser::parseAssignmentExpression); - args.push_back(expr); - if (this->match(RightParenthesis)) { - break; - } - this->expectCommaSeparator(); - } - } - this->expect(RightParenthesis); + expressions.push_back(this->inheritCoverGrammar(&Parser::parseAssignmentExpression)); + } + expr = this->finalize(this->startNode(startToken), new SequenceExpressionNode(std::move(expressions))); + } + } + this->expect(RightParenthesis); - return args; - } + return expr; + } + // ECMA-262 12.3 Left-Hand-Side Expressions - bool isIdentifierName(ScannerResult* token) - { - return token->type == Token::IdentifierToken || - token->type == Token::KeywordToken || - token->type == Token::BooleanLiteralToken || - token->type == Token::NullLiteralToken; - } + ArgumentVector parseArguments() + { + this->expect(LeftParenthesis); + ArgumentVector args; + if (!this->match(RightParenthesis)) { + while (true) { + Node* expr = this->match(PeriodPeriodPeriod) ? this->parseSpreadElement() : this->isolateCoverGrammar(&Parser::parseAssignmentExpression); + args.push_back(expr); + if (this->match(RightParenthesis)) { + break; + } + this->expectCommaSeparator(); + } + } + this->expect(RightParenthesis); - IdentifierNode* parseIdentifierName() - { - MetaNode node = this->createNode(); - ScannerResult* token = this->nextToken(); - if (!this->isIdentifierName(token)) { - this->throwUnexpectedToken(token); - } - return this->finalize(node, finishIdentifier(token, true)); - } + return args; + } - Node* parseNewExpression() - { - MetaNode node = this->createNode(); + bool isIdentifierName(ScannerResult* token) + { + return token->type == Token::IdentifierToken || token->type == Token::KeywordToken || token->type == Token::BooleanLiteralToken || token->type == Token::NullLiteralToken; + } - IdentifierNode* id = this->parseIdentifierName(); - // assert(id.name === 'new', 'New expression must start with `new`'); + IdentifierNode* parseIdentifierName() + { + MetaNode node = this->createNode(); + ScannerResult* token = this->nextToken(); + if (!this->isIdentifierName(token)) { + this->throwUnexpectedToken(token); + } + return this->finalize(node, finishIdentifier(token, true)); + } - Node* expr; - if (this->match(Period)) { - this->nextToken(); - if (this->lookahead->type == Token::IdentifierToken && this->context->inFunctionBody && this->lookahead->valueString == "target") { - // TODO - IdentifierNode* property = this->parseIdentifierName(); - RELEASE_ASSERT_NOT_REACHED(); - // expr = new Node.MetaProperty(id, property); - } else { - this->throwUnexpectedToken(this->lookahead); - } - } else { - Node* callee = this->isolateCoverGrammar(&Parser::parseLeftHandSideExpression); - ArgumentVector args; - if (this->match(LeftParenthesis)) - args = this->parseArguments(); - expr = new NewExpressionNode(callee, std::move(args)); - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } + Node* parseNewExpression() + { + MetaNode node = this->createNode(); - return this->finalize(node, expr); - } + IdentifierNode* id = this->parseIdentifierName(); + // assert(id.name === 'new', 'New expression must start with `new`'); - Node* parseLeftHandSideExpressionAllowCall() - { - ScannerResult* startToken = this->lookahead; - bool previousAllowIn = this->context->allowIn; - this->context->allowIn = true; + Node* expr; + if (this->match(Period)) { + this->nextToken(); + if (this->lookahead->type == Token::IdentifierToken && this->context->inFunctionBody && this->lookahead->valueString == "target") { + // TODO + IdentifierNode* property = this->parseIdentifierName(); + RELEASE_ASSERT_NOT_REACHED(); + // expr = new Node.MetaProperty(id, property); + } else { + this->throwUnexpectedToken(this->lookahead); + } + } else { + Node* callee = this->isolateCoverGrammar(&Parser::parseLeftHandSideExpression); + ArgumentVector args; + if (this->match(LeftParenthesis)) + args = this->parseArguments(); + expr = new NewExpressionNode(callee, std::move(args)); + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } - Node* expr; - if (this->matchKeyword(Super) && this->context->inFunctionBody) { - MetaNode node = this->createNode(); - this->nextToken(); - // TODO - RELEASE_ASSERT_NOT_REACHED(); - // expr = this->finalize(node, new Node.Super()); - if (!this->match(LeftParenthesis) && !this->match(Period) && !this->match(LeftSquareBracket)) { - this->throwUnexpectedToken(this->lookahead); - } - } else { - expr = this->inheritCoverGrammar(this->matchKeyword(New) ? &Parser::parseNewExpression : &Parser::parsePrimaryExpression); - } + return this->finalize(node, expr); + } - while (true) { - if (this->match(Period)) { - this->context->isBindingElement = false; - this->context->isAssignmentTarget = true; - this->expect(Period); - IdentifierNode* property = this->parseIdentifierName(); - expr = this->finalize(this->startNode(startToken), new MemberExpressionNode(expr, property, true)); + Node* parseLeftHandSideExpressionAllowCall() + { + ScannerResult* startToken = this->lookahead; + bool previousAllowIn = this->context->allowIn; + this->context->allowIn = true; - } else if (this->match(LeftParenthesis)) { - this->context->isBindingElement = false; - this->context->isAssignmentTarget = false; - ArgumentVector args = this->parseArguments(); - expr = this->finalize(this->startNode(startToken), new CallExpressionNode(expr, std::move(args))); + Node* expr; + if (this->matchKeyword(Super) && this->context->inFunctionBody) { + MetaNode node = this->createNode(); + this->nextToken(); + // TODO + RELEASE_ASSERT_NOT_REACHED(); + // expr = this->finalize(node, new Node.Super()); + if (!this->match(LeftParenthesis) && !this->match(Period) && !this->match(LeftSquareBracket)) { + this->throwUnexpectedToken(this->lookahead); + } + } else { + expr = this->inheritCoverGrammar(this->matchKeyword(New) ? &Parser::parseNewExpression : &Parser::parsePrimaryExpression); + } - } else if (this->match(LeftSquareBracket)) { - this->context->isBindingElement = false; - this->context->isAssignmentTarget = true; - this->expect(LeftSquareBracket); - Node* property = this->isolateCoverGrammar(&Parser::parseExpression); - this->expect(RightSquareBracket); - expr = this->finalize(this->startNode(startToken), new MemberExpressionNode(expr, property, false)); - - } else if (this->lookahead->type == Token::TemplateToken && this->lookahead->head) { - Node* quasi = this->parseTemplateLiteral(); - // expr = this->finalize(this->startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi)); - RELEASE_ASSERT_NOT_REACHED(); - } else { - break; - } - } - this->context->allowIn = previousAllowIn; + while (true) { + if (this->match(Period)) { + this->context->isBindingElement = false; + this->context->isAssignmentTarget = true; + this->expect(Period); + IdentifierNode* property = this->parseIdentifierName(); + expr = this->finalize(this->startNode(startToken), new MemberExpressionNode(expr, property, true)); - return expr; - } + } else if (this->match(LeftParenthesis)) { + this->context->isBindingElement = false; + this->context->isAssignmentTarget = false; + ArgumentVector args = this->parseArguments(); + expr = this->finalize(this->startNode(startToken), new CallExpressionNode(expr, std::move(args))); - Node* parseSuper() - { - MetaNode node = this->createNode(); + } else if (this->match(LeftSquareBracket)) { + this->context->isBindingElement = false; + this->context->isAssignmentTarget = true; + this->expect(LeftSquareBracket); + Node* property = this->isolateCoverGrammar(&Parser::parseExpression); + this->expect(RightSquareBracket); + expr = this->finalize(this->startNode(startToken), new MemberExpressionNode(expr, property, false)); + + } else if (this->lookahead->type == Token::TemplateToken && this->lookahead->head) { + Node* quasi = this->parseTemplateLiteral(); + // expr = this->finalize(this->startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi)); + RELEASE_ASSERT_NOT_REACHED(); + } else { + break; + } + } + this->context->allowIn = previousAllowIn; - this->expectKeyword(Super); - if (!this->match(LeftSquareBracket) && !this->match(Period)) { - this->throwUnexpectedToken(this->lookahead); - } + return expr; + } - // TODO - RELEASE_ASSERT_NOT_REACHED(); - // return this->finalize(node, new Node.Super()); - return nullptr; - } + Node* parseSuper() + { + MetaNode node = this->createNode(); - Node* parseLeftHandSideExpression() - { - // assert(this->context->allowIn, 'callee of new expression always allow in keyword.'); - ASSERT(this->context->allowIn); + this->expectKeyword(Super); + if (!this->match(LeftSquareBracket) && !this->match(Period)) { + this->throwUnexpectedToken(this->lookahead); + } - MetaNode node = this->startNode(this->lookahead); - Node* expr = (this->matchKeyword(Super) && this->context->inFunctionBody) ? this->parseSuper() : - this->inheritCoverGrammar(this->matchKeyword(New) ? &Parser::parseNewExpression : &Parser::parsePrimaryExpression); + // TODO + RELEASE_ASSERT_NOT_REACHED(); + // return this->finalize(node, new Node.Super()); + return nullptr; + } - while (true) { - if (this->match(LeftSquareBracket)) { - this->context->isBindingElement = false; - this->context->isAssignmentTarget = true; - this->expect(LeftSquareBracket); - Node* property = this->isolateCoverGrammar(&Parser::parseExpression); - this->expect(RightSquareBracket); - expr = this->finalize(node, new MemberExpressionNode(expr, property, false)); + Node* parseLeftHandSideExpression() + { + // assert(this->context->allowIn, 'callee of new expression always allow in keyword.'); + ASSERT(this->context->allowIn); - } else if (this->match(Period)) { - this->context->isBindingElement = false; - this->context->isAssignmentTarget = true; - this->expect(Period); - IdentifierNode* property = this->parseIdentifierName(); - expr = this->finalize(node, new MemberExpressionNode(expr, property, true)); - - } else if (this->lookahead->type == Token::TemplateToken && this->lookahead->head) { - Node* quasi = this->parseTemplateLiteral(); - // TODO - // expr = this->finalize(node, new Node.TaggedTemplateExpression(expr, quasi)); - RELEASE_ASSERT_NOT_REACHED(); - } else { - break; - } - } + MetaNode node = this->startNode(this->lookahead); + Node* expr = (this->matchKeyword(Super) && this->context->inFunctionBody) ? this->parseSuper() : this->inheritCoverGrammar(this->matchKeyword(New) ? &Parser::parseNewExpression : &Parser::parsePrimaryExpression); - return expr; - } + while (true) { + if (this->match(LeftSquareBracket)) { + this->context->isBindingElement = false; + this->context->isAssignmentTarget = true; + this->expect(LeftSquareBracket); + Node* property = this->isolateCoverGrammar(&Parser::parseExpression); + this->expect(RightSquareBracket); + expr = this->finalize(node, new MemberExpressionNode(expr, property, false)); - // ECMA-262 12.4 Update Expressions + } else if (this->match(Period)) { + this->context->isBindingElement = false; + this->context->isAssignmentTarget = true; + this->expect(Period); + IdentifierNode* property = this->parseIdentifierName(); + expr = this->finalize(node, new MemberExpressionNode(expr, property, true)); - Node* parseUpdateExpression() - { - Node* expr; - ScannerResult* startToken = this->lookahead; + } else if (this->lookahead->type == Token::TemplateToken && this->lookahead->head) { + Node* quasi = this->parseTemplateLiteral(); + // TODO + // expr = this->finalize(node, new Node.TaggedTemplateExpression(expr, quasi)); + RELEASE_ASSERT_NOT_REACHED(); + } else { + break; + } + } - if (this->match(PlusPlus) || this->match(MinusMinus)) { - bool isPlus = this->match(PlusPlus); - MetaNode node = this->startNode(startToken); - ScannerResult* token = this->nextToken(); - expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); - if (this->context->strict && expr->type() == Identifier && this->scanner->isRestrictedWord(((IdentifierNode*)expr)->name())) { - this->tolerateError(Messages::StrictLHSPrefix); - } - if (!this->context->isAssignmentTarget) { - this->tolerateError(Messages::InvalidLHSInAssignment); - } - bool prefix = true; + return expr; + } - if (isPlus) { - expr = this->finalize(node, new UpdateExpressionIncrementPrefixNode(expr)); - } else { - expr = this->finalize(node, new UpdateExpressionDecrementPrefixNode(expr)); - } - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } else { - expr = this->inheritCoverGrammar(&Parser::parseLeftHandSideExpressionAllowCall); - if (!this->hasLineTerminator && this->lookahead->type == Token::PunctuatorToken) { - if (this->match(PlusPlus) || this->match(MinusMinus)) { - bool isPlus = this->match(PlusPlus); - if (this->context->strict && expr->isIdentifier() && this->scanner->isRestrictedWord(((IdentifierNode*)expr)->name())) { - this->tolerateError(Messages::StrictLHSPostfix); - } - if (!this->context->isAssignmentTarget) { - this->tolerateError(Messages::InvalidLHSInAssignment); - } - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - this->nextToken(); - if (isPlus) { - expr = this->finalize(this->startNode(startToken), new UpdateExpressionIncrementPostfixNode(expr)); - } else { - expr = this->finalize(this->startNode(startToken), new UpdateExpressionDecrementPostfixNode(expr)); - } - } - } - } + // ECMA-262 12.4 Update Expressions - return expr; - } + Node* parseUpdateExpression() + { + Node* expr; + ScannerResult* startToken = this->lookahead; - // ECMA-262 12.5 Unary Operators + if (this->match(PlusPlus) || this->match(MinusMinus)) { + bool isPlus = this->match(PlusPlus); + MetaNode node = this->startNode(startToken); + ScannerResult* token = this->nextToken(); + expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); + if (this->context->strict && expr->type() == Identifier && this->scanner->isRestrictedWord(((IdentifierNode*)expr)->name())) { + this->tolerateError(Messages::StrictLHSPrefix); + } + if (!this->context->isAssignmentTarget) { + this->tolerateError(Messages::InvalidLHSInAssignment); + } + bool prefix = true; - Node* parseUnaryExpression() - { - Node* expr; + if (isPlus) { + expr = this->finalize(node, new UpdateExpressionIncrementPrefixNode(expr)); + } else { + expr = this->finalize(node, new UpdateExpressionDecrementPrefixNode(expr)); + } + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } else { + expr = this->inheritCoverGrammar(&Parser::parseLeftHandSideExpressionAllowCall); + if (!this->hasLineTerminator && this->lookahead->type == Token::PunctuatorToken) { + if (this->match(PlusPlus) || this->match(MinusMinus)) { + bool isPlus = this->match(PlusPlus); + if (this->context->strict && expr->isIdentifier() && this->scanner->isRestrictedWord(((IdentifierNode*)expr)->name())) { + this->tolerateError(Messages::StrictLHSPostfix); + } + if (!this->context->isAssignmentTarget) { + this->tolerateError(Messages::InvalidLHSInAssignment); + } + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + this->nextToken(); + if (isPlus) { + expr = this->finalize(this->startNode(startToken), new UpdateExpressionIncrementPostfixNode(expr)); + } else { + expr = this->finalize(this->startNode(startToken), new UpdateExpressionDecrementPostfixNode(expr)); + } + } + } + } - if (this->match(Plus)) { - MetaNode node = this->startNode(this->lookahead); - ScannerResult* token = this->nextToken(); - expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); - expr = this->finalize(node, new UnaryExpressionPlusNode(expr)); - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } else if (this->match(Minus)) { - MetaNode node = this->startNode(this->lookahead); - ScannerResult* token = this->nextToken(); - expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); - expr = this->finalize(node, new UnaryExpressionMinusNode(expr)); - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } else if (this->match(Wave)) { - MetaNode node = this->startNode(this->lookahead); - ScannerResult* token = this->nextToken(); - expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); - expr = this->finalize(node, new UnaryExpressionBitwiseNotNode(expr)); - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } else if (this->match(ExclamationMark)) { - MetaNode node = this->startNode(this->lookahead); - ScannerResult* token = this->nextToken(); - expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); - expr = this->finalize(node, new UnaryExpressionLogicalNotNode(expr)); - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } else if (this->matchKeyword(Delete)) { - MetaNode node = this->startNode(this->lookahead); - ScannerResult* token = this->nextToken(); - expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); - Node* exprOld = expr; - expr = this->finalize(node, new UnaryExpressionDeleteNode(expr)); - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; + return expr; + } - if (exprOld->isIdentifier()) { - this->tolerateError(Messages::StrictDelete); - } - } else if (this->matchKeyword(Void)) { - MetaNode node = this->startNode(this->lookahead); - ScannerResult* token = this->nextToken(); - expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); - expr = this->finalize(node, new UnaryExpressionVoidNode(expr)); - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } else if (this->matchKeyword(Typeof)) { - MetaNode node = this->startNode(this->lookahead); - ScannerResult* token = this->nextToken(); - expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); - expr = this->finalize(node, new UnaryExpressionTypeOfNode(expr)); - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } else { - expr = this->parseUpdateExpression(); - } + // ECMA-262 12.5 Unary Operators - return expr; - } + Node* parseUnaryExpression() + { + Node* expr; - Node* parseExponentiationExpression() - { - ScannerResult* startToken = this->lookahead; - Node* expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); - // TODO - /* + if (this->match(Plus)) { + MetaNode node = this->startNode(this->lookahead); + ScannerResult* token = this->nextToken(); + expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); + expr = this->finalize(node, new UnaryExpressionPlusNode(expr)); + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } else if (this->match(Minus)) { + MetaNode node = this->startNode(this->lookahead); + ScannerResult* token = this->nextToken(); + expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); + expr = this->finalize(node, new UnaryExpressionMinusNode(expr)); + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } else if (this->match(Wave)) { + MetaNode node = this->startNode(this->lookahead); + ScannerResult* token = this->nextToken(); + expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); + expr = this->finalize(node, new UnaryExpressionBitwiseNotNode(expr)); + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } else if (this->match(ExclamationMark)) { + MetaNode node = this->startNode(this->lookahead); + ScannerResult* token = this->nextToken(); + expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); + expr = this->finalize(node, new UnaryExpressionLogicalNotNode(expr)); + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } else if (this->matchKeyword(Delete)) { + MetaNode node = this->startNode(this->lookahead); + ScannerResult* token = this->nextToken(); + expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); + Node* exprOld = expr; + expr = this->finalize(node, new UnaryExpressionDeleteNode(expr)); + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + + if (exprOld->isIdentifier()) { + this->tolerateError(Messages::StrictDelete); + } + } else if (this->matchKeyword(Void)) { + MetaNode node = this->startNode(this->lookahead); + ScannerResult* token = this->nextToken(); + expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); + expr = this->finalize(node, new UnaryExpressionVoidNode(expr)); + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } else if (this->matchKeyword(Typeof)) { + MetaNode node = this->startNode(this->lookahead); + ScannerResult* token = this->nextToken(); + expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); + expr = this->finalize(node, new UnaryExpressionTypeOfNode(expr)); + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } else { + expr = this->parseUpdateExpression(); + } + + return expr; + } + + Node* parseExponentiationExpression() + { + ScannerResult* startToken = this->lookahead; + Node* expr = this->inheritCoverGrammar(&Parser::parseUnaryExpression); + // TODO + /* if (expr->type != Syntax.UnaryExpression && this->match('**')) { this->nextToken(); this->context->isAssignmentTarget = false; @@ -3827,270 +3820,270 @@ class Parser : public gc { expr = this->finalize(this->startNode(startToken), new Node.BinaryExpression('**', left, right)); }*/ - return expr; - } + return expr; + } - // ECMA-262 12.6 Exponentiation Operators - // ECMA-262 12.7 Multiplicative Operators - // ECMA-262 12.8 Additive Operators - // ECMA-262 12.9 Bitwise Shift Operators - // ECMA-262 12.10 Relational Operators - // ECMA-262 12.11 Equality Operators - // ECMA-262 12.12 Binary Bitwise Operators - // ECMA-262 12.13 Binary Logical Operators - - int binaryPrecedence(ScannerResult* token) - { - if (token->type == Token::PunctuatorToken) { - if (token->valuePunctuatorsKind == Substitution) { - return 0; - } else if (token->valuePunctuatorsKind == LogicalOr) { - return 1; - } else if (token->valuePunctuatorsKind == LogicalAnd) { - return 2; - } else if (token->valuePunctuatorsKind == BitwiseOr) { - return 3; - } else if (token->valuePunctuatorsKind == BitwiseXor) { - return 4; - } else if (token->valuePunctuatorsKind == BitwiseAnd) { - return 5; - } else if (token->valuePunctuatorsKind == Equal) { - return 6; - } else if (token->valuePunctuatorsKind == NotEqual) { - return 6; - } else if (token->valuePunctuatorsKind == StrictEqual) { - return 6; - } else if (token->valuePunctuatorsKind == NotStrictEqual) { - return 6; - } else if (token->valuePunctuatorsKind == RightInequality) { - return 7; - } else if (token->valuePunctuatorsKind == LeftInequality) { - return 7; - } else if (token->valuePunctuatorsKind == RightInequalityEqual) { - return 7; - } else if (token->valuePunctuatorsKind == LeftInequalityEqual) { - return 7; - } else if (token->valuePunctuatorsKind == LeftShift) { - return 8; - } else if (token->valuePunctuatorsKind == RightShift) { - return 8; - } else if (token->valuePunctuatorsKind == UnsignedRightShift) { - return 8; - } else if (token->valuePunctuatorsKind == Plus) { - return 9; - } else if (token->valuePunctuatorsKind == Minus) { - return 9; - } else if (token->valuePunctuatorsKind == Multiply) { - return 11; - } else if (token->valuePunctuatorsKind == Divide) { - return 11; - } else if (token->valuePunctuatorsKind == Mod) { - return 11; - } - return 0; - } else if (token->type == Token::KeywordToken) { - if (token->valueKeywordKind == In) { - return this->context->allowIn ? 7 : 0; - } else if (token->valueKeywordKind == InstanceofKeyword) { - return 7; - } - } else { - return 0; - } - return 0; - } + // ECMA-262 12.6 Exponentiation Operators + // ECMA-262 12.7 Multiplicative Operators + // ECMA-262 12.8 Additive Operators + // ECMA-262 12.9 Bitwise Shift Operators + // ECMA-262 12.10 Relational Operators + // ECMA-262 12.11 Equality Operators + // ECMA-262 12.12 Binary Bitwise Operators + // ECMA-262 12.13 Binary Logical Operators + + int binaryPrecedence(ScannerResult* token) + { + if (token->type == Token::PunctuatorToken) { + if (token->valuePunctuatorsKind == Substitution) { + return 0; + } else if (token->valuePunctuatorsKind == LogicalOr) { + return 1; + } else if (token->valuePunctuatorsKind == LogicalAnd) { + return 2; + } else if (token->valuePunctuatorsKind == BitwiseOr) { + return 3; + } else if (token->valuePunctuatorsKind == BitwiseXor) { + return 4; + } else if (token->valuePunctuatorsKind == BitwiseAnd) { + return 5; + } else if (token->valuePunctuatorsKind == Equal) { + return 6; + } else if (token->valuePunctuatorsKind == NotEqual) { + return 6; + } else if (token->valuePunctuatorsKind == StrictEqual) { + return 6; + } else if (token->valuePunctuatorsKind == NotStrictEqual) { + return 6; + } else if (token->valuePunctuatorsKind == RightInequality) { + return 7; + } else if (token->valuePunctuatorsKind == LeftInequality) { + return 7; + } else if (token->valuePunctuatorsKind == RightInequalityEqual) { + return 7; + } else if (token->valuePunctuatorsKind == LeftInequalityEqual) { + return 7; + } else if (token->valuePunctuatorsKind == LeftShift) { + return 8; + } else if (token->valuePunctuatorsKind == RightShift) { + return 8; + } else if (token->valuePunctuatorsKind == UnsignedRightShift) { + return 8; + } else if (token->valuePunctuatorsKind == Plus) { + return 9; + } else if (token->valuePunctuatorsKind == Minus) { + return 9; + } else if (token->valuePunctuatorsKind == Multiply) { + return 11; + } else if (token->valuePunctuatorsKind == Divide) { + return 11; + } else if (token->valuePunctuatorsKind == Mod) { + return 11; + } + return 0; + } else if (token->type == Token::KeywordToken) { + if (token->valueKeywordKind == In) { + return this->context->allowIn ? 7 : 0; + } else if (token->valueKeywordKind == InstanceofKeyword) { + return 7; + } + } else { + return 0; + } + return 0; + } - Node* parseBinaryExpression() - { - ScannerResult* startToken = this->lookahead; + Node* parseBinaryExpression() + { + ScannerResult* startToken = this->lookahead; - Node* expr = this->inheritCoverGrammar(&Parser::parseExponentiationExpression); + Node* expr = this->inheritCoverGrammar(&Parser::parseExponentiationExpression); - ScannerResult* token = this->lookahead; - int prec = this->binaryPrecedence(token); - if (prec > 0) { - this->nextToken(); + ScannerResult* token = this->lookahead; + int prec = this->binaryPrecedence(token); + if (prec > 0) { + this->nextToken(); - token->prec = prec; - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; + token->prec = prec; + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; - std::vector> markers; - markers.push_back(startToken); - markers.push_back(this->lookahead); - Node* left = expr; - Node* right = this->isolateCoverGrammar(&Parser::parseExponentiationExpression); + std::vector> markers; + markers.push_back(startToken); + markers.push_back(this->lookahead); + Node* left = expr; + Node* right = this->isolateCoverGrammar(&Parser::parseExponentiationExpression); - std::vector> stack; - stack.push_back(left); - stack.push_back(token); - stack.push_back(right); + std::vector> stack; + stack.push_back(left); + stack.push_back(token); + stack.push_back(right); - while (true) { - prec = this->binaryPrecedence(this->lookahead); - if (prec <= 0) { - break; - } + while (true) { + prec = this->binaryPrecedence(this->lookahead); + if (prec <= 0) { + break; + } - // Reduce: make a binary expression from the three topmost entries. - while ((stack.size() > 2) && (prec <= ((ScannerResult*)stack[stack.size() - 2])->prec)) { - right = (Node*)stack.back(); - stack.pop_back(); - PunctuatorsKind operator_ = ((ScannerResult*)stack.back())->valuePunctuatorsKind; - stack.pop_back(); - left = (Node*)stack.back(); - stack.pop_back(); - markers.pop_back(); - MetaNode node = this->startNode(markers.back()); - stack.push_back(this->finalize(node, finishBinaryExpression(left, right, operator_))); - } + // Reduce: make a binary expression from the three topmost entries. + while ((stack.size() > 2) && (prec <= ((ScannerResult*)stack[stack.size() - 2])->prec)) { + right = (Node*)stack.back(); + stack.pop_back(); + PunctuatorsKind operator_ = ((ScannerResult*)stack.back())->valuePunctuatorsKind; + stack.pop_back(); + left = (Node*)stack.back(); + stack.pop_back(); + markers.pop_back(); + MetaNode node = this->startNode(markers.back()); + stack.push_back(this->finalize(node, finishBinaryExpression(left, right, operator_))); + } - // Shift. - token = this->nextToken(); - token->prec = prec; - stack.push_back(token); - markers.push_back(this->lookahead); - stack.push_back(this->isolateCoverGrammar(&Parser::parseExponentiationExpression)); - } + // Shift. + token = this->nextToken(); + token->prec = prec; + stack.push_back(token); + markers.push_back(this->lookahead); + stack.push_back(this->isolateCoverGrammar(&Parser::parseExponentiationExpression)); + } - // Final reduce to clean-up the stack. - size_t i = stack.size() - 1; - expr = (Node*)stack[i]; - markers.pop_back(); - while (i > 1) { - MetaNode node = this->startNode(markers.back()); - expr = this->finalize(node, finishBinaryExpression((Node*)stack[i - 2], expr, ((ScannerResult*)stack[i - 1])->valuePunctuatorsKind)); - i -= 2; - } - } + // Final reduce to clean-up the stack. + size_t i = stack.size() - 1; + expr = (Node*)stack[i]; + markers.pop_back(); + while (i > 1) { + MetaNode node = this->startNode(markers.back()); + expr = this->finalize(node, finishBinaryExpression((Node*)stack[i - 2], expr, ((ScannerResult*)stack[i - 1])->valuePunctuatorsKind)); + i -= 2; + } + } - return expr; - } + return expr; + } - Node* finishBinaryExpression(Node* left, Node* right, PunctuatorsKind oper) - { - // Additive Operators - Node* nd; - if (oper == Plus) - nd = new BinaryExpressionPlusNode(left, right); - else if (oper == Minus) - nd = new BinaryExpressionMinusNode(left, right); - - // Bitwise Shift Operators - else if (oper == LeftShift) - nd = new BinaryExpressionLeftShiftNode(left, right); - else if (oper == RightShift) - nd = new BinaryExpressionSignedRightShiftNode(left, right); - else if (oper == UnsignedRightShift) - nd = new BinaryExpressionUnsignedRightShiftNode(left, right); - - // Multiplicative Operators - else if (oper == Multiply) - nd = new BinaryExpressionMultiplyNode(left, right); - else if (oper == Divide) - nd = new BinaryExpressionDivisionNode(left, right); - else if (oper == Mod) - nd = new BinaryExpressionModNode(left, right); - - // Relational Operators - else if (oper == LeftInequality) - nd = new BinaryExpressionLessThanNode(left, right); - else if (oper == RightInequality) - nd = new BinaryExpressionGreaterThanNode(left, right); - else if (oper == LeftInequalityEqual) - nd = new BinaryExpressionLessThanOrEqualNode(left, right); - else if (oper == RightInequalityEqual) - nd = new BinaryExpressionGreaterThanOrEqualNode(left, right); - - // Equality Operators - else if (oper == Equal) - nd = new BinaryExpressionEqualNode(left, right); - else if (oper == NotEqual) - nd = new BinaryExpressionNotEqualNode(left, right); - else if (oper == StrictEqual) - nd = new BinaryExpressionStrictEqualNode(left, right); - else if (oper == NotStrictEqual) - nd = new BinaryExpressionNotStrictEqualNode(left, right); - - // Binary Bitwise Operator - else if (oper == BitwiseAnd) - nd = new BinaryExpressionBitwiseAndNode(left, right); - else if (oper == BitwiseXor) - nd = new BinaryExpressionBitwiseXorNode(left, right); - else if (oper == BitwiseOr) - nd = new BinaryExpressionBitwiseOrNode(left, right); - else if (oper == LogicalOr) - nd = new BinaryExpressionLogicalOrNode(left, right); - else if (oper == LogicalAnd) - nd = new BinaryExpressionLogicalAndNode(left, right); - else if (oper == InPunctuator) - nd = new BinaryExpressionInNode(left, right); - else if (oper == InstanceOfPunctuator) - nd = new BinaryExpressionInstanceOfNode(left, right); - // TODO - else - RELEASE_ASSERT_NOT_REACHED(); - - return nd; - } + Node* finishBinaryExpression(Node* left, Node* right, PunctuatorsKind oper) + { + // Additive Operators + Node* nd; + if (oper == Plus) + nd = new BinaryExpressionPlusNode(left, right); + else if (oper == Minus) + nd = new BinaryExpressionMinusNode(left, right); + + // Bitwise Shift Operators + else if (oper == LeftShift) + nd = new BinaryExpressionLeftShiftNode(left, right); + else if (oper == RightShift) + nd = new BinaryExpressionSignedRightShiftNode(left, right); + else if (oper == UnsignedRightShift) + nd = new BinaryExpressionUnsignedRightShiftNode(left, right); + + // Multiplicative Operators + else if (oper == Multiply) + nd = new BinaryExpressionMultiplyNode(left, right); + else if (oper == Divide) + nd = new BinaryExpressionDivisionNode(left, right); + else if (oper == Mod) + nd = new BinaryExpressionModNode(left, right); + + // Relational Operators + else if (oper == LeftInequality) + nd = new BinaryExpressionLessThanNode(left, right); + else if (oper == RightInequality) + nd = new BinaryExpressionGreaterThanNode(left, right); + else if (oper == LeftInequalityEqual) + nd = new BinaryExpressionLessThanOrEqualNode(left, right); + else if (oper == RightInequalityEqual) + nd = new BinaryExpressionGreaterThanOrEqualNode(left, right); + + // Equality Operators + else if (oper == Equal) + nd = new BinaryExpressionEqualNode(left, right); + else if (oper == NotEqual) + nd = new BinaryExpressionNotEqualNode(left, right); + else if (oper == StrictEqual) + nd = new BinaryExpressionStrictEqualNode(left, right); + else if (oper == NotStrictEqual) + nd = new BinaryExpressionNotStrictEqualNode(left, right); + + // Binary Bitwise Operator + else if (oper == BitwiseAnd) + nd = new BinaryExpressionBitwiseAndNode(left, right); + else if (oper == BitwiseXor) + nd = new BinaryExpressionBitwiseXorNode(left, right); + else if (oper == BitwiseOr) + nd = new BinaryExpressionBitwiseOrNode(left, right); + else if (oper == LogicalOr) + nd = new BinaryExpressionLogicalOrNode(left, right); + else if (oper == LogicalAnd) + nd = new BinaryExpressionLogicalAndNode(left, right); + else if (oper == InPunctuator) + nd = new BinaryExpressionInNode(left, right); + else if (oper == InstanceOfPunctuator) + nd = new BinaryExpressionInstanceOfNode(left, right); + // TODO + else + RELEASE_ASSERT_NOT_REACHED(); - // ECMA-262 12.14 Conditional Operator + return nd; + } - Node* parseConditionalExpression() - { - ScannerResult* startToken = this->lookahead; + // ECMA-262 12.14 Conditional Operator - Node* expr = this->inheritCoverGrammar(&Parser::parseBinaryExpression); - if (this->match(GuessMark)) { - this->nextToken(); + Node* parseConditionalExpression() + { + ScannerResult* startToken = this->lookahead; - bool previousAllowIn = this->context->allowIn; - this->context->allowIn = true; - Node* consequent = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); - this->context->allowIn = previousAllowIn; + Node* expr = this->inheritCoverGrammar(&Parser::parseBinaryExpression); + if (this->match(GuessMark)) { + this->nextToken(); - this->expect(Colon); - Node* alternate = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); + bool previousAllowIn = this->context->allowIn; + this->context->allowIn = true; + Node* consequent = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); + this->context->allowIn = previousAllowIn; - expr = this->finalize(this->startNode(startToken), new ConditionalExpressionNode(expr, consequent, alternate)); - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } + this->expect(Colon); + Node* alternate = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); - return expr; - } + expr = this->finalize(this->startNode(startToken), new ConditionalExpressionNode(expr, consequent, alternate)); + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } - // ECMA-262 12.15 Assignment Operators + return expr; + } - void checkPatternParam(ParseParameterOptions options, Node* param) - { - switch (param->type()) { - case Identifier: - this->validateParam(options, nodeExtraInfo.find(((IdentifierNode*)param))->second, ((IdentifierNode*)param)->name()); - break; - case RestElement: - this->checkPatternParam(options, ((RestElementNode*)param)->argument()); - break; - // case AssignmentPattern: - case AssignmentExpression: - case AssignmentExpressionBitwiseAnd: - case AssignmentExpressionBitwiseOr: - case AssignmentExpressionBitwiseXor: - case AssignmentExpressionDivision: - case AssignmentExpressionLeftShift: - case AssignmentExpressionMinus: - case AssignmentExpressionMod: - case AssignmentExpressionMultiply: - case AssignmentExpressionPlus: - case AssignmentExpressionSignedRightShift: - case AssignmentExpressionUnsignedRightShift: - case AssignmentExpressionSimple: - this->checkPatternParam(options, ((AssignmentExpressionSimpleNode*)param)->left()); - break; - default: - RELEASE_ASSERT_NOT_REACHED(); - // TODO - /* + // ECMA-262 12.15 Assignment Operators + + void checkPatternParam(ParseParameterOptions options, Node* param) + { + switch (param->type()) { + case Identifier: + this->validateParam(options, nodeExtraInfo.find(((IdentifierNode*)param))->second, ((IdentifierNode*)param)->name()); + break; + case RestElement: + this->checkPatternParam(options, ((RestElementNode*)param)->argument()); + break; + // case AssignmentPattern: + case AssignmentExpression: + case AssignmentExpressionBitwiseAnd: + case AssignmentExpressionBitwiseOr: + case AssignmentExpressionBitwiseXor: + case AssignmentExpressionDivision: + case AssignmentExpressionLeftShift: + case AssignmentExpressionMinus: + case AssignmentExpressionMod: + case AssignmentExpressionMultiply: + case AssignmentExpressionPlus: + case AssignmentExpressionSignedRightShift: + case AssignmentExpressionUnsignedRightShift: + case AssignmentExpressionSimple: + this->checkPatternParam(options, ((AssignmentExpressionSimpleNode*)param)->left()); + break; + default: + RELEASE_ASSERT_NOT_REACHED(); + // TODO + /* case Syntax.ArrayPattern: for (let i = 0; i < param.elements.length; i++) { if (param.elements[i] !== null) { @@ -4108,9 +4101,9 @@ class Parser : public gc { } break; */ - } - } -/* + } + } + /* reinterpretAsCoverFormalsList(expr) { let params = [expr]; let options; @@ -4168,17 +4161,17 @@ class Parser : public gc { }; } */ - Node* parseAssignmentExpression() - { - Node* expr; + Node* parseAssignmentExpression() + { + Node* expr; - if (!this->context->allowYield && this->matchKeyword(Yield)) { - expr = this->parseYieldExpression(); - } else { - ScannerResult* startToken = this->lookahead; - ScannerResult* token = startToken; - expr = this->parseConditionalExpression(); - /* + if (!this->context->allowYield && this->matchKeyword(Yield)) { + expr = this->parseYieldExpression(); + } else { + ScannerResult* startToken = this->lookahead; + ScannerResult* token = startToken; + expr = this->parseConditionalExpression(); + /* if (expr->type() == ArrowParameterPlaceHolder || this->match('=>')) { RELEASE_ASSERT_NOT_REACHED(); // ECMA-262 14.2 Arrow Function Definitions @@ -4243,111 +4236,111 @@ class Parser : public gc { this->context->firstCoverInitializedNameError = null; } }*/ - if (this->matchAssign()) { - if (!this->context->isAssignmentTarget) { - this->tolerateError(Messages::InvalidLHSInAssignment); - } + if (this->matchAssign()) { + if (!this->context->isAssignmentTarget) { + this->tolerateError(Messages::InvalidLHSInAssignment); + } - if (this->context->strict && expr->type() == Identifier) { - IdentifierNode* id = (IdentifierNode*)(expr); - if (this->scanner->isRestrictedWord(id->name())) { - this->tolerateUnexpectedToken(token, Messages::StrictLHSAssignment); - } - if (this->scanner->isStrictModeReservedWord(id->name())) { - this->tolerateUnexpectedToken(token, Messages::StrictReservedWord); - } - } + if (this->context->strict && expr->type() == Identifier) { + IdentifierNode* id = (IdentifierNode*)(expr); + if (this->scanner->isRestrictedWord(id->name())) { + this->tolerateUnexpectedToken(token, Messages::StrictLHSAssignment); + } + if (this->scanner->isStrictModeReservedWord(id->name())) { + this->tolerateUnexpectedToken(token, Messages::StrictReservedWord); + } + } - if (!this->match(Substitution)) { - this->context->isAssignmentTarget = false; - this->context->isBindingElement = false; - } else { - // TODO - // this->reinterpretExpressionAsPattern(expr); - } + if (!this->match(Substitution)) { + this->context->isAssignmentTarget = false; + this->context->isBindingElement = false; + } else { + // TODO + // this->reinterpretExpressionAsPattern(expr); + } - token = this->nextToken(); - Node* right = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); - // Node* expr; - if (token->valuePunctuatorsKind == Substitution) { - expr = new AssignmentExpressionSimpleNode(expr, right); - } else if (token->valuePunctuatorsKind == PlusEqual) { - expr = new AssignmentExpressionPlusNode(expr, right); - } else if (token->valuePunctuatorsKind == MinusEqual) { - expr = new AssignmentExpressionMinusNode(expr, right); - } else if (token->valuePunctuatorsKind == MultiplyEqual) { - expr = new AssignmentExpressionMultiplyNode(expr, right); - } else if (token->valuePunctuatorsKind == DivideEqual) { - expr = new AssignmentExpressionDivisionNode(expr, right); - } else if (token->valuePunctuatorsKind == ModEqual) { - expr = new AssignmentExpressionModNode(expr, right); - } else if (token->valuePunctuatorsKind == LeftShiftEqual) { - expr = new AssignmentExpressionLeftShiftNode(expr, right); - } else if (token->valuePunctuatorsKind == RightShiftEqual) { - expr = new AssignmentExpressionSignedRightShiftNode(expr, right); - } else if (token->valuePunctuatorsKind == UnsignedRightShiftEqual) { - expr = new AssignmentExpressionUnsignedShiftNode(expr, right); - } else if (token->valuePunctuatorsKind == BitwiseXorEqual) { - expr = new AssignmentExpressionBitwiseXorNode(expr, right); - } else if (token->valuePunctuatorsKind == BitwiseAndEqual) { - expr = new AssignmentExpressionBitwiseAndNode(expr, right); - } else if (token->valuePunctuatorsKind == BitwiseOrEqual) { - expr = new AssignmentExpressionBitwiseOrNode(expr, right); - } else { - RELEASE_ASSERT_NOT_REACHED(); - } - expr = this->finalize(this->startNode(startToken), expr); - this->context->firstCoverInitializedNameError = nullptr; - } - } + token = this->nextToken(); + Node* right = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); + // Node* expr; + if (token->valuePunctuatorsKind == Substitution) { + expr = new AssignmentExpressionSimpleNode(expr, right); + } else if (token->valuePunctuatorsKind == PlusEqual) { + expr = new AssignmentExpressionPlusNode(expr, right); + } else if (token->valuePunctuatorsKind == MinusEqual) { + expr = new AssignmentExpressionMinusNode(expr, right); + } else if (token->valuePunctuatorsKind == MultiplyEqual) { + expr = new AssignmentExpressionMultiplyNode(expr, right); + } else if (token->valuePunctuatorsKind == DivideEqual) { + expr = new AssignmentExpressionDivisionNode(expr, right); + } else if (token->valuePunctuatorsKind == ModEqual) { + expr = new AssignmentExpressionModNode(expr, right); + } else if (token->valuePunctuatorsKind == LeftShiftEqual) { + expr = new AssignmentExpressionLeftShiftNode(expr, right); + } else if (token->valuePunctuatorsKind == RightShiftEqual) { + expr = new AssignmentExpressionSignedRightShiftNode(expr, right); + } else if (token->valuePunctuatorsKind == UnsignedRightShiftEqual) { + expr = new AssignmentExpressionUnsignedShiftNode(expr, right); + } else if (token->valuePunctuatorsKind == BitwiseXorEqual) { + expr = new AssignmentExpressionBitwiseXorNode(expr, right); + } else if (token->valuePunctuatorsKind == BitwiseAndEqual) { + expr = new AssignmentExpressionBitwiseAndNode(expr, right); + } else if (token->valuePunctuatorsKind == BitwiseOrEqual) { + expr = new AssignmentExpressionBitwiseOrNode(expr, right); + } else { + RELEASE_ASSERT_NOT_REACHED(); + } + expr = this->finalize(this->startNode(startToken), expr); + this->context->firstCoverInitializedNameError = nullptr; + } + } - return expr; - } + return expr; + } - // ECMA-262 12.16 Comma Operator + // ECMA-262 12.16 Comma Operator - Node* parseExpression() - { - ScannerResult* startToken = this->lookahead; - Node* expr = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); + Node* parseExpression() + { + ScannerResult* startToken = this->lookahead; + Node* expr = this->isolateCoverGrammar(&Parser::parseAssignmentExpression); - if (this->match(Comma)) { - ExpressionNodeVector expressions; - expressions.push_back(expr); - while (this->startMarker.index < this->scanner->length) { - if (!this->match(Comma)) { - break; - } - this->nextToken(); - expressions.push_back(this->isolateCoverGrammar(&Parser::parseAssignmentExpression)); - } + if (this->match(Comma)) { + ExpressionNodeVector expressions; + expressions.push_back(expr); + while (this->startMarker.index < this->scanner->length) { + if (!this->match(Comma)) { + break; + } + this->nextToken(); + expressions.push_back(this->isolateCoverGrammar(&Parser::parseAssignmentExpression)); + } - expr = this->finalize(this->startNode(startToken), new SequenceExpressionNode(std::move(expressions))); - } + expr = this->finalize(this->startNode(startToken), new SequenceExpressionNode(std::move(expressions))); + } - return expr; - } + return expr; + } - // ECMA-262 13.2 Block + // ECMA-262 13.2 Block - StatementNode* parseStatementListItem() - { - StatementNode* statement = nullptr; - this->context->isAssignmentTarget = true; - this->context->isBindingElement = true; - if (this->lookahead->type == KeywordToken) { - switch (this->lookahead->valueKeywordKind) { - case Function: - statement = this->parseFunctionDeclaration(); - break; - default: - statement = this->parseStatement(); - break; - } - } else { - statement = this->parseStatement(); - } - /* + StatementNode* parseStatementListItem() + { + StatementNode* statement = nullptr; + this->context->isAssignmentTarget = true; + this->context->isBindingElement = true; + if (this->lookahead->type == KeywordToken) { + switch (this->lookahead->valueKeywordKind) { + case Function: + statement = this->parseFunctionDeclaration(); + break; + default: + statement = this->parseStatement(); + break; + } + } else { + statement = this->parseStatement(); + } + /* if (this->lookahead.type === Token.Keyword) { switch (this->lookahead.value) { case 'export': @@ -4382,26 +4375,26 @@ class Parser : public gc { statement = this->parseStatement(); }*/ - return statement; - } + return statement; + } - BlockStatementNode* parseBlock() - { - MetaNode node = this->createNode(); + BlockStatementNode* parseBlock() + { + MetaNode node = this->createNode(); - this->expect(LeftBrace); - StatementNodeVector block; - while (true) { - if (this->match(RightBrace)) { - break; - } - block.push_back(this->parseStatementListItem()); - } - this->expect(RightBrace); + this->expect(LeftBrace); + StatementNodeVector block; + while (true) { + if (this->match(RightBrace)) { + break; + } + block.push_back(this->parseStatementListItem()); + } + this->expect(RightBrace); - return this->finalize(node, new BlockStatementNode(std::move(block))); - } -/* + return this->finalize(node, new BlockStatementNode(std::move(block))); + } + /* // ECMA-262 13.3.1 Let and Const Declarations parseLexicalBinding(kind: string, options): Node.VariableDeclarator { @@ -4596,7 +4589,7 @@ class Parser : public gc { } */ - // ECMA-262 13.3.2 Variable Statement + // ECMA-262 13.3.2 Variable Statement IdentifierNode* parseVariableIdentifier(String* kind = String::emptyString) { MetaNode node = this->createNode(); @@ -4605,7 +4598,8 @@ class Parser : public gc { if (token->type == Token::KeywordToken && token->valueKeywordKind == Yield) { if (this->context->strict) { this->tolerateUnexpectedToken(token, Messages::StrictReservedWord); - }if (!this->context->allowYield) { + } + if (!this->context->allowYield) { this->throwUnexpectedToken(token); } } else if (token->type != Token::IdentifierToken) { @@ -4680,7 +4674,7 @@ class Parser : public gc { VariableDeclaratorVector declarations = this->parseVariableDeclarationList(opt); this->consumeSemicolon(); - return this->finalize(node, new VariableDeclarationNode(std::move(declarations)/*, 'var'*/)); + return this->finalize(node, new VariableDeclarationNode(std::move(declarations) /*, 'var'*/)); } // ECMA-262 13.4 Empty Statement @@ -4817,20 +4811,20 @@ class Parser : public gc { if (decl->init() && (decl->id()->type() == ArrayExpression || decl->id()->type() == ObjectExpression || this->context->strict)) { this->tolerateError(Messages::ForInOfLoopInitializer, new ASCIIString("for-in")); } - init = this->finalize(metaInit, new VariableDeclarationNode(std::move(declarations)/*, 'var'*/)); + init = this->finalize(metaInit, new VariableDeclarationNode(std::move(declarations) /*, 'var'*/)); this->nextToken(); left = init; right = this->parseExpression(); init = nullptr; } else if (declarations.size() == 1 && declarations[0]->init() == nullptr && this->matchContextualKeyword(Of)) { - init = this->finalize(metaInit, new VariableDeclarationNode(std::move(declarations)/*, 'var'*/)); + init = this->finalize(metaInit, new VariableDeclarationNode(std::move(declarations) /*, 'var'*/)); this->nextToken(); left = init; right = this->parseAssignmentExpression(); init = nullptr; forIn = false; } else { - init = this->finalize(metaInit, new VariableDeclarationNode(std::move(declarations)/*, 'var'*/)); + init = this->finalize(metaInit, new VariableDeclarationNode(std::move(declarations) /*, 'var'*/)); this->expect(SemiColon); } } else if (this->matchKeyword(Const) || this->matchKeyword(Let)) { @@ -4951,7 +4945,7 @@ class Parser : public gc { // return this->finalize(node, new Node.ForOfStatement(left, right, body)); } } -/* + /* return (typeof left === 'undefined') ? this->finalize(node, new Node.ForStatement(init, test, update, body)) : forIn ? this->finalize(node, new Node.ForInStatement(left, right, body)) : @@ -4962,7 +4956,7 @@ class Parser : public gc { void removeLabel(String* label) { - for (size_t i = 0; i < this->context->labelSet.size(); i ++) { + for (size_t i = 0; i < this->context->labelSet.size(); i++) { if (this->context->labelSet[i].first->equals(label)) { this->context->labelSet.erase(this->context->labelSet.begin() + i); return; @@ -4973,7 +4967,7 @@ class Parser : public gc { bool hasLabel(String* label) { - for (size_t i = 0; i < this->context->labelSet.size(); i ++) { + for (size_t i = 0; i < this->context->labelSet.size(); i++) { if (this->context->labelSet[i].first->equals(label)) { return true; } @@ -5021,7 +5015,6 @@ class Parser : public gc { if (!hasLabel(label->name().string())) { this->throwError(Messages::UnknownLabel, label->name().string()); } - } this->consumeSemicolon(); @@ -5046,8 +5039,7 @@ class Parser : public gc { MetaNode node = this->createNode(); this->expectKeyword(Return); - bool hasArgument = !this->match(SemiColon) && !this->match(RightBrace) && - !this->hasLineTerminator && this->lookahead->type != EOFToken; + bool hasArgument = !this->match(SemiColon) && !this->match(RightBrace) && !this->hasLineTerminator && this->lookahead->type != EOFToken; Node* argument = nullptr; if (hasArgument) { argument = this->parseExpression(); @@ -5211,10 +5203,9 @@ class Parser : public gc { Node* param = this->parsePattern(params); std::vector> paramMap; - for (size_t i = 0; i < params.size(); i ++) { - + for (size_t i = 0; i < params.size(); i++) { bool has = false; - for (size_t j = 0; j < paramMap.size(); j ++) { + for (size_t j = 0; j < paramMap.size(); j++) { if (paramMap[j]->equals(¶ms[i]->valueString)) { has = true; } @@ -5281,85 +5272,84 @@ class Parser : public gc { { StatementNode* statement = nullptr; switch (this->lookahead->type) { - case Token::BooleanLiteralToken: - case Token::NullLiteralToken: - case Token::NumericLiteralToken: - case Token::StringLiteralToken: - case Token::TemplateToken: - case Token::RegularExpressionToken: + case Token::BooleanLiteralToken: + case Token::NullLiteralToken: + case Token::NumericLiteralToken: + case Token::StringLiteralToken: + case Token::TemplateToken: + case Token::RegularExpressionToken: + statement = this->parseExpressionStatement(); + break; + + case Token::PunctuatorToken: { + PunctuatorsKind value = this->lookahead->valuePunctuatorsKind; + if (value == LeftBrace) { + statement = this->parseBlock(); + } else if (value == LeftParenthesis) { statement = this->parseExpressionStatement(); - break; + } else if (value == SemiColon) { + statement = this->parseEmptyStatement(); + } else { + statement = this->parseExpressionStatement(); + } + break; + } + case Token::IdentifierToken: + statement = asStatementNode(this->parseLabelledStatement()); + break; - case Token::PunctuatorToken: - { - PunctuatorsKind value = this->lookahead->valuePunctuatorsKind; - if (value == LeftBrace) { - statement = this->parseBlock(); - } else if (value == LeftParenthesis) { - statement = this->parseExpressionStatement(); - } else if (value == SemiColon) { - statement = this->parseEmptyStatement(); - } else { - statement = this->parseExpressionStatement(); - } + case Token::KeywordToken: + switch (this->lookahead->valueKeywordKind) { + case Break: + statement = asStatementNode(this->parseBreakStatement()); break; - } - case Token::IdentifierToken: - statement = asStatementNode(this->parseLabelledStatement()); + case Continue: + statement = asStatementNode(this->parseContinueStatement()); break; - - case Token::KeywordToken: - switch (this->lookahead->valueKeywordKind) { - case Break: - statement = asStatementNode(this->parseBreakStatement()); - break; - case Continue: - statement = asStatementNode(this->parseContinueStatement()); - break; - case Debugger: - statement = asStatementNode(this->parseDebuggerStatement()); - break; - case Do: - statement = asStatementNode(this->parseDoWhileStatement()); - break; - case For: - statement = asStatementNode(this->parseForStatement()); - break; - case Function: - statement = asStatementNode(this->parseFunctionDeclaration()); - break; - case If: - statement = asStatementNode(this->parseIfStatement()); - break; - case Return: - statement = asStatementNode(this->parseReturnStatement()); - break; - case Switch: - statement = asStatementNode(this->parseSwitchStatement()); - break; - case Throw: - statement = asStatementNode(this->parseThrowStatement()); - break; - case Try: - statement = asStatementNode(this->parseTryStatement()); - break; - case Var: - statement = asStatementNode(this->parseVariableStatement()); - break; - case While: - statement = asStatementNode(this->parseWhileStatement()); - break; - case With: - statement = asStatementNode(this->parseWithStatement()); - break; - default: - statement = asStatementNode(this->parseExpressionStatement()); - break; - } + case Debugger: + statement = asStatementNode(this->parseDebuggerStatement()); + break; + case Do: + statement = asStatementNode(this->parseDoWhileStatement()); + break; + case For: + statement = asStatementNode(this->parseForStatement()); + break; + case Function: + statement = asStatementNode(this->parseFunctionDeclaration()); + break; + case If: + statement = asStatementNode(this->parseIfStatement()); + break; + case Return: + statement = asStatementNode(this->parseReturnStatement()); + break; + case Switch: + statement = asStatementNode(this->parseSwitchStatement()); + break; + case Throw: + statement = asStatementNode(this->parseThrowStatement()); + break; + case Try: + statement = asStatementNode(this->parseTryStatement()); + break; + case Var: + statement = asStatementNode(this->parseVariableStatement()); + break; + case While: + statement = asStatementNode(this->parseWhileStatement()); + break; + case With: + statement = asStatementNode(this->parseWithStatement()); break; - default: - this->throwUnexpectedToken(this->lookahead); + statement = asStatementNode(this->parseExpressionStatement()); + break; + } + break; + + default: + this->throwUnexpectedToken(this->lookahead); } return statement; @@ -5866,7 +5856,7 @@ class Parser : public gc { scopeContexts.back()->m_locEnd.line = endNode.line; scopeContexts.back()->m_locEnd.column = endNode.column; scopeContexts.back()->m_locEnd.index = endNode.index; - return this->finalize(node, new ProgramNode(std::move(body), scopeContexts.back()/*, this->sourceType*/)); + return this->finalize(node, new ProgramNode(std::move(body), scopeContexts.back() /*, this->sourceType*/)); } // ECMA-262 15.2.2 Imports @@ -6103,7 +6093,6 @@ class Parser : public gc { }; - ProgramNode* parseProgram(::Escargot::Context* ctx, StringView source, ParserASTNodeHandler handler) { Parser parser(ctx, source, handler); @@ -6117,8 +6106,5 @@ Node* parseSingleFunction(::Escargot::Context* ctx, CodeBlock* codeBlock) parser.scopeContexts.pushBack(new ASTScopeContext(codeBlock->isStrict(), nullptr)); return parser.parseFunctionSourceElements(); } - - } - } diff --git a/src/parser/esprima_cpp/esprima.h b/src/parser/esprima_cpp/esprima.h index 7d924b2a3..6aa23aca8 100644 --- a/src/parser/esprima_cpp/esprima.h +++ b/src/parser/esprima_cpp/esprima.h @@ -1,9 +1,9 @@ #ifndef __EscargotEsprima__ #define __EscargotEsprima__ -#include "runtime/String.h" -#include "runtime/Context.h" #include "parser/ast/Node.h" +#include "runtime/Context.h" +#include "runtime/String.h" namespace Escargot { @@ -12,7 +12,7 @@ class CodeBlock; namespace esprima { -typedef std::function ParserASTNodeHandler; +typedef std::function ParserASTNodeHandler; struct Error : public gc { String* name; @@ -33,10 +33,7 @@ struct Error : public gc { ProgramNode* parseProgram(::Escargot::Context* ctx, StringView source, ParserASTNodeHandler astHandler); Node* parseSingleFunction(::Escargot::Context* ctx, CodeBlock* codeBlock); - } - - } #endif diff --git a/src/runtime/AtomicString.cpp b/src/runtime/AtomicString.cpp index 048a47a72..7b0c3c0f0 100644 --- a/src/runtime/AtomicString.cpp +++ b/src/runtime/AtomicString.cpp @@ -77,7 +77,7 @@ void AtomicString::init(AtomicStringMap* ec, const char16_t* src, size_t len) if (isAllASCII(src, len)) { char* abuf = ALLOCA(len, char, ec); - for (unsigned i = 0 ; i < len ; i ++) { + for (unsigned i = 0; i < len; i++) { abuf[i] = src[i]; } init(ec, abuf, len); @@ -96,5 +96,4 @@ void AtomicString::init(AtomicStringMap* ec, const char16_t* src, size_t len) m_string = iter->second; } } - } diff --git a/src/runtime/AtomicString.h b/src/runtime/AtomicString.h index a90d38b05..750d49345 100644 --- a/src/runtime/AtomicString.h +++ b/src/runtime/AtomicString.h @@ -1,15 +1,16 @@ #ifndef __EscargotAtomicString__ #define __EscargotAtomicString__ -#include "runtime/String.h" #include "runtime/ExecutionState.h" +#include "runtime/String.h" #include "util/Vector.h" namespace Escargot { -typedef std::unordered_map, String*, - std::hash >, std::equal_to >, - gc_allocator, String*> > > AtomicStringMap; +typedef std::unordered_map, String*, + std::hash >, std::equal_to >, + gc_allocator, String*> > > + AtomicStringMap; class AtomicString { friend class StaticStrings; @@ -18,6 +19,7 @@ class AtomicString { { m_string = str; } + public: inline AtomicString() { @@ -35,7 +37,6 @@ class AtomicString { AtomicString(ExecutionState& ec, const char* src) : AtomicString(ec, src, strlen(src)) { - } AtomicString(Context* c, const char16_t* src, size_t len); AtomicString(Context* c, const char* src, size_t len); @@ -47,17 +48,17 @@ class AtomicString { return m_string; } - inline friend bool operator == (const AtomicString& a, const AtomicString& b); - inline friend bool operator != (const AtomicString& a, const AtomicString& b); + inline friend bool operator==(const AtomicString& a, const AtomicString& b); + inline friend bool operator!=(const AtomicString& a, const AtomicString& b); - bool operator== (const char* src) const + bool operator==(const char* src) const { size_t srcLen = strlen(src); if (srcLen != m_string->length()) { return false; } - for (size_t i = 0; i < srcLen; i ++) { + for (size_t i = 0; i < srcLen; i++) { if (src[i] != m_string->charAt(i)) { return false; } @@ -73,14 +74,14 @@ class AtomicString { String* m_string; }; -COMPILE_ASSERT(sizeof (AtomicString) == sizeof (size_t), ""); +COMPILE_ASSERT(sizeof(AtomicString) == sizeof(size_t), ""); -inline bool operator == (const AtomicString& a, const AtomicString& b) +inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.string() == b.string(); } -inline bool operator != (const AtomicString& a, const AtomicString& b) +inline bool operator!=(const AtomicString& a, const AtomicString& b) { return !operator==(a, b); } @@ -94,19 +95,20 @@ inline size_t stringHash(const char* src, size_t length) } typedef Vector > AtomicStringVector; - } namespace std { -template<> struct hash > { - size_t operator()(std::pair const &x) const +template <> +struct hash > { + size_t operator()(std::pair const& x) const { return Escargot::stringHash(x.first, x.second); } }; -template<> struct equal_to > { - bool operator()(std::pair const &a, std::pair const &b) const +template <> +struct equal_to > { + bool operator()(std::pair const& a, std::pair const& b) const { if (a.second == b.second) { return memcmp(a.first, b.first, sizeof(char) * a.second) == 0; @@ -114,7 +116,6 @@ template<> struct equal_to > { return false; } }; - } #endif diff --git a/src/runtime/BooleanObject.cpp b/src/runtime/BooleanObject.cpp index a8100ceb3..d21e676d4 100644 --- a/src/runtime/BooleanObject.cpp +++ b/src/runtime/BooleanObject.cpp @@ -10,5 +10,4 @@ BooleanObject::BooleanObject(ExecutionState& state, bool value) { setPrototype(state, state.context()->globalObject()->booleanPrototype()); } - } diff --git a/src/runtime/BooleanObject.h b/src/runtime/BooleanObject.h index dd6b401e7..aed89092a 100644 --- a/src/runtime/BooleanObject.h +++ b/src/runtime/BooleanObject.h @@ -13,10 +13,10 @@ class BooleanObject : public Object { { return m_primitiveValue; } + protected: bool m_primitiveValue; }; - } #endif diff --git a/src/runtime/Context.cpp b/src/runtime/Context.cpp index d57e938bb..51c109a1e 100644 --- a/src/runtime/Context.cpp +++ b/src/runtime/Context.cpp @@ -24,7 +24,7 @@ bool Context::object__proto__NativeSetter(ExecutionState& state, Object* self, c } static ObjectPropertyNativeGetterSetterData object__proto__NativeGetterSetterData( - true, true, true, &Context::object__proto__NativeGetter, &Context::object__proto__NativeSetter); + true, true, true, &Context::object__proto__NativeGetter, &Context::object__proto__NativeSetter); Value Context::functionPrototypeNativeGetter(ExecutionState& state, Object* self) { @@ -40,7 +40,7 @@ bool Context::functionPrototypeNativeSetter(ExecutionState& state, Object* self, } static ObjectPropertyNativeGetterSetterData functionPrototypeNativeGetterSetterData( - true, false, false, &Context::functionPrototypeNativeGetter, &Context::functionPrototypeNativeSetter); + true, false, false, &Context::functionPrototypeNativeGetter, &Context::functionPrototypeNativeSetter); Context::Context(VMInstance* instance) : m_didSomePrototypeObjectDefineIndexedProperty(false) @@ -52,25 +52,25 @@ Context::Context(VMInstance* instance) ObjectStructure defaultStructureForObject(stateForInit); m_defaultStructureForObject = defaultStructureForObject.addProperty(stateForInit, m_staticStrings.__proto__, - ObjectPropertyDescriptor::createDataButHasNativeGetterSetterDescriptor(&object__proto__NativeGetterSetterData)); + ObjectPropertyDescriptor::createDataButHasNativeGetterSetterDescriptor(&object__proto__NativeGetterSetterData)); m_defaultStructureForFunctionObject = m_defaultStructureForObject->addProperty(stateForInit, m_staticStrings.prototype, - ObjectPropertyDescriptor::createDataButHasNativeGetterSetterDescriptor(&functionPrototypeNativeGetterSetterData)); + ObjectPropertyDescriptor::createDataButHasNativeGetterSetterDescriptor(&functionPrototypeNativeGetterSetterData)); m_defaultStructureForFunctionObject = m_defaultStructureForFunctionObject->addProperty(stateForInit, m_staticStrings.name, - ObjectPropertyDescriptor::createDataDescriptor(ObjectPropertyDescriptor::ConfigurablePresent)); + ObjectPropertyDescriptor::createDataDescriptor(ObjectPropertyDescriptor::ConfigurablePresent)); m_defaultStructureForFunctionObject = m_defaultStructureForFunctionObject->addProperty(stateForInit, m_staticStrings.length, - ObjectPropertyDescriptor::createDataDescriptor(ObjectPropertyDescriptor::ConfigurablePresent)); + ObjectPropertyDescriptor::createDataDescriptor(ObjectPropertyDescriptor::ConfigurablePresent)); m_defaultStructureForNotConstructorFunctionObject = m_defaultStructureForObject->addProperty(stateForInit, m_staticStrings.name, - ObjectPropertyDescriptor::createDataDescriptor(ObjectPropertyDescriptor::ConfigurablePresent)); + ObjectPropertyDescriptor::createDataDescriptor(ObjectPropertyDescriptor::ConfigurablePresent)); m_defaultStructureForNotConstructorFunctionObject = m_defaultStructureForNotConstructorFunctionObject->addProperty(stateForInit, m_staticStrings.length, - ObjectPropertyDescriptor::createDataDescriptor(ObjectPropertyDescriptor::ConfigurablePresent)); + ObjectPropertyDescriptor::createDataDescriptor(ObjectPropertyDescriptor::ConfigurablePresent)); m_defaultStructureForFunctionPrototypeObject = m_defaultStructureForObject->addProperty(stateForInit, m_staticStrings.prototype, - ObjectPropertyDescriptor::createDataDescriptor((ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + ObjectPropertyDescriptor::createDataDescriptor((ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); m_globalObject = new GlobalObject(stateForInit); m_globalObject->installBuiltins(stateForInit); @@ -80,5 +80,4 @@ void Context::throwException(ExecutionState& state, const Value& exception) { m_sandBoxStack.back()->throwException(state, exception); } - } diff --git a/src/runtime/Context.h b/src/runtime/Context.h index c62b803f9..28de089e0 100644 --- a/src/runtime/Context.h +++ b/src/runtime/Context.h @@ -1,11 +1,11 @@ #ifndef __EscargotContext__ #define __EscargotContext__ -#include "runtime/Context.h" -#include "runtime/String.h" #include "runtime/AtomicString.h" -#include "runtime/StaticStrings.h" +#include "runtime/Context.h" #include "runtime/GlobalObject.h" +#include "runtime/StaticStrings.h" +#include "runtime/String.h" namespace Escargot { @@ -17,6 +17,7 @@ class SandBox; class Context : public gc { friend class AtomicString; friend class SandBox; + public: Context(VMInstance* instance); const StaticStrings& staticStrings() @@ -86,7 +87,6 @@ class Context : public gc { Vector> m_sandBoxStack; }; - } #endif diff --git a/src/runtime/Environment.h b/src/runtime/Environment.h index 72b39016f..8b33a598f 100644 --- a/src/runtime/Environment.h +++ b/src/runtime/Environment.h @@ -1,9 +1,9 @@ #ifndef __Escargot_Environment_h #define __Escargot_Environment_h -#include "runtime/Value.h" -#include "runtime/String.h" #include "runtime/AtomicString.h" +#include "runtime/String.h" +#include "runtime/Value.h" namespace Escargot { @@ -11,11 +11,14 @@ class GlobalObject; struct IdentifierInfo { AtomicString m_name; - enum Origin { Parameter, FunctionDeclaration, FunctionExpression, VariableDeclarator }; + enum Origin { Parameter, + FunctionDeclaration, + FunctionExpression, + VariableDeclarator }; struct { - bool m_isHeapAllocated:1; - bool m_bindingIsImmutable:1; - Origin m_origin:2; + bool m_isHeapAllocated : 1; + bool m_bindingIsImmutable : 1; + Origin m_origin : 2; } m_flags; IdentifierInfo(AtomicString name, Origin origin) @@ -34,7 +37,6 @@ class LexicalEnvironment : public gc { : m_record(record) , m_outerEnvironment(outerEnvironment) { - } EnvironmentRecord* record() { @@ -52,6 +54,5 @@ class LexicalEnvironment : public gc { EnvironmentRecord* m_record; LexicalEnvironment* m_outerEnvironment; }; - } #endif diff --git a/src/runtime/EnvironmentRecord.cpp b/src/runtime/EnvironmentRecord.cpp index 8f3b9ab82..1c6375e9a 100644 --- a/src/runtime/EnvironmentRecord.cpp +++ b/src/runtime/EnvironmentRecord.cpp @@ -23,7 +23,7 @@ GlobalEnvironmentRecord::GlobalEnvironmentRecord(ExecutionState& state, CodeBloc const CodeBlock::IdentifierInfoVector& vec = codeBlock->identifierInfos(); size_t len = vec.size(); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { ASSERT(vec[i].m_needToAllocateOnStack == false); createMutableBinding(state, vec[i].m_name, false); } @@ -65,7 +65,7 @@ void FunctionEnvironmentRecordNotIndexed::createMutableBinding(ExecutionState& s EnvironmentRecord::GetBindingValueResult FunctionEnvironmentRecordNotIndexed::getBindingValue(ExecutionState& state, const AtomicString& name) { size_t len = m_vector.size(); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { if (m_vector[i].m_name == name) { return EnvironmentRecord::GetBindingValueResult(m_vector[i].m_value); } @@ -76,7 +76,7 @@ EnvironmentRecord::GetBindingValueResult FunctionEnvironmentRecordNotIndexed::ge void FunctionEnvironmentRecordNotIndexed::setMutableBinding(ExecutionState& state, const AtomicString& name, const Value& V) { size_t len = m_vector.size(); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { if (m_vector[i].m_name == name) { m_vector[i].m_value = V; return; @@ -84,6 +84,4 @@ void FunctionEnvironmentRecordNotIndexed::setMutableBinding(ExecutionState& stat } RELEASE_ASSERT_NOT_REACHED(); } - - } diff --git a/src/runtime/EnvironmentRecord.h b/src/runtime/EnvironmentRecord.h index b03e695bf..daf0dac26 100644 --- a/src/runtime/EnvironmentRecord.h +++ b/src/runtime/EnvironmentRecord.h @@ -1,12 +1,12 @@ #ifndef __Escargot_EnvironmentRecord_h #define __Escargot_EnvironmentRecord_h -#include "runtime/Value.h" -#include "runtime/String.h" +#include "parser/CodeBlock.h" #include "runtime/AtomicString.h" -#include "runtime/Object.h" #include "runtime/FunctionObject.h" -#include "parser/CodeBlock.h" +#include "runtime/Object.h" +#include "runtime/String.h" +#include "runtime/Value.h" namespace Escargot { @@ -29,6 +29,7 @@ class EnvironmentRecord : public gc { EnvironmentRecord(ExecutionState& state, CodeBlock* codeBlock) { } + public: struct BindingSlot { MAKE_STACK_ALLOCATED(); @@ -38,12 +39,10 @@ class EnvironmentRecord : public gc { : m_record(record) , m_index(idx) { - } }; - virtual ~EnvironmentRecord() { } - + virtual ~EnvironmentRecord() {} virtual BindingSlot hasBinding(ExecutionState& state, const AtomicString& atomicName) { RELEASE_ASSERT_NOT_REACHED(); @@ -73,21 +72,18 @@ class EnvironmentRecord : public gc { : m_hasBindingValue(false) , m_value(Value(Value::ForceUninitialized)) { - } GetBindingValueResult(const Value& v) : m_hasBindingValue(true) , m_value(v) { - } GetBindingValueResult(bool has, const Value& v) : m_hasBindingValue(has) , m_value(v) { - } }; virtual GetBindingValueResult getBindingValue(ExecutionState& state, const AtomicString& name) @@ -155,6 +151,7 @@ class EnvironmentRecord : public gc { } inline void initInnerFunctionDeclarations(CodeBlock* codeBlock); + protected: }; @@ -165,8 +162,7 @@ class ObjectEnvironmentRecord : public EnvironmentRecord { , m_bindingObject(O) { } - ~ObjectEnvironmentRecord() { } - + ~ObjectEnvironmentRecord() {} Object* bindingObject() { return m_bindingObject; @@ -190,8 +186,7 @@ class ObjectEnvironmentRecord : public EnvironmentRecord { class GlobalEnvironmentRecord : public EnvironmentRecord { public: GlobalEnvironmentRecord(ExecutionState& state, CodeBlock* codeBlock, GlobalObject* global); - ~GlobalEnvironmentRecord() { } - + ~GlobalEnvironmentRecord() {} virtual bool isGlobalEnvironmentRecord() { return true; @@ -210,6 +205,7 @@ class GlobalEnvironmentRecord : public EnvironmentRecord { { return m_globalCodeBlock; } + protected: CodeBlock* m_globalCodeBlock; GlobalObject* m_globalObject; @@ -247,12 +243,12 @@ class DeclarativeEnvironmentRecord : public EnvironmentRecord { ASSERT(isFunctionEnvironmentRecord()); return reinterpret_cast(this); } - }; // http://www.ecma-international.org/ecma-262/6.0/index.html#sec-function-environment-records class FunctionEnvironmentRecord : public DeclarativeEnvironmentRecord { friend class LexicalEnvironment; + public: ALWAYS_INLINE FunctionEnvironmentRecord(ExecutionState& state, const Value& receiver, FunctionObject* function, size_t argc, Value* argv, bool isNewExpression) : DeclarativeEnvironmentRecord(state, function->codeBlock()) @@ -334,6 +330,7 @@ class FunctionEnvironmentRecord : public DeclarativeEnvironmentRecord { class FunctionEnvironmentRecordOnStack : public FunctionEnvironmentRecord { friend class LexicalEnvironment; + public: ALWAYS_INLINE FunctionEnvironmentRecordOnStack(ExecutionState& state, const Value& receiver, FunctionObject* function, size_t argc, Value* argv, bool isNewExpression) : FunctionEnvironmentRecord(state, receiver, function, argc, argv, isNewExpression) @@ -349,6 +346,7 @@ class FunctionEnvironmentRecordOnStack : public FunctionEnvironmentRecord { class FunctionEnvironmentRecordOnHeap : public FunctionEnvironmentRecord { friend class LexicalEnvironment; friend class ByteCodeInterpreter; + public: ALWAYS_INLINE FunctionEnvironmentRecordOnHeap(ExecutionState& state, const Value& receiver, FunctionObject* function, size_t argc, Value* argv, bool isNewExpression) : FunctionEnvironmentRecord(state, receiver, function, argc, argv, isNewExpression) @@ -372,13 +370,14 @@ class FunctionEnvironmentRecordOnHeap : public FunctionEnvironmentRecord { class FunctionEnvironmentRecordNotIndexed : public FunctionEnvironmentRecord { friend class LexicalEnvironment; + public: ALWAYS_INLINE FunctionEnvironmentRecordNotIndexed(ExecutionState& state, const Value& receiver, FunctionObject* function, size_t argc, Value* argv, bool isNewExpression) : FunctionEnvironmentRecord(state, receiver, function, argc, argv, isNewExpression) { const CodeBlock::IdentifierInfoVector& vec = function->codeBlock()->identifierInfos(); size_t len = vec.size(); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { createMutableBinding(state, vec[i].m_name, false); } } @@ -400,7 +399,5 @@ class FunctionEnvironmentRecordNotIndexed : public FunctionEnvironmentRecord { protected: IdentifierRecordVector m_vector; }; - - } #endif diff --git a/src/runtime/ErrorObject.cpp b/src/runtime/ErrorObject.cpp index b7d7fb800..3a8d3dbbb 100644 --- a/src/runtime/ErrorObject.cpp +++ b/src/runtime/ErrorObject.cpp @@ -8,7 +8,7 @@ const char* errorMessage_DefineProperty_Default = "Cannot define property '%s'"; const char* errorMessage_DefineProperty_LengthNotWritable = "Cannot modify property '%s': 'length' is not writable"; const char* errorMessage_DefineProperty_NotWritable = "Cannot modify non-writable property '%s'"; const char* errorMessage_DefineProperty_RedefineNotConfigurable = "Cannot redefine non-configurable property '%s'"; -const char* errorMessage_DefineProperty_NotExtensible ="Cannot define property '%s': object is not extensible"; +const char* errorMessage_DefineProperty_NotExtensible = "Cannot define property '%s': object is not extensible"; const char* errorMessage_ObjectToPrimitiveValue = "Cannot convert object to primitive value"; const char* errorMessage_NullToObject = "cannot convert null into object"; const char* errorMessage_UndefinedToObject = "cannot convert undefined into object"; @@ -100,7 +100,6 @@ void ErrorObject::throwBuiltinError(ExecutionState& state, Code code, String* ob state.throwException(new EvalErrorObject(state, errorMessage)); else state.throwException(new ErrorObject(state, errorMessage)); - } ErrorObject::ErrorObject(ExecutionState& state, String* errorMessage) @@ -146,5 +145,4 @@ EvalErrorObject::EvalErrorObject(ExecutionState& state, String* errorMessage) { setPrototype(state, state.context()->globalObject()->evalErrorPrototype()); } - } diff --git a/src/runtime/ErrorObject.h b/src/runtime/ErrorObject.h index c8a9d6e91..7e65b7a91 100644 --- a/src/runtime/ErrorObject.h +++ b/src/runtime/ErrorObject.h @@ -79,6 +79,7 @@ class ErrorObject : public Object { { return true; } + protected: }; @@ -111,8 +112,6 @@ class EvalErrorObject : public ErrorObject { public: EvalErrorObject(ExecutionState& state, String* errorMessage); }; - - } #endif diff --git a/src/runtime/ExecutionContext.h b/src/runtime/ExecutionContext.h index af105155c..59aba1488 100644 --- a/src/runtime/ExecutionContext.h +++ b/src/runtime/ExecutionContext.h @@ -12,6 +12,7 @@ class ExecutionContext : public gc { friend class FunctionObject; friend class ByteCodeInterpreter; friend class SandBox; + public: ExecutionContext(Context* context, ExecutionContext* parent = nullptr, LexicalEnvironment* lexicalEnvironment = nullptr, bool inStrictMode = false) : m_inStrictMode(inStrictMode) @@ -70,7 +71,6 @@ class ExecutionContext : public gc { Value* m_stackStorage; LexicalEnvironment* m_lexicalEnvironment; }; - } #endif diff --git a/src/runtime/ExecutionState.cpp b/src/runtime/ExecutionState.cpp index fb771822d..c791ee4fd 100644 --- a/src/runtime/ExecutionState.cpp +++ b/src/runtime/ExecutionState.cpp @@ -9,5 +9,4 @@ void ExecutionState::throwException(const Value& e) { context()->throwException(*this, e); } - } diff --git a/src/runtime/ExecutionState.h b/src/runtime/ExecutionState.h index b738b0eb6..ddd47b095 100644 --- a/src/runtime/ExecutionState.h +++ b/src/runtime/ExecutionState.h @@ -11,13 +11,13 @@ class Value; class ExecutionState : public gc { MAKE_STACK_ALLOCATED(); + public: ExecutionState(Context* context, ExecutionContext* executionContext = nullptr, Value* exeuctionResult = nullptr) : m_context(context) , m_executionContext(executionContext) , m_exeuctionResult(exeuctionResult) { - } Context* context() @@ -47,7 +47,6 @@ class ExecutionState : public gc { ExecutionContext* m_executionContext; Value* m_exeuctionResult; }; - } #endif diff --git a/src/runtime/FunctionObject.cpp b/src/runtime/FunctionObject.cpp index c651ea36d..a0e4179e5 100644 --- a/src/runtime/FunctionObject.cpp +++ b/src/runtime/FunctionObject.cpp @@ -93,13 +93,13 @@ Value FunctionObject::call(ExecutionState& state, const Value& receiverOrg, cons size_t stackStorageSize = m_codeBlock->identifierOnStackCount(); if (m_codeBlock->canAllocateEnvironmentOnStack()) { // no capture, very simple case - record = new(alloca(sizeof(LexicalEnvironment))) FunctionEnvironmentRecordOnStack(state, receiver, this, argc, argv, isNewExpression); + record = new (alloca(sizeof(LexicalEnvironment))) FunctionEnvironmentRecordOnStack(state, receiver, this, argc, argv, isNewExpression); if (LIKELY(state.executionContext() != nullptr)) { - env = new(alloca(sizeof(LexicalEnvironment))) LexicalEnvironment(record, state.executionContext()->lexicalEnvironment()); + env = new (alloca(sizeof(LexicalEnvironment))) LexicalEnvironment(record, state.executionContext()->lexicalEnvironment()); } else { - env = new(alloca(sizeof(LexicalEnvironment))) LexicalEnvironment(record, nullptr); + env = new (alloca(sizeof(LexicalEnvironment))) LexicalEnvironment(record, nullptr); } - ec = new(alloca(sizeof(ExecutionContext))) ExecutionContext(ctx, state.executionContext(), env, isStrict); + ec = new (alloca(sizeof(ExecutionContext))) ExecutionContext(ctx, state.executionContext(), env, isStrict); } else { if (m_codeBlock->canUseIndexedVariableStorage()) { record = new FunctionEnvironmentRecordOnHeap(state, receiver, this, argc, argv, isNewExpression); @@ -116,7 +116,7 @@ Value FunctionObject::call(ExecutionState& state, const Value& receiverOrg, cons ec->giveStackStorage(ALLOCA(stackStorageSize * sizeof(Value), Value, state)); Value* stackStorage = ec->stackStorage(); - for (size_t i = 0; i < stackStorageSize; i ++) { + for (size_t i = 0; i < stackStorageSize; i++) { stackStorage[i] = Value(); } Value resultValue; @@ -135,7 +135,7 @@ Value FunctionObject::call(ExecutionState& state, const Value& receiverOrg, cons size_t parameterCopySize = std::min(argc, info.size()); if (UNLIKELY(m_codeBlock->needsComplexParameterCopy())) { - for (size_t i = 0; i < parameterCopySize; i ++) { + for (size_t i = 0; i < parameterCopySize; i++) { if (info[i].m_isHeapAllocated) { record->setHeapValueByIndex(info[i].m_index, argv[i]); } else { @@ -143,7 +143,7 @@ Value FunctionObject::call(ExecutionState& state, const Value& receiverOrg, cons } } } else { - for (size_t i = 0; i < parameterCopySize; i ++) { + for (size_t i = 0; i < parameterCopySize; i++) { stackStorage[i] = argv[i]; } } @@ -163,5 +163,4 @@ Value FunctionObject::call(const Value& callee, ExecutionState& state, const Val RELEASE_ASSERT_NOT_REACHED(); } } - } diff --git a/src/runtime/FunctionObject.h b/src/runtime/FunctionObject.h index 5a470d13f..8ff3d5591 100644 --- a/src/runtime/FunctionObject.h +++ b/src/runtime/FunctionObject.h @@ -1,8 +1,8 @@ #ifndef __EscargotFunctionObject__ #define __EscargotFunctionObject__ -#include "runtime/Object.h" #include "parser/CodeBlock.h" +#include "runtime/Object.h" namespace Escargot { @@ -11,6 +11,7 @@ class FunctionObject : public Object { enum ForBuiltin { __ForBuiltin__ }; FunctionObject(ExecutionState& state, CodeBlock* codeBlock, ForBuiltin); void initFunctionObject(ExecutionState& state); + public: FunctionObject(ExecutionState& state, NativeFunctionInfo info, bool isConstructor = true); FunctionObject(ExecutionState& state, CodeBlock* codeBlock, bool isConstructor = true); @@ -53,13 +54,13 @@ class FunctionObject : public Object { Value call(ExecutionState& state, const Value& receiver, const size_t& argc, Value* argv, bool isNewExpression = false); static Value call(const Value& callee, ExecutionState& state, const Value& receiver, const size_t& argc, Value* argv, bool isNewExpression = false); + protected: Value getFunctionPrototypeSlowCase(ExecutionState& state); bool setFunctionPrototypeSlowCase(ExecutionState& state, const Value& v); bool m_isConstructor; CodeBlock* m_codeBlock; }; - } #endif diff --git a/src/runtime/GlobalObject.cpp b/src/runtime/GlobalObject.cpp index 11ac6a3bf..fbfc76781 100644 --- a/src/runtime/GlobalObject.cpp +++ b/src/runtime/GlobalObject.cpp @@ -22,15 +22,14 @@ void GlobalObject::installOthers(ExecutionState& state) { #ifdef ESCARGOT_SHELL defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().print), - Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, - NativeFunctionInfo(state.context()->staticStrings().print, builtinPrint, 1, nullptr, NativeFunctionInfo::Strict), false), - (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::AllPresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, + NativeFunctionInfo(state.context()->staticStrings().print, builtinPrint, 1, nullptr, NativeFunctionInfo::Strict), false), + (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::AllPresent))); #endif defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().gc), - Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, - NativeFunctionInfo(state.context()->staticStrings().gc, builtinGc, 0, nullptr, NativeFunctionInfo::Strict), false), - (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::AllPresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, + NativeFunctionInfo(state.context()->staticStrings().gc, builtinGc, 0, nullptr, NativeFunctionInfo::Strict), false), + (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::AllPresent))); } - } diff --git a/src/runtime/GlobalObject.h b/src/runtime/GlobalObject.h index dba992036..4c726fd85 100644 --- a/src/runtime/GlobalObject.h +++ b/src/runtime/GlobalObject.h @@ -1,8 +1,8 @@ #ifndef __EscargotObjectGlobalObject__ #define __EscargotObjectGlobalObject__ -#include "runtime/Object.h" #include "runtime/FunctionObject.h" +#include "runtime/Object.h" namespace Escargot { @@ -223,7 +223,6 @@ class GlobalObject : public Object { return m_structure->findProperty(state, name); } }; - } #endif diff --git a/src/runtime/GlobalObjectBuiltinBoolean.cpp b/src/runtime/GlobalObjectBuiltinBoolean.cpp index 22880721e..f0d5dd862 100644 --- a/src/runtime/GlobalObjectBuiltinBoolean.cpp +++ b/src/runtime/GlobalObjectBuiltinBoolean.cpp @@ -14,8 +14,8 @@ static Value builtinBooleanConstructor(ExecutionState& state, Value thisValue, s void GlobalObject::installBoolean(ExecutionState& state) { m_boolean = new FunctionObject(state, new CodeBlock(state.context(), NativeFunctionInfo(state.context()->staticStrings().Boolean, builtinBooleanConstructor, 1, [](ExecutionState& state, size_t argc, Value* argv) -> Object* { - return new BooleanObject(state); - }))); + return new BooleanObject(state); + }))); m_boolean->markThisObjectDontNeedStructureTransitionTable(state); m_boolean->setPrototype(state, m_functionPrototype); // TODO m_boolean->defineAccessorProperty(strings->prototype.string(), ESVMInstance::currentInstance()->functionPrototypeAccessorData(), false, false, false); @@ -26,7 +26,6 @@ void GlobalObject::installBoolean(ExecutionState& state) m_boolean->setFunctionPrototype(state, m_booleanPrototype); defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Boolean), - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_boolean, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_boolean, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); } - } diff --git a/src/runtime/GlobalObjectBuiltinError.cpp b/src/runtime/GlobalObjectBuiltinError.cpp index 360cf16ae..4ab9cb881 100644 --- a/src/runtime/GlobalObjectBuiltinError.cpp +++ b/src/runtime/GlobalObjectBuiltinError.cpp @@ -8,19 +8,19 @@ namespace Escargot { static Value builtinErrorConstructor(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression) { if (isNewExpression) { - Value message = argv[0]; - if (!message.isUndefined()) { - thisValue.toObject(state)->asErrorObject()->defineOwnPropertyThrowsExceptionWhenStrictMode(state, state.context()->staticStrings().message, - Object::ObjectPropertyDescriptorForDefineOwnProperty(message.toString(state), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); - } - return Value(); + Value message = argv[0]; + if (!message.isUndefined()) { + thisValue.toObject(state)->asErrorObject()->defineOwnPropertyThrowsExceptionWhenStrictMode(state, state.context()->staticStrings().message, + Object::ObjectPropertyDescriptorForDefineOwnProperty(message.toString(state), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + } + return Value(); } else { - ErrorObject* obj = new ErrorObject(state, String::emptyString); - Value message = argv[0]; - if (message.isUndefined()) { - obj->setThrowsExceptionWhenStrictMode(state, state.context()->staticStrings().message, message.toString(state), obj); - } - return obj; + ErrorObject* obj = new ErrorObject(state, String::emptyString); + Value message = argv[0]; + if (message.isUndefined()) { + obj->setThrowsExceptionWhenStrictMode(state, state.context()->staticStrings().message, message.toString(state), obj); + } + return obj; } return Value(); } @@ -72,8 +72,8 @@ static Value builtinErrorToString(ExecutionState& state, Value thisValue, size_t void GlobalObject::installError(ExecutionState& state) { m_error = new FunctionObject(state, new CodeBlock(state.context(), NativeFunctionInfo(state.context()->staticStrings().Error, builtinErrorConstructor, 1, [](ExecutionState& state, size_t argc, Value* argv) -> Object* { - return new ErrorObject(state, String::emptyString); - }))); + return new ErrorObject(state, String::emptyString); + }))); m_error->markThisObjectDontNeedStructureTransitionTable(state); m_error->setPrototype(state, m_functionPrototype); @@ -87,19 +87,19 @@ void GlobalObject::installError(ExecutionState& state) auto errorToStringFn = new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toString, builtinErrorToString, 0, nullptr, NativeFunctionInfo::Strict)); m_errorPrototype->defineOwnPropertyThrowsException(state, state.context()->staticStrings().toString, Object::ObjectPropertyDescriptorForDefineOwnProperty(errorToStringFn, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); - // m_##name##Error->defineAccessorProperty(strings->prototype.string(), ESVMInstance::currentInstance()->functionPrototypeAccessorData(), false, false, false); -#define DEFINE_ERROR(errorname, bname) \ - m_##errorname##Error = new FunctionObject(state, new CodeBlock(state.context(), NativeFunctionInfo(state.context()->staticStrings().bname##Error, builtinErrorConstructor, 1, [](ExecutionState& state, size_t argc, Value* argv) -> Object* { \ - return new bname##ErrorObject(state, String::emptyString); \ - }))); \ - m_##errorname##Error->setPrototype(state, m_functionPrototype); \ - m_##errorname##ErrorPrototype = new ErrorObject(state, String::emptyString); \ +// m_##name##Error->defineAccessorProperty(strings->prototype.string(), ESVMInstance::currentInstance()->functionPrototypeAccessorData(), false, false, false); +#define DEFINE_ERROR(errorname, bname) \ + m_##errorname##Error = new FunctionObject(state, new CodeBlock(state.context(), NativeFunctionInfo(state.context()->staticStrings().bname##Error, builtinErrorConstructor, 1, [](ExecutionState& state, size_t argc, Value* argv) -> Object* { \ + return new bname##ErrorObject(state, String::emptyString); \ + }))); \ + m_##errorname##Error->setPrototype(state, m_functionPrototype); \ + m_##errorname##ErrorPrototype = new ErrorObject(state, String::emptyString); \ m_##errorname##ErrorPrototype->defineOwnProperty(state, state.context()->staticStrings().constructor, Object::ObjectPropertyDescriptorForDefineOwnProperty(m_##errorname##Error, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); \ - m_##errorname##ErrorPrototype->defineOwnProperty(state, state.context()->staticStrings().message, Object::ObjectPropertyDescriptorForDefineOwnProperty(String::emptyString, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); \ - m_##errorname##ErrorPrototype->defineOwnProperty(state, state.context()->staticStrings().name, Object::ObjectPropertyDescriptorForDefineOwnProperty(String::emptyString, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); \ - m_##errorname##Error->setFunctionPrototype(state, m_##errorname##ErrorPrototype); \ - defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().bname##Error), \ - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_function, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + m_##errorname##ErrorPrototype->defineOwnProperty(state, state.context()->staticStrings().message, Object::ObjectPropertyDescriptorForDefineOwnProperty(String::emptyString, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); \ + m_##errorname##ErrorPrototype->defineOwnProperty(state, state.context()->staticStrings().name, Object::ObjectPropertyDescriptorForDefineOwnProperty(String::emptyString, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); \ + m_##errorname##Error->setFunctionPrototype(state, m_##errorname##ErrorPrototype); \ + defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().bname##Error), \ + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_function, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); DEFINE_ERROR(reference, Reference); DEFINE_ERROR(type, Type); @@ -109,9 +109,6 @@ void GlobalObject::installError(ExecutionState& state) DEFINE_ERROR(eval, Eval); defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Error), - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_function, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); - + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_function, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); } - - } diff --git a/src/runtime/GlobalObjectBuiltinFunction.cpp b/src/runtime/GlobalObjectBuiltinFunction.cpp index d50f3f55e..c4dfe853c 100644 --- a/src/runtime/GlobalObjectBuiltinFunction.cpp +++ b/src/runtime/GlobalObjectBuiltinFunction.cpp @@ -19,29 +19,28 @@ static Value builtinFunctionConstructor(ExecutionState& state, Value thisValue, void GlobalObject::installFunction(ExecutionState& state) { FunctionObject* emptyFunction = new FunctionObject(state, new CodeBlock(state.context(), NativeFunctionInfo(state.context()->staticStrings().Function, builtinFunctionEmptyFunction, 1, [](ExecutionState& state, size_t argc, Value* argv) -> Object* { - // TODO - RELEASE_ASSERT_NOT_REACHED(); - })), FunctionObject::__ForBuiltin__); + // TODO + RELEASE_ASSERT_NOT_REACHED(); + })), + FunctionObject::__ForBuiltin__); m_functionPrototype = emptyFunction; m_functionPrototype->setPrototype(state, m_objectPrototype); // TODO convert into defineOwnProperty // m_functionPrototype->setFunctionPrototype(state, emptyFunction); m_function = new FunctionObject(state, new CodeBlock(state.context(), NativeFunctionInfo(state.context()->staticStrings().Function, builtinFunctionConstructor, 1, [](ExecutionState& state, size_t argc, Value* argv) -> Object* { - // TODO - RELEASE_ASSERT_NOT_REACHED(); - }))); + // TODO + RELEASE_ASSERT_NOT_REACHED(); + }))); m_function->markThisObjectDontNeedStructureTransitionTable(state); // TODO m_function->defineAccessorProperty(strings->prototype.string(), ESVMInstance::currentInstance()->functionPrototypeAccessorData(), false, false, false); m_function->setPrototype(state, emptyFunction); m_function->setFunctionPrototype(state, emptyFunction); m_functionPrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().constructor), - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_function, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_function, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Function), - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_function, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_function, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); } - - } diff --git a/src/runtime/GlobalObjectBuiltinMath.cpp b/src/runtime/GlobalObjectBuiltinMath.cpp index 07568f399..1b7d38b3f 100644 --- a/src/runtime/GlobalObjectBuiltinMath.cpp +++ b/src/runtime/GlobalObjectBuiltinMath.cpp @@ -10,7 +10,7 @@ static Value builtinMathMax(ExecutionState& state, Value thisValue, size_t argc, if (argc == 0) { double n_inf = -1 * std::numeric_limits::infinity(); return Value(n_inf); - } else { + } else { double maxValue = argv[0].toNumber(state); for (unsigned i = 1; i < argc; i++) { double value = argv[i].toNumber(state); @@ -50,10 +50,9 @@ void GlobalObject::installMath(ExecutionState& state) // initialize math object: $20.2.2.24 Math.max() m_math->defineOwnPropertyThrowsException(state, ObjectPropertyName(state.context()->staticStrings().max), - Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().max, builtinMathMax, 2, nullptr, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().max, builtinMathMax, 2, nullptr, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Math), - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_math, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_math, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); } - } diff --git a/src/runtime/GlobalObjectBuiltinNumber.cpp b/src/runtime/GlobalObjectBuiltinNumber.cpp index b0aaa3b15..87a6db0d6 100644 --- a/src/runtime/GlobalObjectBuiltinNumber.cpp +++ b/src/runtime/GlobalObjectBuiltinNumber.cpp @@ -14,8 +14,8 @@ static Value builtinNumberConstructor(ExecutionState& state, Value thisValue, si void GlobalObject::installNumber(ExecutionState& state) { m_number = new FunctionObject(state, new CodeBlock(state.context(), NativeFunctionInfo(state.context()->staticStrings().Number, builtinNumberConstructor, 1, [](ExecutionState& state, size_t argc, Value* argv) -> Object* { - return new NumberObject(state); - }))); + return new NumberObject(state); + }))); m_number->markThisObjectDontNeedStructureTransitionTable(state); m_number->setPrototype(state, m_functionPrototype); // TODO m_number->defineAccessorProperty(strings->prototype.string(), ESVMInstance::currentInstance()->functionPrototypeAccessorData(), false, false, false); @@ -26,7 +26,6 @@ void GlobalObject::installNumber(ExecutionState& state) m_number->setFunctionPrototype(state, m_numberPrototype); defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Number), - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_number, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_number, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); } - } diff --git a/src/runtime/GlobalObjectBuiltinObject.cpp b/src/runtime/GlobalObjectBuiltinObject.cpp index e418ffe1b..c7caffc6b 100644 --- a/src/runtime/GlobalObjectBuiltinObject.cpp +++ b/src/runtime/GlobalObjectBuiltinObject.cpp @@ -84,25 +84,24 @@ void GlobalObject::installObject(ExecutionState& state) { FunctionObject* emptyFunction = m_functionPrototype; m_object = new FunctionObject(state, new CodeBlock(state.context(), NativeFunctionInfo(state.context()->staticStrings().Object, builtinObjectConstructor, 1, [](ExecutionState& state, size_t argc, Value* argv) -> Object* { - return new Object(state); - }))); + return new Object(state); + }))); m_object->markThisObjectDontNeedStructureTransitionTable(state); m_object->setPrototype(state, emptyFunction); // TODO m_object->defineAccessorProperty(strings->prototype.string(), ESVMInstance::currentInstance()->functionPrototypeAccessorData(), false, false, false); m_object->setFunctionPrototype(state, m_objectPrototype); m_objectPrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().constructor), - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_object, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_object, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); m_objectPrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toString), - Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toString, builtinObjectToString, 0, nullptr, NativeFunctionInfo::Strict)), - (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toString, builtinObjectToString, 0, nullptr, NativeFunctionInfo::Strict)), + (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); // $19.1.3.2 Object.prototype.hasOwnProperty(V) m_objectPrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().hasOwnProperty), - Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toString, builtinObjectHasOwnProperty, 1, nullptr, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toString, builtinObjectHasOwnProperty, 1, nullptr, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Object), - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_object, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_object, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); } - } diff --git a/src/runtime/GlobalObjectBuiltinString.cpp b/src/runtime/GlobalObjectBuiltinString.cpp index bead23af8..fa7c5bf3b 100644 --- a/src/runtime/GlobalObjectBuiltinString.cpp +++ b/src/runtime/GlobalObjectBuiltinString.cpp @@ -14,8 +14,8 @@ static Value builtinStringConstructor(ExecutionState& state, Value thisValue, si void GlobalObject::installString(ExecutionState& state) { m_string = new FunctionObject(state, new CodeBlock(state.context(), NativeFunctionInfo(state.context()->staticStrings().String, builtinStringConstructor, 1, [](ExecutionState& state, size_t argc, Value* argv) -> Object* { - return new StringObject(state); - }))); + return new StringObject(state); + }))); m_string->markThisObjectDontNeedStructureTransitionTable(state); m_string->setPrototype(state, m_functionPrototype); // TODO m_string->defineAccessorProperty(strings->prototype.string(), ESVMInstance::currentInstance()->functionPrototypeAccessorData(), false, false, false); @@ -26,7 +26,6 @@ void GlobalObject::installString(ExecutionState& state) m_string->setFunctionPrototype(state, m_stringPrototype); defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().String), - Object::ObjectPropertyDescriptorForDefineOwnProperty(m_string, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); + Object::ObjectPropertyDescriptorForDefineOwnProperty(m_string, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::EnumerablePresent))); } - } diff --git a/src/runtime/NumberObject.cpp b/src/runtime/NumberObject.cpp index 57236b24b..0b9ffa82e 100644 --- a/src/runtime/NumberObject.cpp +++ b/src/runtime/NumberObject.cpp @@ -10,5 +10,4 @@ NumberObject::NumberObject(ExecutionState& state, double value) { setPrototype(state, state.context()->globalObject()->numberPrototype()); } - } diff --git a/src/runtime/NumberObject.h b/src/runtime/NumberObject.h index b67d826e9..3c23659ce 100644 --- a/src/runtime/NumberObject.h +++ b/src/runtime/NumberObject.h @@ -13,10 +13,10 @@ class NumberObject : public Object { { return m_primitiveValue; } + protected: double m_primitiveValue; }; - } #endif diff --git a/src/runtime/Object.cpp b/src/runtime/Object.cpp index 05d4b1395..0077b20e5 100644 --- a/src/runtime/Object.cpp +++ b/src/runtime/Object.cpp @@ -305,5 +305,4 @@ void Object::deleteOwnProperty(ExecutionState& state, size_t idx) m_structure = m_structure->removeProperty(state, idx); m_values.erase(idx); } - } diff --git a/src/runtime/Object.h b/src/runtime/Object.h index 139931496..183b228c0 100644 --- a/src/runtime/Object.h +++ b/src/runtime/Object.h @@ -1,10 +1,10 @@ #ifndef __EscargotObject__ #define __EscargotObject__ +#include "runtime/ObjectStructure.h" #include "runtime/PointerValue.h" -#include "util/Vector.h" #include "runtime/SmallValue.h" -#include "runtime/ObjectStructure.h" +#include "util/Vector.h" namespace Escargot { @@ -78,6 +78,7 @@ class ObjectPropertyName { { return toPropertyName(state).string(); } + protected: bool m_isUIntType; union ObjectPropertyNameData { @@ -94,6 +95,7 @@ class Object : public PointerValue { friend class GlobalObject; friend class ByteCodeInterpreter; static Object* createBuiltinObjectPrototype(ExecutionState& state); + public: Object(ExecutionState& state); static Object* createFunctionPrototypeObject(ExecutionState& state, FunctionObject* function); @@ -145,7 +147,7 @@ class Object : public PointerValue { if (LIKELY(isPlainObject())) { m_values[0] = value; } else { - setPrototypeSlowCase(state, value); + setPrototypeSlowCase(state, value); } } @@ -172,6 +174,7 @@ class Object : public PointerValue { { return m_descriptor; } + protected: MAKE_STACK_ALLOCATED(); ObjectPropertyDescriptor m_descriptor; @@ -281,6 +284,7 @@ class Object : public PointerValue { ASSERT(structure()->inTransitionMode()); m_structure = m_structure->escapeTransitionMode(state); } + protected: Object(ExecutionState& state, size_t defaultSpace, bool initPlainArea); void initPlainObject(ExecutionState& state); @@ -404,7 +408,6 @@ class Object : public PointerValue { bool set(ExecutionState& state, const ObjectPropertyName& P, const Value& v, Object* receiver); }; - } #endif diff --git a/src/runtime/ObjectPropertyDescriptor.h b/src/runtime/ObjectPropertyDescriptor.h index 26551b98e..a1b7a6339 100644 --- a/src/runtime/ObjectPropertyDescriptor.h +++ b/src/runtime/ObjectPropertyDescriptor.h @@ -1,8 +1,8 @@ #ifndef __EscargotObjectPropertyDescriptor__ #define __EscargotObjectPropertyDescriptor__ -#include "runtime/Value.h" #include "runtime/ExecutionState.h" +#include "runtime/Value.h" namespace Escargot { @@ -19,7 +19,7 @@ struct ObjectPropertyNativeGetterSetterData { ObjectPropertyNativeSetter m_setter; ObjectPropertyNativeGetterSetterData(bool isWritable, bool isEnumerable, bool isConfigurable, - ObjectPropertyNativeGetter getter, ObjectPropertyNativeSetter setter) + ObjectPropertyNativeGetter getter, ObjectPropertyNativeSetter setter) : m_isWritable(isWritable) , m_isEnumerable(isEnumerable) , m_isConfigurable(isConfigurable) @@ -35,9 +35,9 @@ class ObjectPropertyDescriptor { public: enum PresentAttribute { NotPresent = 0, - WritablePresent = 1 << 1, // property can be only read, not written - EnumerablePresent = 1 << 2, // property doesn't appear in (for .. in ..) - ConfigurablePresent = 1 << 3, // property can't be deleted + WritablePresent = 1 << 1, // property can be only read, not written + EnumerablePresent = 1 << 2, // property doesn't appear in (for .. in ..) + ConfigurablePresent = 1 << 3, // property can't be deleted AllPresent = WritablePresent | EnumerablePresent | ConfigurablePresent }; @@ -99,7 +99,7 @@ class ObjectPropertyDescriptor { bool operator!=(const ObjectPropertyDescriptor& desc) const { - return !operator ==(desc); + return !operator==(desc); } ObjectPropertyNativeGetterSetterData* nativeGetterSetterData() const @@ -191,8 +191,7 @@ class ObjectPropertyDescriptor { } }; -COMPILE_ASSERT(sizeof (ObjectPropertyDescriptor) <= sizeof (size_t), ""); - +COMPILE_ASSERT(sizeof(ObjectPropertyDescriptor) <= sizeof(size_t), ""); } #endif diff --git a/src/runtime/ObjectStructure.h b/src/runtime/ObjectStructure.h index 96b6cc783..1a3b51b63 100644 --- a/src/runtime/ObjectStructure.h +++ b/src/runtime/ObjectStructure.h @@ -1,9 +1,9 @@ #ifndef __EscargotObjectStructure__ #define __EscargotObjectStructure__ -#include "runtime/ObjectPropertyDescriptor.h" -#include "runtime/ExecutionState.h" #include "runtime/AtomicString.h" +#include "runtime/ExecutionState.h" +#include "runtime/ObjectPropertyDescriptor.h" #include "runtime/PropertyName.h" namespace Escargot { @@ -15,7 +15,6 @@ struct ObjectStructureItem : public gc { : m_propertyName(as) , m_descriptor(desc) { - } PropertyName m_propertyName; @@ -32,7 +31,6 @@ struct ObjectStructureTransitionItem : public gc { , m_descriptor(desc) , m_structure(structure) { - } }; @@ -40,6 +38,7 @@ typedef Vector> ObjectStructureTransitionTableVector; class ObjectStructure : public gc { friend class Object; + public: ObjectStructure(ExecutionState& state, bool needsTransitionTable = true) { @@ -119,7 +118,7 @@ class ObjectStructure : public gc { newProperties.resizeWithUninitializedValues(m_properties.size() - 1); size_t newIdx = 0; - for (size_t i = 0; i < m_properties.size(); i ++) { + for (size_t i = 0; i < m_properties.size(); i++) { if (i == pIndex) continue; newProperties[newIdx].m_propertyName = m_properties[i].m_propertyName; @@ -146,6 +145,7 @@ class ObjectStructure : public gc { { return m_properties.size(); } + private: bool m_needsTransitionTable; ObjectStructureItemVector m_properties; @@ -154,7 +154,7 @@ class ObjectStructure : public gc { size_t searchTransitionTable(const PropertyName& s, const ObjectPropertyDescriptor& desc) { ASSERT(m_needsTransitionTable); - for (size_t i = 0; i < m_transitionTable.size(); i ++) { + for (size_t i = 0; i < m_transitionTable.size(); i++) { if (m_transitionTable[i].m_descriptor == desc && m_transitionTable[i].m_propertyName == s) { return i; } @@ -165,16 +165,14 @@ class ObjectStructure : public gc { size_t findProperty(PropertyName s) { - for (size_t i = 0; i < m_properties.size(); i ++) { + for (size_t i = 0; i < m_properties.size(); i++) { if (m_properties[i].m_propertyName == s) return i; } return SIZE_MAX; } - }; - } #endif diff --git a/src/runtime/PointerValue.h b/src/runtime/PointerValue.h index 5a4830555..b84c77955 100644 --- a/src/runtime/PointerValue.h +++ b/src/runtime/PointerValue.h @@ -92,7 +92,6 @@ class PointerValue : public gc { return (DoubleInSmallValue*)this; } }; - } #endif diff --git a/src/runtime/PropertyName.cpp b/src/runtime/PropertyName.cpp index be2296104..4f250bc8f 100644 --- a/src/runtime/PropertyName.cpp +++ b/src/runtime/PropertyName.cpp @@ -23,5 +23,4 @@ PropertyName::PropertyName(ExecutionState& state, String* string) } ASSERT(m_data); } - } diff --git a/src/runtime/PropertyName.h b/src/runtime/PropertyName.h index d6aea916a..e3a0f10c5 100644 --- a/src/runtime/PropertyName.h +++ b/src/runtime/PropertyName.h @@ -1,9 +1,9 @@ #ifndef __EscargotPropertyName__ #define __EscargotPropertyName__ +#include "runtime/AtomicString.h" #include "runtime/ExecutionState.h" #include "runtime/String.h" -#include "runtime/AtomicString.h" namespace Escargot { @@ -46,10 +46,10 @@ class PropertyName { } } - inline friend bool operator == (const PropertyName& a, const PropertyName& b); - inline friend bool operator != (const PropertyName& a, const PropertyName& b); -protected: + inline friend bool operator==(const PropertyName& a, const PropertyName& b); + inline friend bool operator!=(const PropertyName& a, const PropertyName& b); +protected: bool hasAtomicString() const { return m_data & 1; @@ -60,7 +60,7 @@ class PropertyName { // String* <- saves pointer }; -inline bool operator == (const PropertyName& a, const PropertyName& b) +inline bool operator==(const PropertyName& a, const PropertyName& b) { if (LIKELY(a.hasAtomicString()) == LIKELY(b.hasAtomicString())) { return a.m_data == b.m_data; @@ -69,11 +69,10 @@ inline bool operator == (const PropertyName& a, const PropertyName& b) } } -inline bool operator != (const PropertyName& a, const PropertyName& b) +inline bool operator!=(const PropertyName& a, const PropertyName& b) { return !operator==(a, b); } - } #endif diff --git a/src/runtime/RopeString.cpp b/src/runtime/RopeString.cpp index 34596b932..26217f344 100644 --- a/src/runtime/RopeString.cpp +++ b/src/runtime/RopeString.cpp @@ -27,12 +27,12 @@ String* RopeString::createRopeString(String* lstr, String* rstr) rope->m_hasASCIIContent = lstr->hasASCIIContent() | rstr->hasASCIIContent(); return rope; } -template +template void RopeString::flattenRopeStringWorker() { A result; result.resizeWithUninitializedValues(m_contentLength); - std::vector> queue; + std::vector> queue; queue.push_back(m_left); queue.push_back(m_right); size_t pos = m_contentLength; @@ -50,12 +50,12 @@ void RopeString::flattenRopeStringWorker() continue; } } - String* sub = cur; - pos -= sub->length(); - size_t subLength = sub->length(); - for (size_t i = 0 ; i < subLength; i ++) { - result[i + pos] = sub->charAt(i); - } + String* sub = cur; + pos -= sub->length(); + size_t subLength = sub->length(); + for (size_t i = 0; i < subLength; i++) { + result[i + pos] = sub->charAt(i); + } } m_left = new B(std::move(result)); m_right = nullptr; @@ -70,6 +70,4 @@ void RopeString::flattenRopeString() flattenRopeStringWorker(); } } - } - diff --git a/src/runtime/RopeString.h b/src/runtime/RopeString.h index f1ffe6301..d99888481 100644 --- a/src/runtime/RopeString.h +++ b/src/runtime/RopeString.h @@ -17,6 +17,7 @@ class RopeString : public String { m_left = nullptr; m_right = nullptr; } + public: // this function not always create RopeString. // if (l+r).length() < ESCARGOT_ROPE_STRING_MIN_LENGTH @@ -53,7 +54,7 @@ class RopeString : public String { const_cast(this)->flattenRopeString(); return m_left; } - template + template void flattenRopeStringWorker(); void flattenRopeString(); @@ -62,8 +63,6 @@ class RopeString : public String { String* m_right; size_t m_contentLength; }; - } #endif - diff --git a/src/runtime/SandBox.cpp b/src/runtime/SandBox.cpp index 77e602cac..70aa2182e 100644 --- a/src/runtime/SandBox.cpp +++ b/src/runtime/SandBox.cpp @@ -14,9 +14,9 @@ SandBox::SandBoxResult SandBox::run(const std::function& scriptRunner) SandBox::SandBoxResult result; try { result.result = scriptRunner(); - } catch(const Value& err) { + } catch (const Value& err) { result.error = err; - for (size_t i = 0; i < m_stackTraceData.size(); i ++) { + for (size_t i = 0; i < m_stackTraceData.size(); i++) { result.stackTraceData.pushBack(m_stackTraceData[i].second); } } @@ -62,5 +62,4 @@ void SandBox::throwException(ExecutionState& state, Value exception) } throw exception; } - } diff --git a/src/runtime/SandBox.h b/src/runtime/SandBox.h index 4cfffc0aa..4510c2458 100644 --- a/src/runtime/SandBox.h +++ b/src/runtime/SandBox.h @@ -1,13 +1,14 @@ #ifndef __EscargotSandBox__ #define __EscargotSandBox__ -#include "runtime/Context.h" #include "parser/ast/Node.h" +#include "runtime/Context.h" namespace Escargot { class SandBox { MAKE_STACK_ALLOCATED(); + public: SandBox(Context* s) { @@ -28,7 +29,6 @@ class SandBox { : fileName(String::emptyString) , loc(SIZE_MAX, SIZE_MAX, SIZE_MAX) { - } }; @@ -45,11 +45,11 @@ class SandBox { SandBoxResult run(const std::function& scriptRunner); // for capsule script executing with try-catch void throwException(ExecutionState& state, Value exception); + protected: Context* m_context; Vector, gc_malloc_allocator>> m_stackTraceData; }; - } #endif diff --git a/src/runtime/SmallValue.cpp b/src/runtime/SmallValue.cpp index 0bf671663..5435fd60e 100644 --- a/src/runtime/SmallValue.cpp +++ b/src/runtime/SmallValue.cpp @@ -33,5 +33,4 @@ SmallValueData* smallValueFalse = new SmallValueData(&dummyInSmallValueFalse); SmallValueData* smallValueEmpty = new SmallValueData(&dummyInSmallValueEmpty); SmallValueData* smallValueDeleted = new SmallValueData(&dummyInSmallValueDelete); } - } diff --git a/src/runtime/SmallValue.h b/src/runtime/SmallValue.h index ad8d17f74..0f6a96b43 100644 --- a/src/runtime/SmallValue.h +++ b/src/runtime/SmallValue.h @@ -59,23 +59,23 @@ const int kSmiTag = 1; const int kSmiTagSize = 1; const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; -template struct SmiTagging; +template +struct SmiTagging; -template +template inline int32_t IntToSmiT(int value) { int smi_shift_bits = kSmiTagSize + kSmiShiftSize; - uintptr_t tagged_value = - (static_cast(value) << smi_shift_bits) | kSmiTag; + uintptr_t tagged_value = (static_cast(value) << smi_shift_bits) | kSmiTag; return (int32_t)(tagged_value); } // Smi constants for 32-bit systems. -template<> struct SmiTagging<4> -{ - enum - { - kSmiShiftSize = 0, kSmiValueSize = 31 +template <> +struct SmiTagging<4> { + enum { + kSmiShiftSize = 0, + kSmiValueSize = 31 }; static int SmiShiftSize() { @@ -129,7 +129,6 @@ extern SmallValueData* smallValueTrue; extern SmallValueData* smallValueFalse; extern SmallValueData* smallValueEmpty; extern SmallValueData* smallValueDeleted; - } class SmallValue { @@ -190,17 +189,15 @@ class SmallValue { return Value(v); } } else { - int32_t value = SmallValueImpl::PlatformSmiTagging::SmiToInt(m_data.payload); + int32_t value = SmallValueImpl::PlatformSmiTagging::SmiToInt(m_data.payload); return Value(value); } return Value(); } + protected: SmallValueData m_data; }; - - - } diff --git a/src/runtime/SmallValueData.h b/src/runtime/SmallValueData.h index 5ff7c235a..9cf43285f 100644 --- a/src/runtime/SmallValueData.h +++ b/src/runtime/SmallValueData.h @@ -7,7 +7,6 @@ union SmallValueData { intptr_t payload; SmallValueData() { - } SmallValueData(void* ptr) @@ -15,7 +14,6 @@ union SmallValueData { payload = (intptr_t)ptr; } }; - } diff --git a/src/runtime/StaticStrings.cpp b/src/runtime/StaticStrings.cpp index f5afb3a18..f0ba44e01 100644 --- a/src/runtime/StaticStrings.cpp +++ b/src/runtime/StaticStrings.cpp @@ -16,14 +16,14 @@ void StaticStrings::initStaticStrings(AtomicStringMap* atomicStringMap) stringCatch.init(atomicStringMap, "catch", strlen("catch")); defaultRegExpString.init(atomicStringMap, "(?:)", strlen("(?:)")); - for (unsigned i = 0; i < ESCARGOT_ASCII_TABLE_MAX ; i ++) { + for (unsigned i = 0; i < ESCARGOT_ASCII_TABLE_MAX; i++) { char buf[2]; buf[0] = i; buf[1] = 0; asciiTable[i].init(atomicStringMap, buf, 1); } - for (unsigned i = 0; i < ESCARGOT_STRINGS_NUMBERS_MAX ; i ++) { + for (unsigned i = 0; i < ESCARGOT_STRINGS_NUMBERS_MAX; i++) { ASCIIStringData s = dtoa(i); numbers[i].init(atomicStringMap, s.data(), s.size()); } @@ -32,5 +32,4 @@ void StaticStrings::initStaticStrings(AtomicStringMap* atomicStringMap) FOR_EACH_STATIC_STRING(INIT_STATIC_STRING) #undef INIT_STATIC_STRING } - } diff --git a/src/runtime/StaticStrings.h b/src/runtime/StaticStrings.h index 2f8182935..f92eaba70 100644 --- a/src/runtime/StaticStrings.h +++ b/src/runtime/StaticStrings.h @@ -6,272 +6,272 @@ namespace Escargot { #define FOR_EACH_STATIC_STRING(F) \ - F(null) \ - F(undefined) \ - F(prototype) \ - F(constructor) \ - F(name) \ - F(arguments) \ - F(caller) \ - F(callee) \ - F(length) \ - F(__proto__) \ - F(value) \ - F(writable) \ - F(enumerable) \ - F(configurable) \ - F(get) \ - F(set) \ - F(String) \ - F(Number) \ - F(NaN) \ - F(Infinity) \ - F(NEGATIVE_INFINITY) \ - F(POSITIVE_INFINITY) \ - F(MAX_VALUE) \ - F(MIN_VALUE) \ - F(eval) \ - F(Object) \ - F(GlobalObject) \ - F(Boolean) \ - F(Error) \ - F(ReferenceError) \ - F(TypeError) \ - F(RangeError) \ - F(SyntaxError) \ - F(URIError) \ - F(EvalError) \ - F(message) \ - F(valueOf) \ - F(Array) \ - F(isArray) \ - F(concat) \ - F(forEach) \ - F(indexOf) \ - F(lastIndexOf) \ - F(join) \ - F(push) \ - F(pop) \ - F(slice) \ - F(splice) \ - F(shift) \ - F(sort) \ - F(Function) \ - F(Empty) \ - F(Date) \ - F(getDate) \ - F(getDay) \ - F(getFullYear) \ - F(getHours) \ - F(getMilliseconds) \ - F(getMinutes) \ - F(getMonth) \ - F(getSeconds) \ - F(getTime) \ - F(getTimezoneOffset) \ - F(getUTCDate) \ - F(getUTCDay) \ - F(getUTCFullYear) \ - F(getUTCHours) \ - F(getUTCMilliseconds) \ - F(getUTCMinutes) \ - F(getUTCMonth) \ - F(getUTCSeconds) \ - F(setDate) \ - F(setFullYear) \ - F(setHours) \ - F(setMilliseconds) \ - F(setMinutes) \ - F(setMonth) \ - F(setSeconds) \ - F(setTime) \ - F(setUTCDate) \ - F(setUTCFullYear) \ - F(setUTCHours) \ - F(setUTCMilliseconds) \ - F(setUTCMinutes) \ - F(setUTCMonth) \ - F(setUTCSeconds) \ - F(toDateString) \ - F(toISOString) \ - F(toLocaleDateString) \ - F(toLocaleTimeString) \ - F(toTimeString) \ - F(toUTCString) \ - F(getYear) \ - F(setYear) \ - F(toGMTString) \ - F(Math) \ - F(PI) \ - F(E) \ - F(abs) \ - F(cos) \ - F(ceil) \ - F(max) \ - F(min) \ - F(floor) \ - F(pow) \ - F(random) \ - F(round) \ - F(sin) \ - F(sqrt) \ - F(tan) \ - F(log) \ - F(toString) \ - F(toLocaleString) \ - F(boolean) \ - F(number) \ - F(toFixed) \ - F(toPrecision) \ - F(string) \ - F(object) \ - F(function) \ - F(RegExp) \ - F(source) \ - F(lastIndex) \ - F(test) \ - F(exec) \ - F(input) \ - F(index) \ - F(compile) \ - F(byteLength) \ - F(subarray) \ - F(buffer) \ - F(JSON) \ - F(parse) \ - F(stringify) \ - F(toJSON) \ - F(getPrototypeOf) \ - F(isPrototypeOf) \ - F(propertyIsEnumerable) \ - F(ignoreCase) \ - F(global) \ - F(multiline) \ - F(implements) \ - F(interface) \ - F(package) \ - F(yield) \ - F(let) \ - F(LN10) \ - F(LN2) \ - F(LOG10E) \ - F(LOG2E) \ - F(MAX_SAFE_INTEGER) \ - F(MIN_SAFE_INTEGER) \ - F(SQRT1_2) \ - F(SQRT2) \ - F(UTC) \ - F(acos) \ - F(acosh) \ - F(anonymous) \ - F(apply) \ - F(asin) \ - F(asinh) \ - F(atan) \ - F(atan2) \ - F(atanh) \ - F(bind) \ - F(call) \ - F(cbrt) \ - F(charAt) \ - F(charCodeAt) \ - F(create) \ - F(dbgBreak) \ - F(decodeURI) \ - F(decodeURIComponent) \ - F(defineProperties) \ - F(defineProperty) \ - F(encodeURI) \ - F(encodeURIComponent) \ - F(escape) \ - F(every) \ - F(exp) \ - F(fill) \ - F(filter) \ - F(find) \ - F(findIndex) \ - F(freeze) \ - F(fromCharCode) \ - F(getOwnPropertyDescriptor) \ - F(getOwnPropertyNames) \ - F(hasOwnProperty) \ - F(imul) \ - F(isExtensible) \ - F(isFinite) \ - F(isFrozen) \ - F(isNaN) \ - F(isSealed) \ - F(keys) \ - F(localeCompare) \ - F(map) \ - F(match) \ - F(now) \ - F(parseFloat) \ - F(parseInt) \ - F(preventExtensions) \ - F(print) \ - F(read) \ - F(append) \ - F(reduce) \ - F(reduceRight) \ - F(replace) \ - F(reverse) \ - F(run) \ - F(seal) \ - F(search) \ - F(some) \ - F(split) \ - F(startsWith) \ - F(substr) \ - F(substring) \ - F(toExponential) \ - F(toLocaleLowerCase) \ - F(toLocaleUpperCase) \ - F(toLowerCase) \ - F(toUpperCase) \ - F(trim) \ - F(unescape) \ - F(unshift) \ - F(TypedArray) \ - F(Int8Array) \ - F(Int16Array) \ - F(Int32Array) \ - F(Uint8Array) \ - F(Uint16Array) \ - F(Uint32Array) \ - F(Uint8ClampedArray) \ - F(Float32Array) \ - F(Float64Array) \ - F(ArrayBuffer) \ - F(isView) \ - F(DataView) \ - F(byteOffset) \ - F(getFloat32) \ - F(getFloat64) \ - F(getInt8) \ - F(getInt16) \ - F(getInt32) \ - F(getUint8) \ - F(getUint16) \ - F(getUint32) \ - F(setFloat32) \ - F(setFloat64) \ - F(setInt8) \ - F(setInt16) \ - F(setInt32) \ - F(setUint8) \ - F(setUint16) \ - F(setUint32) \ - F(Promise) \ - F(alreadyResolved) \ - F(alreadyCalled) \ - F(values) \ - F(remainingElements) \ - F(all) \ - F(race) \ - F(reject) \ - F(resolve) \ - F(then) \ + F(null) \ + F(undefined) \ + F(prototype) \ + F(constructor) \ + F(name) \ + F(arguments) \ + F(caller) \ + F(callee) \ + F(length) \ + F(__proto__) \ + F(value) \ + F(writable) \ + F(enumerable) \ + F(configurable) \ + F(get) \ + F(set) \ + F(String) \ + F(Number) \ + F(NaN) \ + F(Infinity) \ + F(NEGATIVE_INFINITY) \ + F(POSITIVE_INFINITY) \ + F(MAX_VALUE) \ + F(MIN_VALUE) \ + F(eval) \ + F(Object) \ + F(GlobalObject) \ + F(Boolean) \ + F(Error) \ + F(ReferenceError) \ + F(TypeError) \ + F(RangeError) \ + F(SyntaxError) \ + F(URIError) \ + F(EvalError) \ + F(message) \ + F(valueOf) \ + F(Array) \ + F(isArray) \ + F(concat) \ + F(forEach) \ + F(indexOf) \ + F(lastIndexOf) \ + F(join) \ + F(push) \ + F(pop) \ + F(slice) \ + F(splice) \ + F(shift) \ + F(sort) \ + F(Function) \ + F(Empty) \ + F(Date) \ + F(getDate) \ + F(getDay) \ + F(getFullYear) \ + F(getHours) \ + F(getMilliseconds) \ + F(getMinutes) \ + F(getMonth) \ + F(getSeconds) \ + F(getTime) \ + F(getTimezoneOffset) \ + F(getUTCDate) \ + F(getUTCDay) \ + F(getUTCFullYear) \ + F(getUTCHours) \ + F(getUTCMilliseconds) \ + F(getUTCMinutes) \ + F(getUTCMonth) \ + F(getUTCSeconds) \ + F(setDate) \ + F(setFullYear) \ + F(setHours) \ + F(setMilliseconds) \ + F(setMinutes) \ + F(setMonth) \ + F(setSeconds) \ + F(setTime) \ + F(setUTCDate) \ + F(setUTCFullYear) \ + F(setUTCHours) \ + F(setUTCMilliseconds) \ + F(setUTCMinutes) \ + F(setUTCMonth) \ + F(setUTCSeconds) \ + F(toDateString) \ + F(toISOString) \ + F(toLocaleDateString) \ + F(toLocaleTimeString) \ + F(toTimeString) \ + F(toUTCString) \ + F(getYear) \ + F(setYear) \ + F(toGMTString) \ + F(Math) \ + F(PI) \ + F(E) \ + F(abs) \ + F(cos) \ + F(ceil) \ + F(max) \ + F(min) \ + F(floor) \ + F(pow) \ + F(random) \ + F(round) \ + F(sin) \ + F(sqrt) \ + F(tan) \ + F(log) \ + F(toString) \ + F(toLocaleString) \ + F(boolean) \ + F(number) \ + F(toFixed) \ + F(toPrecision) \ + F(string) \ + F(object) \ + F(function) \ + F(RegExp) \ + F(source) \ + F(lastIndex) \ + F(test) \ + F(exec) \ + F(input) \ + F(index) \ + F(compile) \ + F(byteLength) \ + F(subarray) \ + F(buffer) \ + F(JSON) \ + F(parse) \ + F(stringify) \ + F(toJSON) \ + F(getPrototypeOf) \ + F(isPrototypeOf) \ + F(propertyIsEnumerable) \ + F(ignoreCase) \ + F(global) \ + F(multiline) \ + F(implements) \ + F(interface) \ + F(package) \ + F(yield) \ + F(let) \ + F(LN10) \ + F(LN2) \ + F(LOG10E) \ + F(LOG2E) \ + F(MAX_SAFE_INTEGER) \ + F(MIN_SAFE_INTEGER) \ + F(SQRT1_2) \ + F(SQRT2) \ + F(UTC) \ + F(acos) \ + F(acosh) \ + F(anonymous) \ + F(apply) \ + F(asin) \ + F(asinh) \ + F(atan) \ + F(atan2) \ + F(atanh) \ + F(bind) \ + F(call) \ + F(cbrt) \ + F(charAt) \ + F(charCodeAt) \ + F(create) \ + F(dbgBreak) \ + F(decodeURI) \ + F(decodeURIComponent) \ + F(defineProperties) \ + F(defineProperty) \ + F(encodeURI) \ + F(encodeURIComponent) \ + F(escape) \ + F(every) \ + F(exp) \ + F(fill) \ + F(filter) \ + F(find) \ + F(findIndex) \ + F(freeze) \ + F(fromCharCode) \ + F(getOwnPropertyDescriptor) \ + F(getOwnPropertyNames) \ + F(hasOwnProperty) \ + F(imul) \ + F(isExtensible) \ + F(isFinite) \ + F(isFrozen) \ + F(isNaN) \ + F(isSealed) \ + F(keys) \ + F(localeCompare) \ + F(map) \ + F(match) \ + F(now) \ + F(parseFloat) \ + F(parseInt) \ + F(preventExtensions) \ + F(print) \ + F(read) \ + F(append) \ + F(reduce) \ + F(reduceRight) \ + F(replace) \ + F(reverse) \ + F(run) \ + F(seal) \ + F(search) \ + F(some) \ + F(split) \ + F(startsWith) \ + F(substr) \ + F(substring) \ + F(toExponential) \ + F(toLocaleLowerCase) \ + F(toLocaleUpperCase) \ + F(toLowerCase) \ + F(toUpperCase) \ + F(trim) \ + F(unescape) \ + F(unshift) \ + F(TypedArray) \ + F(Int8Array) \ + F(Int16Array) \ + F(Int32Array) \ + F(Uint8Array) \ + F(Uint16Array) \ + F(Uint32Array) \ + F(Uint8ClampedArray) \ + F(Float32Array) \ + F(Float64Array) \ + F(ArrayBuffer) \ + F(isView) \ + F(DataView) \ + F(byteOffset) \ + F(getFloat32) \ + F(getFloat64) \ + F(getInt8) \ + F(getInt16) \ + F(getInt32) \ + F(getUint8) \ + F(getUint16) \ + F(getUint32) \ + F(setFloat32) \ + F(setFloat64) \ + F(setInt8) \ + F(setInt16) \ + F(setInt32) \ + F(setUint8) \ + F(setUint16) \ + F(setUint32) \ + F(Promise) \ + F(alreadyResolved) \ + F(alreadyCalled) \ + F(values) \ + F(remainingElements) \ + F(all) \ + F(race) \ + F(reject) \ + F(resolve) \ + F(then) \ F(gc) class StaticStrings { @@ -298,7 +298,6 @@ class StaticStrings { void initStaticStrings(AtomicStringMap* map); }; - } #endif diff --git a/src/runtime/String.cpp b/src/runtime/String.cpp index 6824c1301..967ffca81 100644 --- a/src/runtime/String.cpp +++ b/src/runtime/String.cpp @@ -6,11 +6,11 @@ namespace Escargot { -String* String::emptyString = new(malloc(sizeof (String))) ASCIIString(""); +String* String::emptyString = new (malloc(sizeof(String))) ASCIIString(""); bool isAllASCII(const char* buf, const size_t& len) { - for (unsigned i = 0; i < len ; i ++) { + for (unsigned i = 0; i < len; i++) { if ((buf[i] & 0x80) != 0) { return false; } @@ -20,7 +20,7 @@ bool isAllASCII(const char* buf, const size_t& len) bool isAllASCII(const char16_t* buf, const size_t& len) { - for (unsigned i = 0; i < len ; i ++) { + for (unsigned i = 0; i < len; i++) { if (buf[i] >= 128) { return false; } @@ -93,15 +93,15 @@ UTF16StringData utf8StringToUTF16String(const char* buf, const size_t& len) if (!valid) { // Invalid sequence str += 0xFFFD; } else if (((uint32_t)(ch) <= 0xffff)) { // BMP - if ((((ch) & 0xfffff800) == 0xd800)) { // SURROGATE + if ((((ch)&0xfffff800) == 0xd800)) { // SURROGATE str += 0xFFFD; source -= (charlen - 1); } else { str += ch; // normal case } - } else if (((uint32_t)((ch) - 0x10000) <= 0xfffff)) { // SUPPLEMENTARY + } else if (((uint32_t)((ch)-0x10000) <= 0xfffff)) { // SUPPLEMENTARY str += (char16_t)(((ch) >> 10) + 0xd7c0); // LEAD - str += (char16_t)(((ch) & 0x3ff) | 0xdc00); // TRAIL + str += (char16_t)(((ch)&0x3ff) | 0xdc00); // TRAIL } else { str += 0xFFFD; source -= (charlen - 1); @@ -115,7 +115,7 @@ ASCIIStringData utf16StringToASCIIString(const char16_t* buf, const size_t& len) { ASCIIStringData str; str.resizeWithUninitializedValues(len); - for (unsigned i = 0 ; i < len ; i ++) { + for (unsigned i = 0; i < len; i++) { ASSERT(buf[i] < 128); str[i] = buf[i]; } @@ -149,32 +149,32 @@ size_t utf32ToUtf8(char32_t uc, char* UTF8) tRequiredSize = 3; } else if (uc <= 0x1fffff) { if (NULL != UTF8) { - UTF8[0] = (char)(0xf0 + uc / (0x01 <<18)); - UTF8[1] = (char)(0x80 + uc / (0x01 <<12) % (0x01 <<12)); + UTF8[0] = (char)(0xf0 + uc / (0x01 << 18)); + UTF8[1] = (char)(0x80 + uc / (0x01 << 12) % (0x01 << 12)); UTF8[2] = (char)(0x80 + uc / (0x01 << 6) % (0x01 << 6)); UTF8[3] = (char)(0x80 + uc % (0x01 << 6)); - UTF8[4] = (char) '\0'; + UTF8[4] = (char)'\0'; } tRequiredSize = 4; } else if (uc <= 0x3ffffff) { if (NULL != UTF8) { - UTF8[0] = (char)(0xf8 + uc / (0x01 <<24)); - UTF8[1] = (char)(0x80 + uc / (0x01 <<18) % (0x01 <<18)); - UTF8[2] = (char)(0x80 + uc / (0x01 <<12) % (0x01 <<12)); + UTF8[0] = (char)(0xf8 + uc / (0x01 << 24)); + UTF8[1] = (char)(0x80 + uc / (0x01 << 18) % (0x01 << 18)); + UTF8[2] = (char)(0x80 + uc / (0x01 << 12) % (0x01 << 12)); UTF8[3] = (char)(0x80 + uc / (0x01 << 6) % (0x01 << 6)); UTF8[4] = (char)(0x80 + uc % (0x01 << 6)); - UTF8[5] = (char) '\0'; + UTF8[5] = (char)'\0'; } tRequiredSize = 5; } else if (uc <= 0x7fffffff) { if (NULL != UTF8) { - UTF8[0] = (char)(0xfc + uc / (0x01 <<30)); - UTF8[1] = (char)(0x80 + uc / (0x01 <<24) % (0x01 <<24)); - UTF8[2] = (char)(0x80 + uc / (0x01 <<18) % (0x01 <<18)); - UTF8[3] = (char)(0x80 + uc / (0x01 <<12) % (0x01 <<12)); + UTF8[0] = (char)(0xfc + uc / (0x01 << 30)); + UTF8[1] = (char)(0x80 + uc / (0x01 << 24) % (0x01 << 24)); + UTF8[2] = (char)(0x80 + uc / (0x01 << 18) % (0x01 << 18)); + UTF8[3] = (char)(0x80 + uc / (0x01 << 12) % (0x01 << 12)); UTF8[4] = (char)(0x80 + uc / (0x01 << 6) % (0x01 << 6)); UTF8[5] = (char)(0x80 + uc % (0x01 << 6)); - UTF8[6] = (char) '\0'; + UTF8[6] = (char)'\0'; } tRequiredSize = 6; } else { @@ -189,10 +189,10 @@ UTF8StringData utf16StringToUTF8String(const char16_t* buf, const size_t& len) { UTF8StringDataNonGCStd str; str.reserve(len); - for (unsigned i = 0 ; i < len ;) { + for (unsigned i = 0; i < len;) { if (buf[i] < 128) { str += buf[i]; - i ++; + i++; } else { char32_t c; U16_NEXT(buf, i, len, c); @@ -210,7 +210,7 @@ UTF16StringData ASCIIString::toUTF16StringData() const UTF16StringData ret; size_t len = length(); ret.resizeWithUninitializedValues(len); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { ret[i] = charAt(i); } return ret; @@ -245,7 +245,8 @@ void CreateDecimalRepresentation( int length, int decimal_point, int digits_after_point, - double_conversion::StringBuilder* result_builder) { + double_conversion::StringBuilder* result_builder) +{ // Create a representation that is padded with zeros if needed. if (decimal_point <= 0) { // "0.00000decimal_rep". @@ -273,7 +274,7 @@ void CreateDecimalRepresentation( result_builder->AddCharacter('.'); ASSERT(length - decimal_point <= digits_after_point); result_builder->AddSubstring(&decimal_digits[decimal_point], - length - decimal_point); + length - decimal_point); int remaining_digits = digits_after_point - (length - decimal_point); result_builder->AddPadding('0', remaining_digits); } @@ -292,12 +293,13 @@ void CreateExponentialRepresentation( const char* decimal_digits, int length, int exponent, - double_conversion::StringBuilder* result_builder) { + double_conversion::StringBuilder* result_builder) +{ ASSERT(length != 0); result_builder->AddCharacter(decimal_digits[0]); if (length != 1) { result_builder->AddCharacter('.'); - result_builder->AddSubstring(&decimal_digits[1], length-1); + result_builder->AddSubstring(&decimal_digits[1], length - 1); } result_builder->AddCharacter('e'); if (exponent < 0) { @@ -322,7 +324,7 @@ void CreateExponentialRepresentation( exponent /= 10; } result_builder->AddSubstring(&buffer[first_char_pos], - kMaxExponentLength - first_char_pos); + kMaxExponentLength - first_char_pos); } ASCIIStringData dtoa(double number) @@ -370,13 +372,13 @@ ASCIIStringData dtoa(double number) const int decimal_in_shortest_high_ = 21; if ((decimal_in_shortest_low_ <= exponent) && (exponent < decimal_in_shortest_high_)) { - CreateDecimalRepresentation(flags, decimal_rep, decimal_rep_length, - decimal_point, - double_conversion::Max(0, decimal_rep_length - decimal_point), - &builder); + CreateDecimalRepresentation(flags, decimal_rep, decimal_rep_length, + decimal_point, + double_conversion::Max(0, decimal_rep_length - decimal_point), + &builder); } else { CreateExponentialRepresentation(flags, decimal_rep, decimal_rep_length, exponent, - &builder); + &builder); } ASCIIStringDataNonGCStd str; if (sign) @@ -421,6 +423,4 @@ int String::stringCompare(size_t l1, size_t l2, const String* c1, const String* return (l1 > l2) ? 1 : -1; } - - } diff --git a/src/runtime/String.h b/src/runtime/String.h index 54e545931..22636e038 100644 --- a/src/runtime/String.h +++ b/src/runtime/String.h @@ -1,16 +1,16 @@ #ifndef __EscargotString__ #define __EscargotString__ -#include #include "runtime/PointerValue.h" #include "util/BasicString.h" +#include namespace Escargot { -typedef BasicString > ASCIIStringData; -typedef BasicString > UTF8StringData; -typedef BasicString > UTF16StringData; -typedef BasicString > UTF32StringData; +typedef BasicString> ASCIIStringData; +typedef BasicString> UTF8StringData; +typedef BasicString> UTF16StringData; +typedef BasicString> UTF32StringData; typedef std::basic_string> ASCIIStringDataNonGCStd; typedef std::basic_string> UTF8StringDataNonGCStd; @@ -22,6 +22,7 @@ class UTF16String; class String : public PointerValue { friend class AtomicString; + public: virtual Type type() { @@ -71,7 +72,7 @@ class String : public PointerValue { return false; } - for (size_t i = 0; i < srcLen; i ++) { + for (size_t i = 0; i < srcLen; i++) { if (src->charAt(i) != charAt(i)) { return false; } @@ -87,7 +88,7 @@ class String : public PointerValue { return false; } - for (size_t i = 0; i < srcLen; i ++) { + for (size_t i = 0; i < srcLen; i++) { if (src[i] != charAt(i)) { return false; } @@ -103,13 +104,13 @@ class String : public PointerValue { bool operator!=(const String& src) const { - return !operator ==(src); + return !operator==(src); } - ALWAYS_INLINE friend bool operator <(const String& a, const String& b); - ALWAYS_INLINE friend bool operator <= (const String& a, const String& b); - ALWAYS_INLINE friend bool operator >(const String& a, const String& b); - ALWAYS_INLINE friend bool operator >= (const String& a, const String& b); + ALWAYS_INLINE friend bool operator<(const String& a, const String& b); + ALWAYS_INLINE friend bool operator<=(const String& a, const String& b); + ALWAYS_INLINE friend bool operator>(const String& a, const String& b); + ALWAYS_INLINE friend bool operator>=(const String& a, const String& b); // NOTE these function generates new copy of string data virtual UTF16StringData toUTF16StringData() const = 0; @@ -126,28 +127,29 @@ class String : public PointerValue { static int stringCompare(size_t l1, size_t l2, const String* c1, const String* c2); }; -inline bool operator <(const String& a, const String& b) +inline bool operator<(const String& a, const String& b) { return String::stringCompare(a.length(), b.length(), &a, &b) < 0; } -inline bool operator >(const String& a, const String& b) +inline bool operator>(const String& a, const String& b) { return String::stringCompare(a.length(), b.length(), &a, &b) > 0; } -inline bool operator <= (const String& a, const String& b) +inline bool operator<=(const String& a, const String& b) { return String::stringCompare(a.length(), b.length(), &a, &b) <= 0; } -inline bool operator >= (const String& a, const String& b) +inline bool operator>=(const String& a, const String& b) { return String::stringCompare(a.length(), b.length(), &a, &b) >= 0; } class ASCIIString : public String { friend class String; + public: virtual bool isASCIIString() { @@ -196,6 +198,7 @@ class ASCIIString : public String { class UTF16String : public String { friend class String; + public: virtual bool hasASCIIContent() { @@ -211,7 +214,6 @@ class UTF16String : public String { UTF16String(const char16_t* str, size_t len) : String() { - m_stringData.append(str, len); } @@ -262,11 +264,9 @@ inline String* fromCharCode(char32_t code) return new UTF16String(buf, 2); } } - } -#include "runtime/StringView.h" #include "runtime/RopeString.h" #include "runtime/StringBuilder.h" +#include "runtime/StringView.h" #endif - diff --git a/src/runtime/StringBuilder.cpp b/src/runtime/StringBuilder.cpp index 747e8a618..29a5cdc19 100644 --- a/src/runtime/StringBuilder.cpp +++ b/src/runtime/StringBuilder.cpp @@ -30,20 +30,20 @@ String* StringBuilder::finalize() ret.resizeWithUninitializedValues(m_contentLength); size_t currentLength = 0; - for (size_t i = 0; i < m_piecesInlineStorageUsage; i ++) { + for (size_t i = 0; i < m_piecesInlineStorageUsage; i++) { String* data = m_piecesInlineStorage[i].m_string; size_t s = m_piecesInlineStorage[i].m_start; size_t e = m_piecesInlineStorage[i].m_end; - for (size_t j = s; j < e; j ++) { + for (size_t j = s; j < e; j++) { ret[currentLength++] = data->charAt(j); } } - for (size_t i = 0; i < m_pieces.size(); i ++) { + for (size_t i = 0; i < m_pieces.size(); i++) { String* data = m_pieces[i].m_string; size_t s = m_pieces[i].m_start; size_t e = m_pieces[i].m_end; - for (size_t j = s; j < e; j ++) { + for (size_t j = s; j < e; j++) { ret[currentLength++] = data->charAt(j); } } @@ -54,20 +54,20 @@ String* StringBuilder::finalize() ret.resizeWithUninitializedValues(m_contentLength); size_t currentLength = 0; - for (size_t i = 0; i < m_piecesInlineStorageUsage; i ++) { + for (size_t i = 0; i < m_piecesInlineStorageUsage; i++) { String* data = m_piecesInlineStorage[i].m_string; size_t s = m_piecesInlineStorage[i].m_start; size_t e = m_piecesInlineStorage[i].m_end; - for (size_t j = s; j < e; j ++) { + for (size_t j = s; j < e; j++) { ret[currentLength++] = data->charAt(j); } } - for (size_t i = 0; i < m_pieces.size(); i ++) { + for (size_t i = 0; i < m_pieces.size(); i++) { String* data = m_pieces[i].m_string; size_t s = m_pieces[i].m_start; size_t e = m_pieces[i].m_end; - for (size_t j = s; j < e; j ++) { + for (size_t j = s; j < e; j++) { ret[currentLength++] = data->charAt(j); } } @@ -75,6 +75,4 @@ String* StringBuilder::finalize() return new UTF16String(std::move(ret)); } } - } - diff --git a/src/runtime/StringBuilder.h b/src/runtime/StringBuilder.h index 33f9419eb..ff4e0d932 100644 --- a/src/runtime/StringBuilder.h +++ b/src/runtime/StringBuilder.h @@ -14,6 +14,7 @@ class StringBuilder { }; void appendPiece(String* str, size_t s, size_t e); + public: StringBuilder() { @@ -23,7 +24,6 @@ class StringBuilder { } size_t contentLength() { return m_contentLength; } - void appendString(const char* str) { appendPiece(new ASCIIString(str), 0, strlen(str)); @@ -46,6 +46,7 @@ class StringBuilder { } String* finalize(); + protected: bool m_hasASCIIContent; size_t m_piecesInlineStorageUsage; @@ -53,8 +54,6 @@ class StringBuilder { StringBuilderPiece m_piecesInlineStorage[ESCARGOT_STRING_BUILDER_INLINE_STORAGE_MAX]; std::vector> m_pieces; }; - } #endif - diff --git a/src/runtime/StringObject.cpp b/src/runtime/StringObject.cpp index 8a2c56b05..11bbf2f0b 100644 --- a/src/runtime/StringObject.cpp +++ b/src/runtime/StringObject.cpp @@ -10,5 +10,4 @@ StringObject::StringObject(ExecutionState& state, String* value) { setPrototype(state, state.context()->globalObject()->stringPrototype()); } - } diff --git a/src/runtime/StringObject.h b/src/runtime/StringObject.h index e8565e63f..dfcfb6829 100644 --- a/src/runtime/StringObject.h +++ b/src/runtime/StringObject.h @@ -18,10 +18,10 @@ class StringObject : public Object { { return true; } + protected: String* m_primitiveValue; }; - } #endif diff --git a/src/runtime/StringView.h b/src/runtime/StringView.h index 971a72b61..eb1fa79ba 100644 --- a/src/runtime/StringView.h +++ b/src/runtime/StringView.h @@ -38,14 +38,14 @@ class StringView : public String { return m_end - m_start; } - bool operator== (const char* src) const + bool operator==(const char* src) const { size_t srcLen = strlen(src); if (srcLen != length()) { return false; } - for (size_t i = 0; i < srcLen; i ++) { + for (size_t i = 0; i < srcLen; i++) { if (src[i] != charAt(i)) { return false; } @@ -54,9 +54,9 @@ class StringView : public String { return true; } - bool operator!= (const char* src) const + bool operator!=(const char* src) const { - return !operator ==(src); + return !operator==(src); } virtual UTF16StringData toUTF16StringData() const @@ -65,7 +65,7 @@ class StringView : public String { size_t len = length(); ret.resizeWithUninitializedValues(len); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { ret[i] = charAt(i); } @@ -103,9 +103,6 @@ class StringView : public String { String* m_string; size_t m_start, m_end; }; - - } #endif - diff --git a/src/runtime/VMInstance.cpp b/src/runtime/VMInstance.cpp index 97a8b37aa..d2c9040b1 100644 --- a/src/runtime/VMInstance.cpp +++ b/src/runtime/VMInstance.cpp @@ -6,6 +6,4 @@ namespace Escargot { VMInstance::VMInstance() { } - - } diff --git a/src/runtime/VMInstance.h b/src/runtime/VMInstance.h index bfb210f68..4c2c7933c 100644 --- a/src/runtime/VMInstance.h +++ b/src/runtime/VMInstance.h @@ -8,9 +8,9 @@ namespace Escargot { class VMInstance : public gc { public: VMInstance(); + protected: }; - } #endif diff --git a/src/runtime/Value.cpp b/src/runtime/Value.cpp index 64110f027..8a0708b60 100644 --- a/src/runtime/Value.cpp +++ b/src/runtime/Value.cpp @@ -16,39 +16,39 @@ namespace Escargot { String* Value::toStringSlowCase(ExecutionState& ec) const // $7.1.12 ToString { ASSERT(!isString()); - if (isInt32()) { - int num = asInt32(); - if (num >= 0 && num < ESCARGOT_STRINGS_NUMBERS_MAX) - return ec.context()->staticStrings().numbers[num].string(); + if (isInt32()) { + int num = asInt32(); + if (num >= 0 && num < ESCARGOT_STRINGS_NUMBERS_MAX) + return ec.context()->staticStrings().numbers[num].string(); - return String::fromInt32(num); - } else if (isNumber()) { - double d = asNumber(); - if (std::isnan(d)) - return ec.context()->staticStrings().NaN.string(); - if (std::isinf(d)) { - if (std::signbit(d)) - return ec.context()->staticStrings().NegativeInfinity.string(); - else - return ec.context()->staticStrings().Infinity.string(); - } - // convert -0.0 into 0.0 - // in c++, d = -0.0, d == 0.0 is true - if (d == 0.0) - d = 0; - return String::fromDouble(d); - } else if (isUndefined()) { - return ec.context()->staticStrings().undefined.string(); - } else if (isNull()) { - return ec.context()->staticStrings().null.string(); - } else if (isBoolean()) { - if (asBoolean()) - return ec.context()->staticStrings().stringTrue.string(); - else - return ec.context()->staticStrings().stringFalse.string(); - } else { - return toPrimitive(ec, PreferString).toString(ec); - } + return String::fromInt32(num); + } else if (isNumber()) { + double d = asNumber(); + if (std::isnan(d)) + return ec.context()->staticStrings().NaN.string(); + if (std::isinf(d)) { + if (std::signbit(d)) + return ec.context()->staticStrings().NegativeInfinity.string(); + else + return ec.context()->staticStrings().Infinity.string(); + } + // convert -0.0 into 0.0 + // in c++, d = -0.0, d == 0.0 is true + if (d == 0.0) + d = 0; + return String::fromDouble(d); + } else if (isUndefined()) { + return ec.context()->staticStrings().undefined.string(); + } else if (isNull()) { + return ec.context()->staticStrings().null.string(); + } else if (isBoolean()) { + if (asBoolean()) + return ec.context()->staticStrings().stringTrue.string(); + else + return ec.context()->staticStrings().stringFalse.string(); + } else { + return toPrimitive(ec, PreferString).toString(ec); + } } Object* Value::toObjectSlowCase(ExecutionState& state) const // $7.1.13 ToObject @@ -233,7 +233,7 @@ double Value::toNumberSlowCase(ExecutionState& state) const // $7.1.3 ToNumber char* buf; buf = ALLOCA(data->length() + 1, char, state); const size_t len = data->length(); - for (unsigned i = 0; i < len ; i ++) { + for (unsigned i = 0; i < len; i++) { char16_t c = data->charAt(i); if (c >= 128) c = 0; @@ -245,20 +245,40 @@ double Value::toNumberSlowCase(ExecutionState& state) const // $7.1.3 ToNumber return val; } double_conversion::StringToDoubleConverter converter(double_conversion::StringToDoubleConverter::ALLOW_HEX - | double_conversion::StringToDoubleConverter::ALLOW_LEADING_SPACES - | double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES, 0.0, double_conversion::Double::NaN(), - "Infinity", "NaN"); + | double_conversion::StringToDoubleConverter::ALLOW_LEADING_SPACES + | double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES, + 0.0, double_conversion::Double::NaN(), + "Infinity", "NaN"); val = converter.StringToDouble(buf, len, &end); if (static_cast(end) != len) { - auto isSpace = [] (char16_t c) -> bool { + auto isSpace = [](char16_t c) -> bool { switch (c) { - case 0x0009: case 0x000A: case 0x000B: case 0x000C: - case 0x000D: case 0x0020: case 0x00A0: case 0x1680: - case 0x180E: case 0x2000: case 0x2001: case 0x2002: - case 0x2003: case 0x2004: case 0x2005: case 0x2006: - case 0x2007: case 0x2008: case 0x2009: case 0x200A: - case 0x2028: case 0x2029: case 0x202F: case 0x205F: - case 0x3000: case 0xFEFF: + case 0x0009: + case 0x000A: + case 0x000B: + case 0x000C: + case 0x000D: + case 0x0020: + case 0x00A0: + case 0x1680: + case 0x180E: + case 0x2000: + case 0x2001: + case 0x2002: + case 0x2003: + case 0x2004: + case 0x2005: + case 0x2006: + case 0x2007: + case 0x2008: + case 0x2009: + case 0x200A: + case 0x2028: + case 0x2029: + case 0x202F: + case 0x205F: + case 0x3000: + case 0xFEFF: return true; default: return false; @@ -266,9 +286,12 @@ double Value::toNumberSlowCase(ExecutionState& state) const // $7.1.3 ToNumber }; unsigned ptr = 0; - enum State { Initial, ReadingNumber, DoneReadingNumber, Invalid }; + enum State { Initial, + ReadingNumber, + DoneReadingNumber, + Invalid }; State state = State::Initial; - for (unsigned i = 0; i < len; i ++) { + for (unsigned i = 0; i < len; i++) { switch (state) { case Initial: if (isSpace(data->charAt(i))) @@ -345,5 +368,4 @@ int32_t Value::toInt32SlowCase(ExecutionState& state) const // $7.1.5 ToInt32 // but testing 'bits' is likely faster) invert the result appropriately. return bits < 0 ? -result : result; } - } diff --git a/src/runtime/Value.h b/src/runtime/Value.h index 9950c6749..79acfe40d 100644 --- a/src/runtime/Value.h +++ b/src/runtime/Value.h @@ -46,7 +46,7 @@ union ValueDescriptor { } asBits; }; -template +template inline ToType bitwise_cast(FromType from) { ASSERT(sizeof(FromType) == sizeof(ToType)); @@ -67,14 +67,14 @@ inline ToType bitwise_cast(FromType from) class Value { public: #ifdef ESCARGOT_32 - enum { Int32Tag = 0xffffffff }; - enum { BooleanTag = 0xfffffffe }; - enum { NullTag = 0xfffffffd }; - enum { UndefinedTag = 0xfffffffc }; - enum { PointerTag = 0xfffffffb }; - enum { EmptyValueTag = 0xfffffffa }; + enum { Int32Tag = 0xffffffff }; + enum { BooleanTag = 0xfffffffe }; + enum { NullTag = 0xfffffffd }; + enum { UndefinedTag = 0xfffffffc }; + enum { PointerTag = 0xfffffffb }; + enum { EmptyValueTag = 0xfffffffa }; enum { DeletedValueTag = 0xfffffff9 }; - enum { LowestTag = DeletedValueTag }; + enum { LowestTag = DeletedValueTag }; #endif enum NullInitTag { Null }; @@ -154,7 +154,8 @@ class Value { bool isObject() const; bool isIterable() const; - enum PrimitiveTypeHint { PreferString, PreferNumber }; + enum PrimitiveTypeHint { PreferString, + PreferNumber }; Value toPrimitive(ExecutionState& ec, PrimitiveTypeHint = PreferNumber) const; // $7.1.1 ToPrimitive inline bool toBoolean(ExecutionState& ec) const; // $7.1.2 ToBoolean double toNumber(ExecutionState& ec) const; // $7.1.3 ToNumber @@ -183,34 +184,34 @@ class Value { uint32_t tag() const; int32_t payload() const; #elif ESCARGOT_64 - // These values are #defines since using static const integers here is a ~1% regression! +// These values are #defines since using static const integers here is a ~1% regression! - // This value is 2^48, used to encode doubles such that the encoded value will begin - // with a 16-bit pattern within the range 0x0001..0xFFFE. +// This value is 2^48, used to encode doubles such that the encoded value will begin +// with a 16-bit pattern within the range 0x0001..0xFFFE. #define DoubleEncodeOffset 0x1000000000000ll - // If all bits in the mask are set, this indicates an integer number, - // if any but not all are set this value is a double precision number. +// If all bits in the mask are set, this indicates an integer number, +// if any but not all are set this value is a double precision number. #define TagTypeNumber 0xffff000000000000ll - // All non-numeric (bool, null, undefined) immediates have bit 2 set. +// All non-numeric (bool, null, undefined) immediates have bit 2 set. #define TagBitTypeOther 0x2ll -#define TagBitBool 0x4ll +#define TagBitBool 0x4ll #define TagBitUndefined 0x8ll - // Combined integer value for non-numeric immediates. -#define ValueFalse (TagBitTypeOther | TagBitBool | false) -#define ValueTrue (TagBitTypeOther | TagBitBool | true) +// Combined integer value for non-numeric immediates. +#define ValueFalse (TagBitTypeOther | TagBitBool | false) +#define ValueTrue (TagBitTypeOther | TagBitBool | true) #define ValueUndefined (TagBitTypeOther | TagBitUndefined) -#define ValueNull (TagBitTypeOther) +#define ValueNull (TagBitTypeOther) - // TagMask is used to check for all types of immediate values (either number or 'other'). +// TagMask is used to check for all types of immediate values (either number or 'other'). #define TagMask (TagTypeNumber | TagBitTypeOther) - // These special values are never visible to JavaScript code; Empty is used to represent - // Array holes, and for uninitialized ESValues. Deleted is used in hash table code. - // These values would map to cell types in the ESValue encoding, but not valid GC cell - // pointer should have either of these values (Empty is null, deleted is at an invalid - // alignment for a GC cell, and in the zero page). -#define ValueEmpty 0x0ll +// These special values are never visible to JavaScript code; Empty is used to represent +// Array holes, and for uninitialized ESValues. Deleted is used in hash table code. +// These values would map to cell types in the ESValue encoding, but not valid GC cell +// pointer should have either of these values (Empty is null, deleted is at an invalid +// alignment for a GC cell, and in the zero page). +#define ValueEmpty 0x0ll #define ValueDeleted 0x4ll #endif @@ -223,12 +224,11 @@ class Value { Value toPrimitiveSlowCase(ExecutionState& ec, PrimitiveTypeHint) const; // $7.1.1 ToPrimitive int32_t toInt32SlowCase(ExecutionState& ec) const; // $7.1.5 ToInt32 }; - } +#include "runtime/Object.h" #include "runtime/PointerValue.h" #include "runtime/String.h" -#include "runtime/Object.h" #include "runtime/ValueInlines.h" namespace Escargot { diff --git a/src/runtime/ValueInlines.h b/src/runtime/ValueInlines.h index 0f9f9353f..e5eab49a1 100644 --- a/src/runtime/ValueInlines.h +++ b/src/runtime/ValueInlines.h @@ -30,7 +30,6 @@ inline double FastI2D(int x) inline Value::Value(ForceUninitializedTag) { - } inline Value::Value() @@ -327,7 +326,7 @@ inline bool Value::isInt32() const { #ifdef CARGOT_LITTLE_ENDIAN ASSERT(sizeof(short) == 2); - unsigned short* firstByte = (unsigned short *)&u.asInt64; + unsigned short* firstByte = (unsigned short*)&u.asInt64; return firstByte[3] == 0xffff; #else return (u.asInt64 & TagTypeNumber) == TagTypeNumber; @@ -371,7 +370,7 @@ inline bool Value::isNumber() const { #ifdef CARGOT_LITTLE_ENDIAN ASSERT(sizeof(short) == 2); - unsigned short* firstByte = (unsigned short *)&u.asInt64; + unsigned short* firstByte = (unsigned short*)&u.asInt64; return firstByte[3]; #else return u.asInt64 & TagTypeNumber; @@ -552,7 +551,7 @@ inline FunctionObject* Value::asFunction() const inline double Value::toNumber(ExecutionState& state) const { - // http://www.ecma-international.org/ecma-262/6.0/#sec-tonumber +// http://www.ecma-international.org/ecma-262/6.0/#sec-tonumber #ifdef ESCARGOT_64 auto n = u.asInt64 & TagTypeNumber; if (LIKELY(n)) { @@ -573,7 +572,7 @@ inline double Value::toNumber(ExecutionState& state) const else if (isNull()) return 0; else if (isBoolean()) - return asBoolean() ? 1 : 0; + return asBoolean() ? 1 : 0; else { return toNumberSlowCase(state); } @@ -659,7 +658,6 @@ inline uint32_t Value::toUint32(ExecutionState& state) const // http://www.ecma- { return toInt32(state); } - } #endif diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index ef60a69d0..a8e8c0430 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -25,7 +25,7 @@ void __attribute__((optimize("O0"))) fillStack(size_t siz) { volatile char a[siz]; - for (unsigned i = 0 ; i < siz ; i ++) { + for (unsigned i = 0; i < siz; i++) { a[i] = 0x00; } } @@ -33,7 +33,7 @@ void __attribute__((optimize("O0"))) fillStack(size_t siz) #ifdef PROFILE_MASSIF std::unordered_map g_addressTable; -std::vector g_freeList; +std::vector g_freeList; void unregisterGCAddress(void* address) { @@ -127,7 +127,7 @@ void eval(Escargot::Context* context, Escargot::String* str, Escargot::String* f puts(resultValue.result.toString(state)->toUTF8StringData().data()); } else { puts(resultValue.error.errorValue.toString(state)->toUTF8StringData().data()); - for (size_t i = 0; i < resultValue.error.stackTrace.size(); i ++) { + for (size_t i = 0; i < resultValue.error.stackTrace.size(); i++) { printf("%s (%d:%d)\n", resultValue.error.stackTrace[i].fileName->toUTF8StringData().data(), (int)resultValue.error.stackTrace[i].line, (int)resultValue.error.stackTrace[i].column); } } @@ -150,11 +150,10 @@ int main(int argc, char* argv[]) */ GC_set_free_space_divisor(24); GC_set_force_unmap_on_gcollect(1); - // GC_set_full_freq(1); - // GC_set_time_limit(GC_TIME_UNLIMITED); +// GC_set_full_freq(1); +// GC_set_time_limit(GC_TIME_UNLIMITED); #ifdef PROFILE_MASSIF - GC_is_valid_displacement_print_proc = [](void* ptr) - { + GC_is_valid_displacement_print_proc = [](void* ptr) { g_freeList.push_back(ptr); }; GC_set_on_collection_event([](GC_EventType evtType) { @@ -165,7 +164,7 @@ int main(int argc, char* argv[]) iter++; } - for (unsigned i = 0; i < g_freeList.size(); i ++) { + for (unsigned i = 0; i < g_freeList.size(); i++) { unregisterGCAddress(g_freeList[i]); } @@ -183,7 +182,7 @@ int main(int argc, char* argv[]) bool runShell = true; - for (int i = 1; i < argc; i ++) { + for (int i = 1; i < argc; i++) { FILE* fp = fopen(argv[i], "r"); if (fp) { runShell = false; @@ -195,7 +194,7 @@ int main(int argc, char* argv[]) fclose(fp); Escargot::String* src = new Escargot::UTF16String(std::move(Escargot::utf8StringToUTF16String(str.data(), str.length()))); - eval(context, src, Escargot::String::fromUTF8(argv[i], strlen(argv[i])),false); + eval(context, src, Escargot::String::fromUTF8(argv[i], strlen(argv[i])), false); } if (strcmp(argv[i], "--shell") == 0) { runShell = true; @@ -211,7 +210,7 @@ int main(int argc, char* argv[]) return 3; } Escargot::String* str = new Escargot::UTF16String(std::move(Escargot::utf8StringToUTF16String(buf, strlen(buf)))); - eval(context, str, Escargot::String::fromUTF8("from shell input", strlen("from shell input")),true); + eval(context, str, Escargot::String::fromUTF8("from shell input", strlen("from shell input")), true); } delete context; diff --git a/src/util/BasicString.cpp b/src/util/BasicString.cpp index 5573a7ad5..f09553bf8 100644 --- a/src/util/BasicString.cpp +++ b/src/util/BasicString.cpp @@ -2,5 +2,4 @@ #include "BasicString.h" namespace Escargot { - } diff --git a/src/util/BasicString.h b/src/util/BasicString.h index e82b3494e..316c7f826 100644 --- a/src/util/BasicString.h +++ b/src/util/BasicString.h @@ -10,6 +10,7 @@ class BasicString : public gc { m_buffer = allocate(0); m_size = 0; } + public: BasicString() { @@ -91,11 +92,11 @@ class BasicString : public gc { { ASSERT(pos < m_size); T* newBuffer = allocate(m_size + 1); - for (size_t i = 0; i < pos; i ++) { + for (size_t i = 0; i < pos; i++) { newBuffer[i] = m_buffer[i]; } newBuffer[pos] = val; - for (size_t i = pos; i < m_size; i ++) { + for (size_t i = pos; i < m_size; i++) { newBuffer[i + 1] = m_buffer[i]; } if (!m_buffer) @@ -118,11 +119,11 @@ class BasicString : public gc { size_t c = end - start; if (m_size - c) { T* newBuffer = allocate(m_size - c); - for (size_t i = 0; i < start; i ++) { + for (size_t i = 0; i < start; i++) { newBuffer[i] = m_buffer[i]; } - for (size_t i = end + c; i < m_size; i ++) { + for (size_t i = end + c; i < m_size; i++) { newBuffer[i - c] = m_buffer[i]; } @@ -160,7 +161,7 @@ class BasicString : public gc { void pop_back() { - erase(m_size - 1); + erase(m_size - 1); } T& operator[](const size_t& idx) @@ -197,7 +198,7 @@ class BasicString : public gc { if (newSize) { T* newBuffer = allocate(newSize); - for (size_t i = 0; i < m_size && i < newSize ; i ++) { + for (size_t i = 0; i < m_size && i < newSize; i++) { newBuffer[i] = m_buffer[i]; } @@ -214,7 +215,6 @@ class BasicString : public gc { } protected: - T* allocate(size_t siz) const { T* ret = Allocator().allocate(siz + 1); @@ -230,8 +230,6 @@ class BasicString : public gc { T* m_buffer; size_t m_size; }; - - } #endif diff --git a/src/util/Vector.cpp b/src/util/Vector.cpp index b9a7cef7d..82b22c2ed 100644 --- a/src/util/Vector.cpp +++ b/src/util/Vector.cpp @@ -5,5 +5,4 @@ namespace Escargot { const size_t VectorUtil::invalidIndex = SIZE_MAX; - } diff --git a/src/util/Vector.h b/src/util/Vector.h index 8d1a43f70..f0074f65e 100644 --- a/src/util/Vector.h +++ b/src/util/Vector.h @@ -32,7 +32,7 @@ class Vector : public gc { if (other.size()) { m_size = other.size(); m_buffer = Allocator().allocate(m_size); - for (size_t i = 0; i < m_size; i ++) { + for (size_t i = 0; i < m_size; i++) { m_buffer[i] = other[i]; } } else { @@ -46,7 +46,7 @@ class Vector : public gc { if (other.size()) { m_size = other.size(); m_buffer = Allocator().allocate(m_size); - for (size_t i = 0; i < m_size; i ++) { + for (size_t i = 0; i < m_size; i++) { m_buffer[i] = other[i]; } } else { @@ -59,7 +59,7 @@ class Vector : public gc { { m_size = other.size() + 1; m_buffer = Allocator().allocate(m_size); - for (size_t i = 0; i < other.size(); i ++) { + for (size_t i = 0; i < other.size(); i++) { m_buffer[i] = other[i]; } m_buffer[other.size()] = newItem; @@ -79,7 +79,7 @@ class Vector : public gc { void pushBack(const T& val) { T* newBuffer = Allocator().allocate(m_size + 1); - for (size_t i = 0; i < m_size; i ++) { + for (size_t i = 0; i < m_size; i++) { newBuffer[i] = m_buffer[i]; } newBuffer[m_size] = val; @@ -98,11 +98,11 @@ class Vector : public gc { { ASSERT(pos <= m_size); T* newBuffer = Allocator().allocate(m_size + 1); - for (size_t i = 0; i < pos; i ++) { + for (size_t i = 0; i < pos; i++) { newBuffer[i] = m_buffer[i]; } newBuffer[pos] = val; - for (size_t i = pos; i < m_size; i ++) { + for (size_t i = pos; i < m_size; i++) { newBuffer[i + 1] = m_buffer[i]; } if (!m_buffer) @@ -125,11 +125,11 @@ class Vector : public gc { size_t c = end - start; if (m_size - c) { T* newBuffer = Allocator().allocate(m_size - c); - for (size_t i = 0; i < start; i ++) { + for (size_t i = 0; i < start; i++) { newBuffer[i] = m_buffer[i]; } - for (size_t i = end + c; i < m_size; i ++) { + for (size_t i = end + c; i < m_size; i++) { newBuffer[i - c] = m_buffer[i]; } @@ -162,7 +162,7 @@ class Vector : public gc { void pop_back() { - erase(m_size - 1); + erase(m_size - 1); } T& operator[](const size_t& idx) @@ -200,7 +200,7 @@ class Vector : public gc { if (newSize) { T* newBuffer = Allocator().allocate(newSize); - for (size_t i = 0; i < m_size && i < newSize ; i ++) { + for (size_t i = 0; i < m_size && i < newSize; i++) { newBuffer[i] = m_buffer[i]; } @@ -221,11 +221,11 @@ class Vector : public gc { if (newSize) { T* newBuffer = Allocator().allocate(newSize); - for (size_t i = 0; i < m_size && i < newSize ; i ++) { + for (size_t i = 0; i < m_size && i < newSize; i++) { newBuffer[i] = m_buffer[i]; } - for (size_t i = m_size; i < newSize ; i ++) { + for (size_t i = m_size; i < newSize; i++) { newBuffer[i] = val; } @@ -255,7 +255,7 @@ class VectorUtil { static size_t findInVector(const Vector& vector, const T& target) { size_t len = vector.size(); - for (size_t i = 0; i < len; i ++) { + for (size_t i = 0; i < len; i++) { if (vector[i] == target) { return i; } @@ -263,9 +263,7 @@ class VectorUtil { return invalidIndex; } - }; - } #endif