tint: IntrinsicTable: Use [[display]] name for type matchers
TypeMatcher::String() was not respecting the [[display]] decoration of the matcher's sub-types. By calling TypeMatcher::String() on the sub-types, we can display the custom type names in diagnostics. Bug: tint:1504 Change-Id: I0856fee31231f9c048d2e3028d25c4d261fbb008 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90529 Reviewed-by: David Neto <dneto@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
parent
0a63c6d2fb
commit
b1fa457ab3
|
@ -231,7 +231,7 @@ class TypeMatcher {
|
|||
|
||||
/// @return a string representation of the matcher. Used for printing error
|
||||
/// messages when no overload is found.
|
||||
virtual std::string String(MatchState& state) const = 0;
|
||||
virtual std::string String(MatchState* state) const = 0;
|
||||
};
|
||||
|
||||
/// A NumberMatcher is the interface used to match a number or enumerator used
|
||||
|
@ -249,7 +249,7 @@ class NumberMatcher {
|
|||
|
||||
/// @return a string representation of the matcher. Used for printing error
|
||||
/// messages when no overload is found.
|
||||
virtual std::string String(MatchState& state) const = 0;
|
||||
virtual std::string String(MatchState* state) const = 0;
|
||||
};
|
||||
|
||||
/// TemplateTypeMatcher is a Matcher for a template type.
|
||||
|
@ -270,7 +270,7 @@ class TemplateTypeMatcher : public TypeMatcher {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::string String(MatchState& state) const override;
|
||||
std::string String(MatchState* state) const override;
|
||||
|
||||
private:
|
||||
size_t index_;
|
||||
|
@ -290,7 +290,7 @@ class TemplateNumberMatcher : public NumberMatcher {
|
|||
return state.templates.Num(index_, number) ? number : Number::invalid;
|
||||
}
|
||||
|
||||
std::string String(MatchState& state) const override;
|
||||
std::string String(MatchState* state) const override;
|
||||
|
||||
private:
|
||||
size_t index_;
|
||||
|
@ -1008,12 +1008,12 @@ std::string CallSignature(ProgramBuilder& builder,
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
std::string TemplateTypeMatcher::String(MatchState& state) const {
|
||||
return state.overload->template_types[index_].name;
|
||||
std::string TemplateTypeMatcher::String(MatchState* state) const {
|
||||
return state->overload->template_types[index_].name;
|
||||
}
|
||||
|
||||
std::string TemplateNumberMatcher::String(MatchState& state) const {
|
||||
return state.overload->template_numbers[index_].name;
|
||||
std::string TemplateNumberMatcher::String(MatchState* state) const {
|
||||
return state->overload->template_numbers[index_].name;
|
||||
}
|
||||
|
||||
Impl::Impl(ProgramBuilder& b) : builder(b) {}
|
||||
|
@ -1477,13 +1477,13 @@ Number MatchState::Num(Number number) {
|
|||
std::string MatchState::TypeName() {
|
||||
MatcherIndex matcher_index = *matcher_indices_++;
|
||||
auto* matcher = matchers.type[matcher_index];
|
||||
return matcher->String(*this);
|
||||
return matcher->String(this);
|
||||
}
|
||||
|
||||
std::string MatchState::NumName() {
|
||||
MatcherIndex matcher_index = *matcher_indices_++;
|
||||
auto* matcher = matchers.number[matcher_index];
|
||||
return matcher->String(*this);
|
||||
return matcher->String(this);
|
||||
}
|
||||
|
||||
void Impl::ErrMultipleOverloadsMatched(size_t num_matched,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -188,7 +188,7 @@ class {{$class}} : public TypeMatcher {
|
|||
const sem::Type* type) const override;
|
||||
/// @param state the MatchState
|
||||
/// @return a string representation of the matcher.
|
||||
std::string String(MatchState& state) const override;
|
||||
std::string String(MatchState* state) const override;
|
||||
};
|
||||
|
||||
const sem::Type* {{$class}}::Match(MatchState& state, const sem::Type* ty) const {
|
||||
|
@ -207,7 +207,7 @@ const sem::Type* {{$class}}::Match(MatchState& state, const sem::Type* ty) const
|
|||
return build_{{TrimLeft .Name "_"}}(state{{range .TemplateParams}}, {{.GetName}}{{end}});
|
||||
}
|
||||
|
||||
std::string {{$class}}::String(MatchState&{{if .TemplateParams}} state{{end}}) const {
|
||||
std::string {{$class}}::String(MatchState*{{if .TemplateParams}} state{{end}}) const {
|
||||
{{- range .TemplateParams }}
|
||||
{{- template "DeclareLocalTemplateParamName" . }}
|
||||
{{- end }}
|
||||
|
@ -244,7 +244,7 @@ class {{$class}} : public TypeMatcher {
|
|||
const sem::Type* type) const override;
|
||||
/// @param state the MatchState
|
||||
/// @return a string representation of the matcher.
|
||||
std::string String(MatchState& state) const override;
|
||||
std::string String(MatchState* state) const override;
|
||||
};
|
||||
|
||||
const sem::Type* {{$class}}::Match(MatchState& state, const sem::Type* ty) const {
|
||||
|
@ -256,15 +256,18 @@ const sem::Type* {{$class}}::Match(MatchState& state, const sem::Type* ty) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::string {{$class}}::String(MatchState&) const {
|
||||
return "
|
||||
std::string {{$class}}::String(MatchState*) const {
|
||||
std::stringstream ss;
|
||||
// Note: We pass nullptr to the TypeMatcher::String() functions, as 'matcher's do not support
|
||||
// template arguments, nor can they match sub-types. As such, they have no use for the MatchState.
|
||||
ss
|
||||
{{- range .Types -}}
|
||||
{{- if IsFirstIn . $.Types }}{{.Name}}
|
||||
{{- else if IsLastIn . $.Types }} or {{.Name}}
|
||||
{{- else }}, {{.Name}}
|
||||
{{- if IsFirstIn . $.Types }} << {{PascalCase .Name}}().String(nullptr)
|
||||
{{- else if IsLastIn . $.Types }} << " or " << {{PascalCase .Name}}().String(nullptr)
|
||||
{{- else }} << ", " << {{PascalCase .Name}}().String(nullptr)
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
";
|
||||
{{- end -}};
|
||||
return ss.str();
|
||||
}
|
||||
{{ end -}}
|
||||
|
||||
|
@ -287,7 +290,7 @@ class {{$class}} : public NumberMatcher {
|
|||
Number Match(MatchState& state, Number number) const override;
|
||||
/// @param state the MatchState
|
||||
/// @return a string representation of the matcher.
|
||||
std::string String(MatchState& state) const override;
|
||||
std::string String(MatchState* state) const override;
|
||||
};
|
||||
|
||||
{{ if eq 1 (len .Options) -}}
|
||||
|
@ -312,7 +315,7 @@ Number {{$class}}::Match(MatchState&, Number number) const {
|
|||
}
|
||||
{{- end }}
|
||||
|
||||
std::string {{$class}}::String(MatchState&) const {
|
||||
std::string {{$class}}::String(MatchState*) const {
|
||||
return "
|
||||
{{- range .Options -}}
|
||||
{{- if IsFirstIn . $.Options }}{{.Name}}
|
||||
|
@ -405,11 +408,11 @@ Matchers::~Matchers() = default;
|
|||
{{- define "DeclareLocalTemplateParamName" -}}
|
||||
{{- /* ------------------------------------------------------------------ */ -}}
|
||||
{{- if IsTemplateTypeParam . }}
|
||||
const std::string {{.Name}} = state.TypeName();
|
||||
const std::string {{.Name}} = state->TypeName();
|
||||
{{- else if IsTemplateNumberParam . }}
|
||||
const std::string {{.Name}} = state.NumName();
|
||||
const std::string {{.Name}} = state->NumName();
|
||||
{{- else if IsTemplateEnumParam . }}
|
||||
const std::string {{.Name}} = state.NumName();
|
||||
const std::string {{.Name}} = state->NumName();
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue