Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/ConstExtract/ConstExtract.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//===-------- ConstExtract.h -- Gather Compile-Time-Known Values ----------===//
//===---- ConstExtract.h -- Gather Compile-Time-Known Values ----*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2022 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
Expand Down
26 changes: 23 additions & 3 deletions lib/ConstExtract/ConstExtract.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//===-------- ConstExtract.pp -- Gather Compile-Time-Known Values --------===//
//===-------- ConstExtract.cpp -- Gather Compile-Time-Known Values --------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2022 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
Expand Down Expand Up @@ -222,6 +222,21 @@ std::string toString(const CompileTimeValue *Value) {
}
}

std::string toString(CompileTimeValue::ValueKind Kind) {
switch (Kind) {
case CompileTimeValue::ValueKind::RawLiteral:
return "RawLiteral";
case CompileTimeValue::ValueKind::InitCall:
return "InitCall";
case CompileTimeValue::ValueKind::Builder:
return "Builder";
case CompileTimeValue::ValueKind::Dictionary:
return "Dictionary";
case CompileTimeValue::ValueKind::Runtime:
return "Runtime";
}
}

bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
llvm::raw_fd_ostream &OS) {
llvm::json::OStream JSON(OS, 2);
Expand All @@ -244,7 +259,12 @@ bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
PropertyDecl->isStatic() ? "true" : "false");
JSON.attribute("isComputed",
!PropertyDecl->hasStorage() ? "true" : "false");
JSON.attribute("value", toString(PropertyInfo.Value.get()));
auto value = PropertyInfo.Value.get();
auto valueKind = value->getKind();
JSON.attribute("valueKind", toString(valueKind));
if (valueKind != CompileTimeValue::ValueKind::Runtime) {
JSON.attribute("value", toString(value));
}
});
}
});
Expand Down
10 changes: 10 additions & 0 deletions test/ConstExtraction/fields.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,69 +15,79 @@
// CHECK-NEXT: "type": "Swift.String",
// CHECK-NEXT: "isStatic": "false",
// CHECK-NEXT: "isComputed": "false",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "\"Hello, World\""
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "p5",
// CHECK-NEXT: "type": "[Swift.Int]",
// CHECK-NEXT: "isStatic": "false",
// CHECK-NEXT: "isComputed": "false",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "[1, 2, 3, 4, 5, 6, 7, 8, 9]"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "p6",
// CHECK-NEXT: "type": "Swift.Bool",
// CHECK-NEXT: "isStatic": "false",
// CHECK-NEXT: "isComputed": "false",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "false"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "p7",
// CHECK-NEXT: "type": "Swift.Bool?",
// CHECK-NEXT: "isStatic": "false",
// CHECK-NEXT: "isComputed": "false",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "nil"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "p8",
// CHECK-NEXT: "type": "(Swift.Int, Swift.Float)",
// CHECK-NEXT: "isStatic": "false",
// CHECK-NEXT: "isComputed": "false",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "(42, 6.6)"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "p9",
// CHECK-NEXT: "type": "[Swift.String : Swift.Int]",
// CHECK-NEXT: "isStatic": "false",
// CHECK-NEXT: "isComputed": "false",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "[(\"One\", 1), (\"Two\", 2), (\"Three\", 3)]"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "p0",
// CHECK-NEXT: "type": "Swift.Int",
// CHECK-NEXT: "isStatic": "true",
// CHECK-NEXT: "isComputed": "false",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "11"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "p2",
// CHECK-NEXT: "type": "Swift.Float",
// CHECK-NEXT: "isStatic": "true",
// CHECK-NEXT: "isComputed": "false",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "42.2"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "p3",
// CHECK-NEXT: "type": "Swift.Int",
// CHECK-NEXT: "isStatic": "false",
// CHECK-NEXT: "isComputed": "true",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "3"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "p4",
// CHECK-NEXT: "type": "Swift.Int",
// CHECK-NEXT: "isStatic": "true",
// CHECK-NEXT: "isComputed": "true",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "3"
// CHECK-NEXT: }
// CHECK-NEXT: ]
Expand Down