/*
 * Copyright 2010-2015 JetBrains s.r.o.
 *
 * 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 org.jetbrains.kotlin.serialization.jvm;

import "core/deserialization/src/descriptors.proto";

option java_outer_classname = "JvmProtoBuf";
option optimize_for = LITE_RUNTIME;

message JvmType {
  // Either a primitive type, or a class FQ name should be present

  enum PrimitiveType {
    // These values correspond to ASM Type sorts
    VOID = 0;
    BOOLEAN = 1;
    CHAR = 2;
    BYTE = 3;
    SHORT = 4;
    INT = 5;
    FLOAT = 6;
    LONG = 7;
    DOUBLE = 8;
  }

  optional PrimitiveType primitive_type = 1;

  // id in QualifiedNameTable of a name in the following format: 'package.Outer$Nested'
  optional int32 class_fq_name = 2;

  optional int32 array_dimension = 3 [default = 0];
}

message JvmMethodSignature {
  required int32 name = 1;
  required JvmType return_type = 2;
  repeated JvmType parameter_type = 3;
}

message JvmFieldSignature {
  required int32 name = 1;
  required JvmType type = 2;

  // True iff this field is a backing field for a companion object and is really present as a static
  // field in the outer class, not as an instance field here
  optional bool is_static_in_outer = 3 [default = false];
}

message JvmPropertySignature {
  // A property itself is identified either by the field, or by the synthetic method.
  // If the property is annotated, then either field or synthetic_method should be present
  optional JvmFieldSignature field = 1;

  // Annotations on properties without backing fields are written on a synthetic method with this signature
  optional JvmMethodSignature synthetic_method = 2;

  optional JvmMethodSignature getter = 3;
  optional JvmMethodSignature setter = 4;
}

extend org.jetbrains.kotlin.serialization.Callable {
  optional JvmMethodSignature method_signature = 100;

  optional JvmPropertySignature property_signature = 101;

  // Package-less name of the class with the callable's body and annotations, if it differs from the class it's serialized into.
  // E.g. for a class "A/B/C$D" this would be "C$D".
  // This is needed to find the class to load annotations from in the following cases:
  // 1) annotations on top-level members are written to compiled package part classes
  // 2) annotations on properties in traits are written to TImpl classes
  optional int32 impl_class_name = 102;
}

extend org.jetbrains.kotlin.serialization.Type {
  repeated Annotation type_annotation = 100;
}

extend org.jetbrains.kotlin.serialization.Callable.ValueParameter {
  // Index of the corresponding parameter of this method in JVM (counting receiver parameters, enum constructor synthetic parameters, etc.)
  optional int32 index = 100;
}
