]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add ast validation checker
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 24 Oct 2023 14:08:00 +0000 (16:08 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:13:10 +0000 (19:13 +0100)
Add a new visitor to validate a given ast after the expansion pass.

gcc/rust/ChangeLog:

* Make-lang.in: Add the new object file the list.
* checks/errors/rust-ast-validation.cc: New file.
* checks/errors/rust-ast-validation.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/Make-lang.in
gcc/rust/checks/errors/rust-ast-validation.cc [new file with mode: 0644]
gcc/rust/checks/errors/rust-ast-validation.h [new file with mode: 0644]

index 1cba9466fdfe9bc8ee8d47fe4b44b9b6d1e09e6f..015b4333d3b242ed378b0b30bbcfbf6f678f5321 100644 (file)
@@ -189,6 +189,7 @@ GRS_OBJS = \
     rust/rust-builtins.o \
     rust/rust-feature.o \
     rust/rust-feature-gate.o \
+    rust/rust-ast-validation.o \
     rust/rust-dir-owner.o \
     rust/rust-unicode.o \
     rust/rust-punycode.o \
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc
new file mode 100644 (file)
index 0000000..199b2f9
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-ast-validation.h"
+
+namespace Rust {
+
+template <typename T>
+void
+ASTValidation::visit (T &node)
+{
+  node.accept_vis (*this);
+}
+
+template <typename T>
+void
+ASTValidation::visit (std::unique_ptr<T> &node)
+{
+  node->accept_vis (*this);
+}
+
+void
+ASTValidation::check (AST::Crate &crate)
+{
+  for (auto &item : crate.items)
+    {
+      visit (item);
+    }
+}
+
+void
+ASTValidation::visit (AST::InherentImpl &impl)
+{}
+
+} // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h
new file mode 100644 (file)
index 0000000..982a929
--- /dev/null
@@ -0,0 +1,194 @@
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_AST_VALIDATION_H
+#define RUST_AST_VALIDATION_H
+
+#include "rust-ast-visitor.h"
+#include "rust-ast-full.h"
+
+namespace Rust {
+
+class ASTValidation : public AST::ASTVisitor
+{
+public:
+  ASTValidation () {}
+
+  void check (AST::Crate &crate);
+
+  template <typename T> void visit (T &node);
+
+  template <typename T> void visit (std::unique_ptr<T> &node);
+
+  void visit (AST::Token &tok) override {}
+  void visit (AST::DelimTokenTree &delim_tok_tree) override {}
+  void visit (AST::AttrInputMetaItemContainer &input) override {}
+  void visit (AST::IdentifierExpr &ident_expr) override {}
+  void visit (AST::Lifetime &lifetime) override {}
+  void visit (AST::LifetimeParam &lifetime_param) override {}
+  void visit (AST::ConstGenericParam &const_param) override {}
+  void visit (AST::PathInExpression &path) override {}
+  void visit (AST::TypePathSegment &segment) override {}
+  void visit (AST::TypePathSegmentGeneric &segment) override {}
+  void visit (AST::TypePathSegmentFunction &segment) override {}
+  void visit (AST::TypePath &path) override {}
+  void visit (AST::QualifiedPathInExpression &path) override {}
+  void visit (AST::QualifiedPathInType &path) override {}
+  void visit (AST::LiteralExpr &expr) override {}
+  void visit (AST::AttrInputLiteral &attr_input) override {}
+  void visit (AST::AttrInputMacro &attr_input) override {}
+  void visit (AST::MetaItemLitExpr &meta_item) override {}
+  void visit (AST::MetaItemPathLit &meta_item) override {}
+  void visit (AST::BorrowExpr &expr) override {}
+  void visit (AST::DereferenceExpr &expr) override {}
+  void visit (AST::ErrorPropagationExpr &expr) override {}
+  void visit (AST::NegationExpr &expr) override {}
+  void visit (AST::ArithmeticOrLogicalExpr &expr) override {}
+  void visit (AST::ComparisonExpr &expr) override {}
+  void visit (AST::LazyBooleanExpr &expr) override {}
+  void visit (AST::TypeCastExpr &expr) override {}
+  void visit (AST::AssignmentExpr &expr) override {}
+  void visit (AST::CompoundAssignmentExpr &expr) override {}
+  void visit (AST::GroupedExpr &expr) override {}
+  void visit (AST::ArrayElemsValues &elems) override {}
+  void visit (AST::ArrayElemsCopied &elems) override {}
+  void visit (AST::ArrayExpr &expr) override {}
+  void visit (AST::ArrayIndexExpr &expr) override {}
+  void visit (AST::TupleExpr &expr) override {}
+  void visit (AST::TupleIndexExpr &expr) override {}
+  void visit (AST::StructExprStruct &expr) override {}
+  void visit (AST::StructExprFieldIdentifier &field) override {}
+  void visit (AST::StructExprFieldIdentifierValue &field) override {}
+  void visit (AST::StructExprFieldIndexValue &field) override {}
+  void visit (AST::StructExprStructFields &expr) override {}
+  void visit (AST::StructExprStructBase &expr) override {}
+  void visit (AST::CallExpr &expr) override {}
+  void visit (AST::MethodCallExpr &expr) override {}
+  void visit (AST::FieldAccessExpr &expr) override {}
+  void visit (AST::ClosureExprInner &expr) override {}
+  void visit (AST::BlockExpr &expr) override {}
+  void visit (AST::ClosureExprInnerTyped &expr) override {}
+  void visit (AST::ContinueExpr &expr) override {}
+  void visit (AST::BreakExpr &expr) override {}
+  void visit (AST::RangeFromToExpr &expr) override {}
+  void visit (AST::RangeFromExpr &expr) override {}
+  void visit (AST::RangeToExpr &expr) override {}
+  void visit (AST::RangeFullExpr &expr) override {}
+  void visit (AST::RangeFromToInclExpr &expr) override {}
+  void visit (AST::RangeToInclExpr &expr) override {}
+  void visit (AST::ReturnExpr &expr) override {}
+  void visit (AST::UnsafeBlockExpr &expr) override {}
+  void visit (AST::LoopExpr &expr) override {}
+  void visit (AST::WhileLoopExpr &expr) override {}
+  void visit (AST::WhileLetLoopExpr &expr) override {}
+  void visit (AST::ForLoopExpr &expr) override {}
+  void visit (AST::IfExpr &expr) override {}
+  void visit (AST::IfExprConseqElse &expr) override {}
+  void visit (AST::IfLetExpr &expr) override {}
+  void visit (AST::IfLetExprConseqElse &expr) override {}
+  void visit (AST::MatchExpr &expr) override {}
+  void visit (AST::AwaitExpr &expr) override {}
+  void visit (AST::AsyncBlockExpr &expr) override {}
+  void visit (AST::TypeParam &param) override {}
+  void visit (AST::LifetimeWhereClauseItem &item) override {}
+  void visit (AST::TypeBoundWhereClauseItem &item) override {}
+  void visit (AST::Method &method) override {}
+  void visit (AST::Module &module) override {}
+  void visit (AST::ExternCrate &crate) override {}
+  void visit (AST::UseTreeGlob &use_tree) override {}
+  void visit (AST::UseTreeList &use_tree) override {}
+  void visit (AST::UseTreeRebind &use_tree) override {}
+  void visit (AST::UseDeclaration &use_decl) override {}
+  void visit (AST::Function &function) override {}
+  void visit (AST::TypeAlias &type_alias) override {}
+  void visit (AST::StructStruct &struct_item) override {}
+  void visit (AST::TupleStruct &tuple_struct) override {}
+  void visit (AST::EnumItem &item) override {}
+  void visit (AST::EnumItemTuple &item) override {}
+  void visit (AST::EnumItemStruct &item) override {}
+  void visit (AST::EnumItemDiscriminant &item) override {}
+  void visit (AST::Enum &enum_item) override {}
+  void visit (AST::Union &union_item) override {}
+  void visit (AST::ConstantItem &const_item) override {}
+  void visit (AST::StaticItem &static_item) override {}
+  void visit (AST::TraitItemFunc &item) override {}
+  void visit (AST::TraitItemMethod &item) override {}
+  void visit (AST::TraitItemConst &item) override {}
+  void visit (AST::TraitItemType &item) override {}
+  void visit (AST::Trait &trait) override {}
+  void visit (AST::InherentImpl &impl) override;
+  void visit (AST::TraitImpl &impl) override {}
+  void visit (AST::ExternalTypeItem &item) override {}
+  void visit (AST::ExternalStaticItem &item) override {}
+  void visit (AST::ExternalFunctionItem &item) override {}
+  void visit (AST::ExternBlock &block) override {}
+  void visit (AST::MacroMatchFragment &match) override {}
+  void visit (AST::MacroMatchRepetition &match) override {}
+  void visit (AST::MacroMatcher &matcher) override {}
+  void visit (AST::MacroRulesDefinition &rules_def) override {}
+  void visit (AST::MacroInvocation &macro_invoc) override {}
+  void visit (AST::MetaItemPath &meta_item) override {}
+  void visit (AST::MetaItemSeq &meta_item) override {}
+  void visit (AST::MetaWord &meta_item) override {}
+  void visit (AST::MetaNameValueStr &meta_item) override {}
+  void visit (AST::MetaListPaths &meta_item) override {}
+  void visit (AST::MetaListNameValueStr &meta_item) override {}
+  void visit (AST::LiteralPattern &pattern) override {}
+  void visit (AST::IdentifierPattern &pattern) override {}
+  void visit (AST::WildcardPattern &pattern) override {}
+  void visit (AST::RestPattern &pattern) override {}
+  void visit (AST::RangePatternBoundLiteral &bound) override {}
+  void visit (AST::RangePatternBoundPath &bound) override {}
+  void visit (AST::RangePatternBoundQualPath &bound) override {}
+  void visit (AST::RangePattern &pattern) override {}
+  void visit (AST::ReferencePattern &pattern) override {}
+  void visit (AST::StructPatternFieldTuplePat &field) override {}
+  void visit (AST::StructPatternFieldIdentPat &field) override {}
+  void visit (AST::StructPatternFieldIdent &field) override {}
+  void visit (AST::StructPattern &pattern) override {}
+  void visit (AST::TupleStructItemsNoRange &tuple_items) override {}
+  void visit (AST::TupleStructItemsRange &tuple_items) override {}
+  void visit (AST::TupleStructPattern &pattern) override {}
+  void visit (AST::TuplePatternItemsMultiple &tuple_items) override {}
+  void visit (AST::TuplePatternItemsRanged &tuple_items) override {}
+  void visit (AST::TuplePattern &pattern) override {}
+  void visit (AST::GroupedPattern &pattern) override {}
+  void visit (AST::SlicePattern &pattern) override {}
+  void visit (AST::AltPattern &pattern) override {}
+  void visit (AST::EmptyStmt &stmt) override {}
+  void visit (AST::LetStmt &stmt) override {}
+  void visit (AST::ExprStmt &stmt) override {}
+  void visit (AST::TraitBound &bound) override {}
+  void visit (AST::ImplTraitType &type) override {}
+  void visit (AST::TraitObjectType &type) override {}
+  void visit (AST::ParenthesisedType &type) override {}
+  void visit (AST::ImplTraitTypeOneBound &type) override {}
+  void visit (AST::TraitObjectTypeOneBound &type) override {}
+  void visit (AST::TupleType &type) override {}
+  void visit (AST::NeverType &type) override {}
+  void visit (AST::RawPointerType &type) override {}
+  void visit (AST::ReferenceType &type) override {}
+  void visit (AST::ArrayType &type) override {}
+  void visit (AST::SliceType &type) override {}
+  void visit (AST::InferredType &type) override {}
+  void visit (AST::BareFunctionType &type) override {}
+};
+
+} // namespace Rust
+
+#endif /* ! RUST_AST_VALIDATION_H */