Spicy
auto.h
1 // Copyright (c) 2020 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <memory>
6 #include <utility>
7 #include <vector>
8 
9 #include <hilti/ast/type.h>
10 #include <hilti/ast/types/unknown.h>
11 
12 namespace hilti {
13 namespace type {
14 
16 class Auto : public TypeBase,
22 public:
23  Auto(Meta m = Meta())
24  : TypeBase(std::move(m)),
25  _type(std::make_shared<std::shared_ptr<Node>>(std::make_shared<Node>(type::unknown))) {}
26 
27  const Type& type() const { return (*_type)->as<Type>(); }
28 
29  auto isSet() const { return ! (*_type)->isA<type::Unknown>(); }
30 
31  Node& typeNode() const { return **_type; }
32 
33  void linkTo(const Auto& other) { *_type = *other._type; }
34 
35  bool operator==(const Auto& other) const { return _type.get() == other._type.get(); }
36 
38  bool isEqual(const Type& other) const { return type() == other; }
40  Type effectiveType() const {
41  if ( isSet() )
42  return type();
43  else
44  return *this; // don't resolve yet
45  }
46 
47  std::vector<Node> typeParameters() const { return type().typeParameters(); }
48  bool isWildcard() const { return type().isWildcard(); }
49  Type iteratorType(bool const_) const { return type().iteratorType(const_); }
50  Type viewType() const { return type().viewType(); }
51  Type dereferencedType() const { return type().dereferencedType(); }
52  Type elementType() const { return type().elementType(); }
53 
55  auto properties() const { return node::Properties{{"resolves-to", Node(**_type).typename_()}}; }
56 
57 private:
58  std::shared_ptr<std::shared_ptr<Node>> _type;
59 };
60 
61 } // namespace type
62 } // namespace hilti
auto properties() const
Definition: auto.h:55
Definition: meta.h:18
Definition: type.h:25
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
Definition: type.h:152
Definition: type.h:33
Definition: node.h:97
Definition: auto.h:16
Definition: unknown.h:13
Type effectiveType() const
Definition: auto.h:40
bool isEqual(const Type &other) const
Definition: auto.h:38