Skip to content

Commit

Permalink
Merge branch 'kythe:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerwilliams authored Feb 4, 2025
2 parents 9db9df3 + ede6dfb commit 65f0a7c
Show file tree
Hide file tree
Showing 11 changed files with 970 additions and 28 deletions.
43 changes: 42 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
# Release Notes

## [v0.0.68] - 2025-01-06
#### Bug Fixes
* **go_indexer:**
* emit docs nodes for interface methods (#6060) ([07be8602](https://github.com/kythe/kythe/commit/07be8602deb772705ed78c71fe5b74137c7fce09))
* emit bindings for named interface method params (#6061) ([e1713667](https://github.com/kythe/kythe/commit/e17136673a160d087e86ca0cab2ac43b7564cb36))
* emit nodes for anonymous interface params (#6062) ([1d7a58a1](https://github.com/kythe/kythe/commit/1d7a58a1797801462a2cd1a86128a2328c9256dd))
* only handle top-level flags (#6063) ([f6b2e265](https://github.com/kythe/kythe/commit/f6b2e265012974038c7bcbea2fa9c7677fc90185))
* **bazel:**
* remove cyclic dependency by removing usage of assign_external_projects_to_separate_corpora config_setting flag (#6146) ([46275ee6](https://github.com/kythe/kythe/commit/46275ee670cab83d0c86ed3a5fbcfe826d386dac))
* **java_indexer:**
* emit node kinds for jvm nodes (#6077) ([22726c4e](https://github.com/kythe/kythe/commit/22726c4ec9f911a2bb38c2284f2064eaff4641af))
* emit jvm refs for enum constants (#6103) ([b6c04946](https://github.com/kythe/kythe/commit/b6c049462ed9b8a5cca671c3d3e2a9b2fa9e71c3))
* **cxx_indexer:**
* use flat_hash_map, not unordered_map; fix rehashing (#6083) ([cba4452d](https://github.com/kythe/kythe/commit/cba4452dc97187e1172d412961d7da494fa32182))
* clarify the use of llvm::dyn_cast on ClaimTokens (#6093) ([ae3434e7](https://github.com/kythe/kythe/commit/ae3434e763027ae747996ca2f6daaf0de71613fd))
* **verifier_test:** ensure tools use the same configuration as indexer (#6113) ([d19f7f30](https://github.com/kythe/kythe/commit/d19f7f30d69c72bf673465a60c47d2303756cc40))
* **extraction:** add proto rule to simple vnames config (#6068) ([28c16cff](https://github.com/kythe/kythe/commit/28c16cff1815c8980004d5192e02dcc07bd87762))

#### Features
* **go_indexer:**
* support flag field vars (#6064) ([df747be8](https://github.com/kythe/kythe/commit/df747be8fb4b999d813e7a57eb0c270a32f6ebe5))
* ref/writes for flag.Set invocations (#6085) ([ae1f3644](https://github.com/kythe/kythe/commit/ae1f36447dc41e74a2ec6b23e703b62ebd349e51))
* **cxx_indexer:**
* experiment with variable initializer types (#6080) ([68671474](https://github.com/kythe/kythe/commit/68671474b72d5387f14fab7133cc29de75ebf86c))
* only emit flattened type representations once (#6082) ([a7f7af76](https://github.com/kythe/kythe/commit/a7f7af76587c9d9a0637ccdff9c5be90f62b3b62))
* look through the obvious casts for init types (#6081) ([49d98e25](https://github.com/kythe/kythe/commit/49d98e258bdaf930924d3b56ebd3ab77e467967c))
* emit symbols for extern C function defns (#6104) ([5b920720](https://github.com/kythe/kythe/commit/5b9207200c01371ddb29293cc3831d0b63f58faa))
* emit name nodes for flags (#6094) ([b1cc57f6](https://github.com/kythe/kythe/commit/b1cc57f64ac7833be44aace759211a98baf15d8c))
* **typescript_indexer:**
* support xrefs in nested object literals (#6125) ([3a66d508](https://github.com/kythe/kythe/commit/3a66d508dbd7094139c14a745fc72058756dbb47))
* add flag to fail analysis on plugin error (#6079) ([65d37c97](https://github.com/kythe/kythe/commit/65d37c972697b201b8c6916811a7607a473ae568))
* **java_indexer:**
* add names for native methods (#6108) ([f13abd65](https://github.com/kythe/kythe/commit/f13abd65999cdbce234fb189cc1e48a70184fe61))
* **protobuf:** add types for protobuf service RPCs (#6109) ([9cd1af59](https://github.com/kythe/kythe/commit/9cd1af596659580469c0aa6a060b4c4a526235aa))
* **tools:** --render_marked_source added to kythe docs cli (#6097) ([cc445fd5](https://github.com/kythe/kythe/commit/cc445fd57ca2d99322e35a65dd723bf1c2398c65))
* **tooling:** entrystream support for textproto output (#6087) ([94e76f87](https://github.com/kythe/kythe/commit/94e76f8791f17a847eb497f78df10f19fbbfdb01))
* define a Language schema enum (#6067) ([7206b16d](https://github.com/kythe/kythe/commit/7206b16d0a7618b1e346edda93cf63612ba2bd6b))
* **build:** regenerate checked-in source artifacts in pre-commit (#6072) ([9db7d1c4](https://github.com/kythe/kythe/commit/9db7d1c4d50f9e8f1a0d827fb57215c40032a943))
* **testing:** provide ability to save logs from indexers in verifier_test (#6075) ([97d1980e](https://github.com/kythe/kythe/commit/97d1980e425da3218d7d235edc38ce61d6286542))

## [v0.0.67] - 2024-03-14

#### Bug Fixes
Expand Down Expand Up @@ -1753,7 +1793,8 @@ https://github.com/kythe/kythe/compare/v0.0.26...v0.0.27

Initial release

[Unreleased] https://github.com/kythe/kythe/compare/v0.0.67...HEAD
[Unreleased] https://github.com/kythe/kythe/compare/v0.0.68...HEAD
[v0.0.68] https://github.com/kythe/kythe/compare/v0.0.67...v0.0.68
[v0.0.67] https://github.com/kythe/kythe/compare/v0.0.66...v0.0.67
[v0.0.66] https://github.com/kythe/kythe/compare/v0.0.65...v0.0.66
[v0.0.65] https://github.com/kythe/kythe/compare/v0.0.64...v0.0.65
Expand Down
6 changes: 3 additions & 3 deletions kythe/cxx/common/json_proto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ absl::Status WriteMessageAsJsonToStringInternal(
options.preserve_proto_field_names = true;

auto status = google::protobuf::util::BinaryToJsonString(
resolver.get(), message.GetDescriptor()->full_name(),
resolver.get(), std::string(message.GetDescriptor()->full_name()),
message.SerializeAsString(), out, options);
if (!status.ok()) {
return absl::Status(static_cast<absl::StatusCode>(status.code()),
Expand Down Expand Up @@ -143,8 +143,8 @@ absl::Status ParseFromJsonStream(
std::string binary;
google::protobuf::io::StringOutputStream output(&binary);
auto status = google::protobuf::util::JsonToBinaryStream(
resolver.get(), message->GetDescriptor()->full_name(), input, &output,
options);
resolver.get(), std::string(message->GetDescriptor()->full_name()), input,
&output, options);

if (!status.ok()) {
return absl::Status(static_cast<absl::StatusCode>(status.code()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
/*
* Copyright 2014 The Kythe Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.devtools.kythe.platform.java.helpers;

import com.google.common.flogger.FluentLogger;
import com.sun.source.tree.BlockTree;
import com.sun.source.tree.CatchTree;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.EnhancedForLoopTree;
import com.sun.source.tree.ForLoopTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePath;
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import java.util.HashMap;
import java.util.Map;
import javax.lang.model.element.Element;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* This class is responsible for generating signatures for blocks and anonymous classes. The maps
* used for caching in this class are specific through out the life of analyzer and they can be used
* for one or more compilation units which are part of one compilation context.
*/
public class BlockAnonymousSignatureGenerator
extends TreeScanner<Void, BlockAnonymousSignatureGenerator.BlockAnonymousData> {
/*
* Blocks are numbered sequentially from zero within a class scope or a method scope.
* Here is an example of block numbering:
* <code><pre>
* class A {// block 0
* {// block 1
* {// block 2
* }
* }
* {// block 3
* }
* void method() {// block 0
* {// block 1
* }
* if (true) {// block 2
* } else {// block 3
* }
* }
* }
* </code></pre>
*/

static class BlockAnonymousData {
int blockNumber;
int anonymousNumber;
final String topLevelSignature;

public BlockAnonymousData(int blockNumber, int anonymousNumber, String topLevelSignature) {
this.blockNumber = blockNumber;
this.anonymousNumber = anonymousNumber;
this.topLevelSignature = topLevelSignature;
}
}

private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final SignatureGenerator signatureGenerator;

BlockAnonymousSignatureGenerator(SignatureGenerator signatureGenerator) {
this.signatureGenerator = signatureGenerator;
}

// Indicates whether the compilation unit has already been processed or not.
private boolean unitProcessed = false;

// Holds the signature for each block visited.
// Holds the signature for each anonymous class.
// Anonymous classes are numbered with respect to their first enclosing class declaration or
// block. They are numbered from zero.
private final Map<Tree, String> blockAnonymousMap = new HashMap<>();

/** Returns the block signature of the corresponding element */
String getBlockSignature(Element element) {
TreePath path = signatureGenerator.getPath(element);
if (path == null) {
throw new IllegalStateException("path was null for element: " + element);
}
return getBlockSignature(path);
}

/** Returns the block signature of the corresponding path */
String getBlockSignature(TreePath path) {
this.process(path.getCompilationUnit());
path = path.getParentPath();
JCTree parent = (JCTree) path.getLeaf();
while (!(parent.getTag() == JCTree.Tag.BLOCK
|| parent.getTag() == JCTree.Tag.CLASSDEF
|| parent.getTag() == JCTree.Tag.FORLOOP
|| parent.getTag() == JCTree.Tag.FOREACHLOOP
|| parent.getTag() == JCTree.Tag.METHODDEF
|| parent.getTag() == JCTree.Tag.CATCH)) {
path = path.getParentPath();
parent = (JCTree) path.getLeaf();
}
if (parent.getTag() == JCTree.Tag.BLOCK
|| parent.getTag() == JCTree.Tag.FORLOOP
|| parent.getTag() == JCTree.Tag.FOREACHLOOP
|| parent.getTag() == JCTree.Tag.CATCH) {
return blockAnonymousMap.get(parent);
} else if (parent.getTag() == JCTree.Tag.METHODDEF) {
JCMethodDecl methodDecl = (JCMethodDecl) parent;
StringBuilder methodSignature = new StringBuilder();
methodDecl.sym.accept(this.signatureGenerator, methodSignature);
return methodSignature.toString();
} else {
JCClassDecl classDecl = (JCClassDecl) parent;
StringBuilder classSignature = new StringBuilder();
classDecl.sym.accept(this.signatureGenerator, classSignature);
return classSignature.toString();
}
}

boolean isInBlock(Element e) {
TreePath tp = signatureGenerator.getPath(e);
JCTree parent = null;
do {
if (tp != null) {
parent = (JCTree) tp.getLeaf();
} else {
return false;
}
tp = tp.getParentPath();
} while (parent.getTag() != JCTree.Tag.BLOCK);
return parent.getTag() == JCTree.Tag.BLOCK;
}

// Returns the anonymous signature of the corresponding element. Element is supposed to be an
// anonymous class definition.
@Nullable String getAnonymousSignature(Element e) {
TreePath tp = signatureGenerator.getPath(e);
if (tp == null) {
return null;
}
this.process(tp.getCompilationUnit());
return blockAnonymousMap.get(tp.getLeaf());
}

private void process(CompilationUnitTree unit) {
if (!unitProcessed) {
unitProcessed = true;
unit.accept(this, new BlockAnonymousData(0, 0, ""));
}
}

@Override
public Void visitMethod(MethodTree methodTree, BlockAnonymousData blockData) {
JCMethodDecl methodDecl = (JCMethodDecl) methodTree;
StringBuilder methodSignature = new StringBuilder();
if (methodDecl.sym == null) {
logger.atInfo().log("methodDecl symbol was null");
return null;
}
methodDecl.sym.accept(signatureGenerator, methodSignature);
return super.visitMethod(methodTree, new BlockAnonymousData(-1, 0, methodSignature.toString()));
}

@Override
public Void visitClass(ClassTree classTree, BlockAnonymousData blockData) {
JCClassDecl classDecl = (JCClassDecl) classTree;
if (classTree.getSimpleName().contentEquals("")) {
StringBuilder anonymousClassSignature = new StringBuilder();
if (classDecl.sym != null) {
anonymousClassSignature.append(getBlockSignature(classDecl.sym));
} else {
String name = classDecl.name == null ? "" : classDecl.name.toString();
logger.atWarning().log(
"BlockAnonymous class symbol was null: %s#%d", name, blockData.anonymousNumber);
}
anonymousClassSignature.append(SignatureGenerator.ANONYMOUS);
anonymousClassSignature.append("#");
anonymousClassSignature.append(blockData.anonymousNumber);
blockAnonymousMap.put(classDecl, anonymousClassSignature.toString());
blockData.anonymousNumber++;
return super.visitClass(
classTree, new BlockAnonymousData(0, 0, blockAnonymousMap.get(classDecl)));
} else {
StringBuilder classSignature = new StringBuilder();
classDecl.sym.accept(this.signatureGenerator, classSignature);
return super.visitClass(classTree, new BlockAnonymousData(0, 0, classSignature.toString()));
}
}

@Override
public Void visitEnhancedForLoop(
EnhancedForLoopTree enhancedForLoopTree, BlockAnonymousData blockData) {
blockAnonymousMap.put(
enhancedForLoopTree, blockData.topLevelSignature + ".{}" + (blockData.blockNumber + 1));
if (enhancedForLoopTree.getStatement().getKind() != Tree.Kind.BLOCK) {
blockData.blockNumber++;
}
return super.visitEnhancedForLoop(enhancedForLoopTree, blockData);
}

@Override
public Void visitForLoop(ForLoopTree forLoopTree, BlockAnonymousData blockData) {
blockAnonymousMap.put(
forLoopTree, blockData.topLevelSignature + ".{}" + (blockData.blockNumber + 1));
if (forLoopTree.getStatement().getKind() != Tree.Kind.BLOCK) {
blockData.blockNumber++;
}
return super.visitForLoop(forLoopTree, blockData);
}

@Override
public Void visitCatch(CatchTree catchTree, BlockAnonymousData blockData) {
blockAnonymousMap.put(
catchTree, blockData.topLevelSignature + ".{}" + (blockData.blockNumber + 1));
return super.visitCatch(catchTree, blockData);
}

@Override
public Void visitBlock(BlockTree b, BlockAnonymousData blockData) {
blockData.blockNumber++;
JCBlock block = (JCBlock) b;
blockAnonymousMap.put(block, blockData.topLevelSignature + ".{}" + blockData.blockNumber);
BlockAnonymousData newBlockAnonymousData =
new BlockAnonymousData(blockData.blockNumber, 0, blockData.topLevelSignature);
super.visitBlock(block, newBlockAnonymousData);
blockData.blockNumber = newBlockAnonymousData.blockNumber;
return null;
}
}
Loading

0 comments on commit 65f0a7c

Please sign in to comment.