Commit 365e7d4b authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] refactor Type to expose the implementation pointer directly

Change-Id: I61a594e194082577135dbc82b2673bf477105ef3
Reviewed-on: https://chromium-review.googlesource.com/1046949
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53050}
parent f33575be
......@@ -3049,6 +3049,7 @@ if (current_toolchain == v8_snapshot_toolchain) {
"src/torque/ast-generator.cc",
"src/torque/ast-generator.h",
"src/torque/ast.h",
"src/torque/declarable.cc",
"src/torque/declarable.h",
"src/torque/declaration-visitor.cc",
"src/torque/declaration-visitor.h",
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fstream>
#include <iostream>
#include "src/torque/declarable.h"
namespace v8 {
namespace internal {
namespace torque {
bool Type::IsSubtypeOf(const Type* supertype) const {
const Type* subtype = this;
while (subtype != nullptr) {
if (subtype == supertype) return true;
subtype = subtype->parent();
}
return false;
}
std::string Type::GetGeneratedTNodeTypeName() const {
std::string result = GetGeneratedTypeName();
DCHECK_EQ(result.substr(0, 6), "TNode<");
result = result.substr(6, result.length() - 7);
return result;
}
} // namespace torque
} // namespace internal
} // namespace v8
......@@ -23,7 +23,7 @@ class Declarable {
public:
virtual ~Declarable() {}
enum Kind {
kTypeImpl,
kType,
kVariable,
kParameter,
kMacro,
......@@ -35,7 +35,7 @@ class Declarable {
};
explicit Declarable(Kind kind) : kind_(kind) {}
Kind kind() const { return kind_; }
bool IsTypeImpl() const { return kind() == kTypeImpl; }
bool IsType() const { return kind() == kType; }
bool IsMacro() const { return kind() == kMacro; }
bool IsBuiltin() const { return kind() == kBuiltin; }
bool IsRuntimeFunction() const { return kind() == kRuntimeFunction; }
......@@ -62,25 +62,40 @@ class Declarable {
} \
const char* type_name() const override { return #y; }
class TypeImpl : public Declarable {
class Type : public Declarable {
public:
DECLARE_DECLARABLE_BOILERPLATE(TypeImpl, type_impl);
TypeImpl(TypeImpl* parent, const std::string& name,
const std::string& generated_type)
: Declarable(Declarable::kTypeImpl),
DECLARE_DECLARABLE_BOILERPLATE(Type, type);
Type(const Type* parent, const std::string& name,
const std::string& generated_type)
: Declarable(Declarable::kType),
parent_(parent),
name_(name),
generated_type_(generated_type) {}
TypeImpl* parent() const { return parent_; }
const Type* parent() const { return parent_; }
const std::string& name() const { return name_; }
const std::string& generated_type() const { return generated_type_; }
const std::string& GetGeneratedTypeName() const { return generated_type_; }
std::string GetGeneratedTNodeTypeName() const;
bool IsSubtypeOf(const Type* supertype) const;
bool IsVoid() const { return name() == VOID_TYPE_STRING; }
bool IsNever() const { return name() == NEVER_TYPE_STRING; }
bool IsBool() const { return name() == BOOL_TYPE_STRING; }
bool IsVoidOrNever() const { return IsVoid() || IsNever(); }
bool IsConstexpr() const {
return name().substr(0, strlen(CONSTEXPR_TYPE_PREFIX)) ==
CONSTEXPR_TYPE_PREFIX;
}
private:
TypeImpl* parent_;
std::string name_;
std::string generated_type_;
const Type* const parent_;
const std::string name_;
const std::string generated_type_;
};
inline std::ostream& operator<<(std::ostream& os, const Type* t) {
os << t->name().c_str();
return os;
}
class Value : public Declarable {
public:
const std::string& name() const { return name_; }
......@@ -91,14 +106,14 @@ class Value : public Declarable {
}
virtual std::string GetValueForWrite() const { UNREACHABLE(); }
DECLARE_DECLARABLE_BOILERPLATE(Value, value);
Type type() const { return type_; }
const Type* type() const { return type_; }
protected:
Value(Kind kind, Type type, const std::string& name)
Value(Kind kind, const Type* type, const std::string& name)
: Declarable(kind), type_(type), name_(name) {}
private:
Type type_;
const Type* type_;
std::string name_;
};
......@@ -109,7 +124,8 @@ class Parameter : public Value {
private:
friend class Declarations;
Parameter(const std::string& name, Type type, const std::string& var_name)
Parameter(const std::string& name, const Type* type,
const std::string& var_name)
: Value(Declarable::kParameter, type, name), var_name_(var_name) {}
std::string var_name_;
......@@ -129,7 +145,7 @@ class Variable : public Value {
private:
friend class Declarations;
Variable(const std::string& name, const std::string& value, Type type)
Variable(const std::string& name, const std::string& value, const Type* type)
: Value(Declarable::kVariable, type, name),
value_(value),
defined_(false) {}
......@@ -173,7 +189,7 @@ class Constant : public Value {
private:
friend class Declarations;
explicit Constant(const std::string& name, Type type,
explicit Constant(const std::string& name, const Type* type,
const std::string& value)
: Value(Declarable::kConstant, type, name), value_(value) {}
......@@ -198,7 +214,7 @@ class Callable : public Declarable {
return signature_.parameter_names;
}
bool HasReturnValue() const {
return !signature_.return_type.IsVoidOrNever();
return !signature_.return_type->IsVoidOrNever();
}
void IncrementReturns() { ++returns_; }
bool HasReturns() const { return returns_; }
......
......@@ -64,7 +64,7 @@ void DeclarationVisitor::Visit(BuiltinDeclaration* decl) {
DeclareParameterList(decl->pos, signature, {});
if (signature.types().size() == 0 ||
!signature.types()[0].Is(CONTEXT_TYPE_STRING)) {
!(signature.types()[0]->name() == CONTEXT_TYPE_STRING)) {
std::stringstream stream;
stream << "first parameter to builtin " << decl->name
<< " is not a context but should be at "
......@@ -84,7 +84,7 @@ void DeclarationVisitor::Visit(BuiltinDeclaration* decl) {
}
if (javascript) {
if (signature.types().size() < 2 ||
!signature.types()[1].Is(OBJECT_TYPE_STRING)) {
!(signature.types()[1]->name() == OBJECT_TYPE_STRING)) {
std::stringstream stream;
stream << "second parameter to javascript builtin " << decl->name
<< " is not a receiver type but should be at "
......@@ -112,7 +112,7 @@ void DeclarationVisitor::Visit(MacroDeclaration* decl) {
DeclareParameterList(decl->pos, signature, decl->labels);
if (!signature.return_type.IsVoidOrNever()) {
if (!signature.return_type->IsVoidOrNever()) {
declarations()->DeclareVariable(decl->pos, kReturnValueVariable,
signature.return_type);
}
......
......@@ -25,8 +25,6 @@ class DeclarationVisitor : public FileVisitor {
explicit DeclarationVisitor(GlobalContext& global_context)
: FileVisitor(global_context),
scope_(declarations(), global_context.ast()->default_module()) {
declarations()->DeclareType(SourcePosition(), EXCEPTION_TYPE_STRING,
"Label*", nullptr);
}
void Visit(Ast* ast) { Visit(ast->default_module()); }
......@@ -97,7 +95,7 @@ class DeclarationVisitor : public FileVisitor {
MakeSignature(decl->pos, decl->parameters, decl->return_type, {});
if (signature.parameter_types.types.size() == 0 ||
!signature.parameter_types.types[0].Is(CONTEXT_TYPE_STRING)) {
!(signature.parameter_types.types[0]->name() == CONTEXT_TYPE_STRING)) {
std::stringstream stream;
stream << "first parameter to builtin " << decl->name
<< " is not a context but should be at "
......@@ -115,7 +113,7 @@ class DeclarationVisitor : public FileVisitor {
}
if (javascript) {
if (signature.types().size() < 2 ||
!signature.types()[1].Is(OBJECT_TYPE_STRING)) {
!(signature.types()[1]->name() == OBJECT_TYPE_STRING)) {
std::stringstream stream;
stream << "second parameter to javascript builtin " << decl->name
<< " is not a receiver type but should be at "
......@@ -135,11 +133,12 @@ class DeclarationVisitor : public FileVisitor {
<< " with signature ";
}
Type return_type = declarations()->LookupType(decl->pos, decl->return_type);
const Type* return_type =
declarations()->LookupType(decl->pos, decl->return_type);
TypeVector parameter_types =
GetTypeVector(decl->pos, decl->parameters.types);
if (parameter_types.size() == 0 ||
!parameter_types[0].Is(CONTEXT_TYPE_STRING)) {
!(parameter_types[0]->name() == CONTEXT_TYPE_STRING)) {
std::stringstream stream;
stream << "first parameter to runtime " << decl->name
<< " is not a context but should be at "
......@@ -208,7 +207,7 @@ class DeclarationVisitor : public FileVisitor {
void Visit(VarDeclarationStatement* stmt) {
std::string variable_name = stmt->name;
Type type = declarations()->LookupType(stmt->pos, stmt->type);
const Type* type = declarations()->LookupType(stmt->pos, stmt->type);
declarations()->DeclareVariable(stmt->pos, variable_name, type);
if (global_context_.verbose()) {
std::cout << "declared variable " << variable_name << " with type "
......
......@@ -29,15 +29,16 @@ void Declarations::CheckAlreadyDeclared(SourcePosition pos,
}
}
Type Declarations::LookupType(SourcePosition pos, const std::string& name) {
const Type* Declarations::LookupType(SourcePosition pos,
const std::string& name) {
Declarable* raw = Lookup(pos, name);
if (!raw->IsTypeImpl()) {
if (!raw->IsType()) {
std::stringstream s;
s << "declaration \"" << name << "\" is not a Type at "
<< PositionAsString(pos);
ReportError(s.str());
}
return Type(TypeImpl::cast(raw));
return Type::cast(raw);
}
Value* Declarations::LookupValue(SourcePosition pos, const std::string& name) {
......@@ -97,11 +98,12 @@ Builtin* Declarations::LookupBuiltin(SourcePosition pos,
return nullptr;
}
Type Declarations::DeclareType(SourcePosition pos, const std::string& name,
const std::string& generated,
const std::string* parent) {
const Type* Declarations::DeclareType(SourcePosition pos,
const std::string& name,
const std::string& generated,
const std::string* parent) {
CheckAlreadyDeclared(pos, name, "type");
TypeImpl* parent_type = nullptr;
const Type* parent_type = nullptr;
if (parent != nullptr) {
Declarable* maybe_parent_type = Lookup(*parent);
if (maybe_parent_type == nullptr) {
......@@ -110,18 +112,18 @@ Type Declarations::DeclareType(SourcePosition pos, const std::string& name,
<< PositionAsString(pos);
ReportError(s.str());
}
if (!maybe_parent_type->IsTypeImpl()) {
if (!maybe_parent_type->IsType()) {
std::stringstream s;
s << "parent \"" << *parent << "\" of type \"" << name << "\""
<< " is not a type "
<< " at " << PositionAsString(pos);
ReportError(s.str());
}
parent_type = TypeImpl::cast(maybe_parent_type);
parent_type = Type::cast(maybe_parent_type);
}
TypeImpl* result = new TypeImpl(parent_type, name, generated);
Type* result = new Type(parent_type, name, generated);
Declare(name, std::unique_ptr<Declarable>(result));
return Type(result);
return result;
}
Label* Declarations::DeclareLabel(SourcePosition pos, const std::string& name) {
......@@ -180,7 +182,8 @@ RuntimeFunction* Declarations::DeclareRuntimeFunction(
}
Variable* Declarations::DeclareVariable(SourcePosition pos,
const std::string& var, Type type) {
const std::string& var,
const Type* type) {
std::string name(var + std::to_string(GetNextUniqueDeclarationNumber()));
CheckAlreadyDeclared(pos, var, "variable");
Variable* result = new Variable(var, name, type);
......@@ -191,7 +194,7 @@ Variable* Declarations::DeclareVariable(SourcePosition pos,
Parameter* Declarations::DeclareParameter(SourcePosition pos,
const std::string& name,
const std::string& var_name,
Type type) {
const Type* type) {
CheckAlreadyDeclared(pos, name, "parameter");
Parameter* result = new Parameter(name, type, var_name);
Declare(name, std::unique_ptr<Declarable>(result));
......@@ -209,7 +212,7 @@ Label* Declarations::DeclarePrivateLabel(SourcePosition pos,
}
void Declarations::DeclareConstant(SourcePosition pos, const std::string& name,
Type type, const std::string& value) {
const Type* type, const std::string& value) {
CheckAlreadyDeclared(pos, name, "constant, parameter or arguments");
Constant* result = new Constant(name, type, value);
Declare(name, std::unique_ptr<Declarable>(result));
......
......@@ -31,7 +31,7 @@ class Declarations {
return d;
}
Type LookupType(SourcePosition pos, const std::string& name);
const Type* LookupType(SourcePosition pos, const std::string& name);
Value* LookupValue(SourcePosition pos, const std::string& name);
......@@ -42,9 +42,9 @@ class Declarations {
Label* LookupLabel(SourcePosition pos, const std::string& name);
Type DeclareType(SourcePosition pos, const std::string& name,
const std::string& generated,
const std::string* parent = nullptr);
const Type* DeclareType(SourcePosition pos, const std::string& name,
const std::string& generated,
const std::string* parent = nullptr);
Label* DeclareLabel(SourcePosition pos, const std::string& name);
......@@ -59,15 +59,16 @@ class Declarations {
const Signature& signature);
Variable* DeclareVariable(SourcePosition pos, const std::string& var,
Type type);
const Type* type);
Parameter* DeclareParameter(SourcePosition pos, const std::string& name,
const std::string& mangled_name, Type type);
const std::string& mangled_name,
const Type* type);
Label* DeclarePrivateLabel(SourcePosition pos, const std::string& name);
void DeclareConstant(SourcePosition pos, const std::string& name, Type type,
const std::string& value);
void DeclareConstant(SourcePosition pos, const std::string& name,
const Type* type, const std::string& value);
std::set<const Variable*> GetLiveVariables() {
return chain_.GetLiveVariables();
......
......@@ -39,7 +39,7 @@ class OperationHandler {
public:
std::string macro_name;
ParameterTypes parameter_types;
Type result_type;
const Type* result_type;
};
struct SourceFileContext {
......
This diff is collapsed.
......@@ -34,7 +34,7 @@ class ImplementationVisitor : public FileVisitor {
void Visit(Ast* ast) { Visit(ast->default_module()); }
VisitResult Visit(Expression* expr);
Type Visit(Statement* stmt);
const Type* Visit(Statement* stmt);
void Visit(Declaration* decl);
LocationReference GetLocationReference(LocationExpression* location);
......@@ -105,7 +105,7 @@ class ImplementationVisitor : public FileVisitor {
void Visit(ExternalRuntimeDeclaration* decl) {}
VisitResult Visit(CallExpression* expr, bool is_tail = false);
Type Visit(TailCallStatement* stmt);
const Type* Visit(TailCallStatement* stmt);
VisitResult Visit(ConditionalExpression* expr);
......@@ -120,20 +120,20 @@ class ImplementationVisitor : public FileVisitor {
VisitResult Visit(StringLiteralExpression* expr);
VisitResult Visit(NumberLiteralExpression* expr);
Type Visit(TryCatchStatement* stmt);
Type Visit(ReturnStatement* stmt);
Type Visit(GotoStatement* stmt);
Type Visit(IfStatement* stmt);
Type Visit(WhileStatement* stmt);
Type Visit(BreakStatement* stmt);
Type Visit(ContinueStatement* stmt);
Type Visit(ForLoopStatement* stmt);
Type Visit(VarDeclarationStatement* stmt);
Type Visit(ForOfLoopStatement* stmt);
Type Visit(BlockStatement* block);
Type Visit(ExpressionStatement* stmt);
Type Visit(DebugStatement* stmt);
Type Visit(AssertStatement* stmt);
const Type* Visit(TryCatchStatement* stmt);
const Type* Visit(ReturnStatement* stmt);
const Type* Visit(GotoStatement* stmt);
const Type* Visit(IfStatement* stmt);
const Type* Visit(WhileStatement* stmt);
const Type* Visit(BreakStatement* stmt);
const Type* Visit(ContinueStatement* stmt);
const Type* Visit(ForLoopStatement* stmt);
const Type* Visit(VarDeclarationStatement* stmt);
const Type* Visit(ForOfLoopStatement* stmt);
const Type* Visit(BlockStatement* block);
const Type* Visit(ExpressionStatement* stmt);
const Type* Visit(DebugStatement* stmt);
const Type* Visit(AssertStatement* stmt);
void GenerateImplementation(const std::string& dir, Module* module);
......@@ -167,7 +167,8 @@ class ImplementationVisitor : public FileVisitor {
void GenerateChangedVarsFromControlSplit(AstNode* node);
Type GetCommonType(SourcePosition pos, Type left, Type right);
const Type* GetCommonType(SourcePosition pos, const Type* left,
const Type* right);
VisitResult GenerateCopy(const VisitResult& to_copy);
......@@ -179,7 +180,8 @@ class ImplementationVisitor : public FileVisitor {
VisitResult assignment_value);
Variable* GenerateVariableDeclaration(
AstNode* node, const std::string& name, const base::Optional<Type>& type,
AstNode* node, const std::string& name,
const base::Optional<const Type*>& type,
const base::Optional<VisitResult>& initialization = {});
void GenerateParameter(SourcePosition pos, const std::string& parameter_name);
......@@ -209,14 +211,15 @@ class ImplementationVisitor : public FileVisitor {
VisitResult GenerateOperation(SourcePosition pos,
const std::string& operation,
Arguments arguments,
base::Optional<Type> return_type = {});
base::Optional<const Type*> return_type = {});
VisitResult GenerateImplicitConvert(SourcePosition pos, Type destination_type,
VisitResult GenerateImplicitConvert(SourcePosition pos,
const Type* destination_type,
VisitResult source);
std::string NewTempVariable();
std::string GenerateNewTempVariable(Type type);
std::string GenerateNewTempVariable(const Type* type);
void GenerateLabelDefinition(Label* label, AstNode* node = nullptr);
......
......@@ -19,37 +19,41 @@ class TypeOracle {
explicit TypeOracle(Declarations* declarations)
: declarations_(declarations) {}
void RegisterImplicitConversion(Type to, Type from) {
void RegisterImplicitConversion(const Type* to, const Type* from) {
implicit_conversions_.push_back(std::make_pair(to, from));
}
Type GetArgumentsType() { return GetBuiltinType(ARGUMENTS_TYPE_STRING); }
const Type* GetArgumentsType() {
return GetBuiltinType(ARGUMENTS_TYPE_STRING);
}
Type GetBoolType() { return GetBuiltinType(BOOL_TYPE_STRING); }
const Type* GetBoolType() { return GetBuiltinType(BOOL_TYPE_STRING); }
Type GetConstexprBoolType() {
const Type* GetConstexprBoolType() {
return GetBuiltinType(CONSTEXPR_BOOL_TYPE_STRING);
}
Type GetVoidType() { return GetBuiltinType(VOID_TYPE_STRING); }
const Type* GetVoidType() { return GetBuiltinType(VOID_TYPE_STRING); }
Type GetObjectType() { return GetBuiltinType(OBJECT_TYPE_STRING); }
const Type* GetObjectType() { return GetBuiltinType(OBJECT_TYPE_STRING); }
Type GetStringType() { return GetBuiltinType(STRING_TYPE_STRING); }
const Type* GetStringType() { return GetBuiltinType(STRING_TYPE_STRING); }
Type GetIntPtrType() { return GetBuiltinType(INTPTR_TYPE_STRING); }
const Type* GetIntPtrType() { return GetBuiltinType(INTPTR_TYPE_STRING); }
Type GetNeverType() { return GetBuiltinType(NEVER_TYPE_STRING); }
const Type* GetNeverType() { return GetBuiltinType(NEVER_TYPE_STRING); }
Type GetConstInt31Type() { return GetBuiltinType(CONST_INT31_TYPE_STRING); }
const Type* GetConstInt31Type() {
return GetBuiltinType(CONST_INT31_TYPE_STRING);
}
bool IsAssignableFrom(Type to, Type from) {
bool IsAssignableFrom(const Type* to, const Type* from) {
if (to == from) return true;
if (to.IsSubclass(from) && !from.IsConstexpr()) return true;
if (from->IsSubtypeOf(to) && !from->IsConstexpr()) return true;
return IsImplicitlyConverableFrom(to, from);
}
bool IsImplicitlyConverableFrom(Type to, Type from) {
bool IsImplicitlyConverableFrom(const Type* to, const Type* from) {
for (auto& conversion : implicit_conversions_) {
if (conversion.first == to && conversion.second == from) {
return true;
......@@ -72,14 +76,14 @@ class TypeOracle {
}
private:
Type GetBuiltinType(const std::string& name) {
const Type* GetBuiltinType(const std::string& name) {
Declarable* declarable = declarations_->Lookup(name);
DCHECK(declarable != nullptr);
return Type(TypeImpl::cast(declarable));
return Type::cast(declarable);
}
Declarations* declarations_;
std::vector<std::pair<Type, Type>> implicit_conversions_;
std::vector<std::pair<const Type*, const Type*>> implicit_conversions_;
};
} // namespace torque
......
......@@ -12,31 +12,6 @@ namespace v8 {
namespace internal {
namespace torque {
bool Type::Is(const std::string& name) const { return name == impl_->name(); }
const std::string& Type::name() const { return impl_->name(); }
bool Type::IsSubclass(Type from) {
TypeImpl* to_class = type_impl();
TypeImpl* from_class = from.type_impl();
while (from_class != nullptr) {
if (to_class == from_class) return true;
from_class = from_class->parent();
}
return false;
}
const std::string& Type::GetGeneratedTypeName() const {
return type_impl()->generated_type();
}
std::string Type::GetGeneratedTNodeTypeName() const {
std::string result = type_impl()->generated_type();
DCHECK_EQ(result.substr(0, 6), "TNode<");
result = result.substr(6, result.length() - 7);
return result;
}
std::ostream& operator<<(std::ostream& os, const Signature& sig) {
os << "(";
for (size_t i = 0; i < sig.parameter_names.size(); ++i) {
......@@ -49,7 +24,7 @@ std::ostream& operator<<(std::ostream& os, const Signature& sig) {
os << "...";
}
os << ")";
if (!sig.return_type.IsVoid()) {
if (!sig.return_type->IsVoid()) {
os << ": " << sig.return_type;
}
return os;
......
......@@ -16,14 +16,11 @@ namespace torque {
static const char* const CONSTEXPR_TYPE_PREFIX = "constexpr ";
static const char* const NEVER_TYPE_STRING = "never";
static const char* const BRANCH_TYPE_STRING = "branch";
static const char* const CONSTEXPR_BOOL_TYPE_STRING = "constexpr bool";
static const char* const BOOL_TYPE_STRING = "bool";
static const char* const VOID_TYPE_STRING = "void";
static const char* const ARGUMENTS_TYPE_STRING = "Arguments";
static const char* const TAGGED_TYPE_STRING = "tagged";
static const char* const CONTEXT_TYPE_STRING = "Context";
static const char* const EXCEPTION_TYPE_STRING = "Exception";
static const char* const OBJECT_TYPE_STRING = "Object";
static const char* const STRING_TYPE_STRING = "String";
static const char* const INTPTR_TYPE_STRING = "intptr";
......@@ -32,61 +29,20 @@ static const char* const CONST_INT32_TYPE_STRING = "constexpr int32";
static const char* const CONST_FLOAT64_TYPE_STRING = "constexpr float64";
class Label;
class Type;
class TypeImpl;
typedef struct Type {
public:
Type() : impl_(nullptr) {}
Type(TypeImpl* type_impl) : impl_(type_impl) {}
bool operator==(const Type& other) const { return impl_ == other.impl_; }
bool operator!=(const Type& other) const { return impl_ != other.impl_; }
bool Is(const Type& other) const { return impl_ == other.impl_; }
bool Is(const std::string& name) const;
bool IsSubclass(Type from);
bool IsException() const { return name() == EXCEPTION_TYPE_STRING; }
bool IsVoid() const { return name() == VOID_TYPE_STRING; }
bool IsNever() const { return name() == NEVER_TYPE_STRING; }
bool IsBool() const { return name() == BOOL_TYPE_STRING; }
bool IsVoidOrNever() const { return IsVoid() || IsNever(); }
bool IsConstexpr() const {
return name().substr(0, strlen(CONSTEXPR_TYPE_PREFIX)) ==
CONSTEXPR_TYPE_PREFIX;
}
const std::string& name() const;
const std::string& GetGeneratedTypeName() const;
std::string GetGeneratedTNodeTypeName() const;
protected:
TypeImpl* type_impl() const { return impl_; }
private:
TypeImpl* impl_;
} Type;
inline std::ostream& operator<<(std::ostream& os, Type t) {
os << t.name().c_str();
return os;
}
using TypeVector = std::vector<Type>;
using TypeVector = std::vector<const Type*>;
class VisitResult {
public:
VisitResult() {}
VisitResult(Type type, const std::string& variable)
VisitResult(const Type* type, const std::string& variable)
: type_(type), variable_(variable) {}
Type type() const { return type_; }
const Type* type() const { return type_; }
const std::string& variable() const { return variable_; }
private:
Type type_;
const Type* type_;
std::string variable_;
};
......@@ -108,7 +64,7 @@ std::ostream& operator<<(std::ostream& os, const TypeVector& types);
struct NameAndType {
std::string name;
Type type;
const Type* type;
};
typedef std::vector<NameAndType> NameAndTypeVector;
......@@ -138,7 +94,7 @@ struct Signature {
const TypeVector& types() const { return parameter_types.types; }
NameVector parameter_names;
ParameterTypes parameter_types;
Type return_type;
const Type* return_type;
LabelDeclarationVector labels;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment