74c28fb3cf1fc15b56da16b20a09e2d31df2166f
[platform/upstream/v8.git] / src / typing-asm.h
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_TYPING_ASM_H_
6 #define V8_TYPING_ASM_H_
7
8 #include "src/allocation.h"
9 #include "src/ast.h"
10 #include "src/effects.h"
11 #include "src/type-info.h"
12 #include "src/types.h"
13 #include "src/zone.h"
14
15 namespace v8 {
16 namespace internal {
17
18 class ZoneTypeCache;
19
20 class AsmTyper : public AstVisitor {
21  public:
22   explicit AsmTyper(Isolate* isolate, Zone* zone, Script* script,
23                     FunctionLiteral* root);
24   bool Validate();
25   const char* error_message() { return error_message_; }
26
27   DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
28
29  private:
30   Script* script_;
31   FunctionLiteral* root_;
32   bool valid_;
33
34   // Information for bi-directional typing with a cap on nesting depth.
35   Type* expected_type_;
36   Type* computed_type_;
37   int intish_;  // How many ops we've gone without a x|0.
38
39   Type* return_type_;  // Return type of last function.
40   size_t array_size_;  // Array size of last ArrayLiteral.
41
42   typedef ZoneMap<std::string, Type*> ObjectTypeMap;
43   ObjectTypeMap stdlib_types_;
44   ObjectTypeMap stdlib_heap_types_;
45   ObjectTypeMap stdlib_math_types_;
46
47   // Map from Variable* to global/local variable Type*.
48   ZoneHashMap global_variable_type_;
49   ZoneHashMap local_variable_type_;
50
51   bool in_function_;  // In module function?
52   bool building_function_tables_;
53
54   ZoneTypeCache const& cache_;
55
56   static const int kErrorMessageLimit = 100;
57   char error_message_[kErrorMessageLimit];
58
59   static const int kMaxUncombinedAdditiveSteps = 1 << 20;
60   static const int kMaxUncombinedMultiplicativeSteps = 1;
61
62   void InitializeStdlib();
63
64   void VisitDeclarations(ZoneList<Declaration*>* d) override;
65   void VisitStatements(ZoneList<Statement*>* s) override;
66
67   void VisitExpressionAnnotation(Expression* e);
68   void VisitFunctionAnnotation(FunctionLiteral* f);
69   void VisitAsmModule(FunctionLiteral* f);
70
71   void VisitHeapAccess(Property* expr);
72
73   int ElementShiftSize(Type* type);
74
75   void SetType(Variable* variable, Type* type);
76   Type* GetType(Variable* variable);
77
78   Type* LibType(ObjectTypeMap map, Handle<String> name);
79
80   void SetResult(Expression* expr, Type* type);
81   void IntersectResult(Expression* expr, Type* type);
82
83   void VisitWithExpectation(Expression* expr, Type* expected_type,
84                             const char* msg);
85
86 #define DECLARE_VISIT(type) virtual void Visit##type(type* node) override;
87   AST_NODE_LIST(DECLARE_VISIT)
88 #undef DECLARE_VISIT
89
90   DISALLOW_COPY_AND_ASSIGN(AsmTyper);
91 };
92 }
93 }  // namespace v8::internal
94
95 #endif  // V8_TYPING_ASM_H_