mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
var func6 : ((int,int) -> int) -> (); // Takes a function, returns nothing.
func funcdecl5() {
func6(_0 + _1); // Closure with two named anonymous arguments
}
into:
(apply_expr type='()'
(declref_expr type='(int, int) -> int -> ()' decl=func6)
(closure_expr type='(int, int) -> int'
(anondecl '_0' type='int')
(anondecl '_1' type='int')
(tuple_expr type='int'
(binary_expr '+' type='int'
(declref_expr type='int' decl=_0)
(declref_expr type='int' decl=_1))))))))
However, there are still some problems with this (and we're definitely not doing type inference yet, all anon args are assumed 'int').
Swift SVN r111
80 lines
2.3 KiB
C++
80 lines
2.3 KiB
C++
//===--- Decl.cpp - Swift Language Decl ASTs ------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the Decl class and subclasses.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "swift/AST/Decl.h"
|
|
#include "swift/AST/ASTContext.h"
|
|
#include "swift/AST/Expr.h"
|
|
#include "swift/AST/Type.h"
|
|
#include "llvm/Support/Casting.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
using namespace swift;
|
|
using llvm::cast;
|
|
|
|
// Only allow allocation of Decls using the allocator in ASTContext.
|
|
void *Decl::operator new(size_t Bytes, ASTContext &C,
|
|
unsigned Alignment) throw() {
|
|
return C.Allocate(Bytes, Alignment);
|
|
}
|
|
|
|
void Decl::dump() const { print(llvm::errs()); llvm::errs() << '\n'; }
|
|
|
|
void Decl::print(llvm::raw_ostream &OS, unsigned Indent) const {
|
|
switch (getKind()) {
|
|
case VarDeclKind: return cast<VarDecl>(this)->print(OS, Indent);
|
|
case FuncDeclKind: return cast<FuncDecl>(this)->print(OS, Indent);
|
|
case AnonDeclKind: return cast<AnonDecl>(this)->print(OS, Indent);
|
|
}
|
|
}
|
|
|
|
|
|
llvm::SMLoc NamedDecl::getLocStart() const {
|
|
if (const VarDecl *V = llvm::dyn_cast<VarDecl>(this))
|
|
return V->VarLoc;
|
|
if (const FuncDecl *F = llvm::dyn_cast<FuncDecl>(this))
|
|
return F->FuncLoc;
|
|
return cast<AnonDecl>(this)->UseLoc;
|
|
}
|
|
|
|
|
|
void NamedDecl::printCommon(llvm::raw_ostream &OS, unsigned Indent) const {
|
|
OS << "'" << Name << "' type='";
|
|
Ty->print(OS);
|
|
OS << "'";
|
|
|
|
if (Init) {
|
|
OS << '\n';
|
|
Init->print(OS, Indent+1);
|
|
}
|
|
OS << ')';
|
|
}
|
|
|
|
|
|
void VarDecl::print(llvm::raw_ostream &OS, unsigned Indent) const {
|
|
OS.indent(Indent) << "(vardecl ";
|
|
printCommon(OS, Indent);
|
|
}
|
|
|
|
void FuncDecl::print(llvm::raw_ostream &OS, unsigned Indent) const {
|
|
OS.indent(Indent) << "(funcdecl ";
|
|
printCommon(OS, Indent);
|
|
}
|
|
|
|
void AnonDecl::print(llvm::raw_ostream &OS, unsigned Indent) const {
|
|
OS.indent(Indent) << "(anondecl ";
|
|
printCommon(OS, Indent);
|
|
}
|
|
|