Ejemplo n.º 1
0
        /// <summary>
        /// Creates a tuple value that stores the given LLVM value representing a Q# value of user defined type.
        /// </summary>
        /// <param name="value">The typed tuple representing a value of user defined type</param>
        /// <param name="udt">The Q# type of the value</param>
        internal TupleValue FromCustomType(Value value, UserDefinedType udt)
        {
            if (!this.sharedState.TryGetCustomType(udt.GetFullName(), out var udtDecl))
            {
                throw new ArgumentException("type declaration not found");
            }

            var elementTypes = udtDecl.Type.Resolution is ResolvedTypeKind.TupleType ts ? ts.Item : ImmutableArray.Create(udtDecl.Type);

            return(new TupleValue(udt, value, elementTypes, this.sharedState));
        }
Ejemplo n.º 2
0
 public override QsResolvedTypeKind OnUserDefinedType(UserDefinedType udt)
 {
     // User-defined types are represented by a tuple of their items.
     if (this.SharedState.TryGetCustomType(udt.GetFullName(), out QsCustomType? udtDefinition))
     {
         this.SharedState.BuiltType = udtDefinition.Type.Resolution.IsUnitType
             ? this.SharedState.Types.Tuple
             : this.SharedState.LlvmStructTypeFromQsharpType(udtDefinition.Type).CreatePointerType();
     }
     else
     {
         throw new InvalidOperationException("unknown user defined type");
     }
     return(QsResolvedTypeKind.InvalidType);
 }