Files
swift-mirror/include/swift/Sema/Semantics.h
David Farler 303a3e5824 Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.

The basic pipeline in the frontend is:

- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
  set to 7 based on prior migrator seasons.  Right now, this is just set
  to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
  file that Xcode knows how to understand.

Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.

- Add -emit-remap frontend option
  This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
  This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
  Useful for debugging, this skips the phase in the Migrator that
  automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
  This is used for testing/debugging scenarios. This takes the final
  migration state's output text and writes it to the file specified
  by this option.
- Add -dump-migration-states-dir

  This dumps all of the migration states encountered during a migration
  run for a file to the given directory. For example, the compiler
  fix-it migration pass dumps the input file, the output file, and the
  remap file between the two.

  State output has the following naming convention:
  ${Index}-${MigrationPassName}-${What}.${extension}, such as:
  1-FixitMigrationState-Input.swift

rdar://problem/30926261
2017-04-17 16:25:02 -07:00

66 lines
2.3 KiB
C++

//===--- Semantics.h - Swift Container for Semantic Info --------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file declares the interface for Semantics, the top-level container
// and manager for semantic analysis.
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SEMA_SEMANTICMODEL_H
#define SWIFT_SEMA_SEMANTICMODEL_H
#include "swift/AST/ASTNode.h"
#include "swift/Syntax/SyntaxData.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
namespace swift {
namespace syntax {
class LegacyASTTransformer;
}
namespace sema {
/// The top-level container and manager for semantic analysis.
///
/// Eventually, this should contain cached semantic information such as
/// resolved symbols and types for Syntax nodes. For now, it only maintains
/// a mapping from lib/AST nodes to lib/Syntax nodes while we integrate
/// the infrastructure into the compiler.
class Semantics final {
friend class LegacyASTTransformer;
llvm::DenseMap<RC<syntax::SyntaxData>, ASTNode> SyntaxMap;
public:
/// Record a syntax node -> semantic node mapping for later retrieval.
///
/// This is a temporary measure to get a syntax node's Type or resolved
/// underlying declaration reference after semantic analysis is done.
void recordSyntaxMapping(RC<syntax::SyntaxData> FromNode,
ASTNode ToNode);
/// Get the semantic node for a piece of syntax. This must have been
/// previously recorded with a call to `recordSyntaxMapping`.
llvm::Optional<ASTNode> getNodeForSyntax(syntax::Syntax SyntaxNode) const;
/// Clear any associations between syntax nodes and semantic nodes.
void clearSyntaxMap();
/// Dump the entire syntax node -> semantic node map for debugging purposes.
void dumpSyntaxMap() const;
};
} // end namespace sema
} // end namespace swift
#endif // SWIFT_SEMA_SEMANTICMODEL_H