示例#1
0
 private void TypeToString(dynamic type, StringBuilder result)
 {
     string brand = type.GetBrand().ToString();
     switch (brand)
     {
         case "Literal":
             string name = type[0];
             result.Append(name);
             break;
         case "SimpleType":
             result.Append(type.Name);
             if (type.IsNullable)
             {
                 result.Append("?");
             }
             break;
         case "ArrayType":
             this.TypeToString(type.ItemType, result);
             result.Append("[]");
             break;
         case "TemplateType":
             result.Append(type.Name);
             result.Append("<");
             string delim = "";
             foreach (dynamic param in type.Params)
             {
                 result.Append(delim);
                 this.TypeToString(param, result);
                 delim = ", ";
             }
             result.Append(">");
             break;
         default:
             break;
     }
 }
示例#2
0
 /// <summary>
 /// Processes type reference node.
 /// </summary>
 /// <remarks>
 /// Searches for built-in types, structs or enums and arrays or nullable types from them.
 /// </remarks>
 /// <param name="node">The node.</param>
 /// <returns>The type that matches the name.</returns>
 /// <exception cref="NameNotFoundException">If no matching type is not found.</exception>
 /// <exception cref="NameCollisionException">If more than one matching type is found.</exception>
 private Type Process_TypeReference(dynamic node)
 {
     if (node.GetBrand() == "SimpleType")
     {
         Type type = node.IsBuiltInType ? BuiltInType.GetBuiltInType(node.Name) : (Type)this.Process_NamespacedTypeReference(node.Name, typeof(EnumType), typeof(StructType));
         return node.IsNullable ? NullableType.CreateFrom(type) : type;
     }
     else if (node.GetBrand() == "ArrayType")
     {
         return ArrayType.CreateFrom(this.Process_TypeReference(node.ItemType));
     }
     else
     {
         return null;
     }
 }
示例#3
0
        /// <summary>
        /// Processes operation contract statement node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_OperationContractStatement(dynamic node)
        {
            if (node.GetBrand() == "Ensures")
            {
                Ensures ensures = new Ensures();

                // Map source location and node to object
                ensures.AddMetaInfo(new SourceLocationInfo(node, context));
                context.AddObject(node, ensures);

                // OperationContract
                ensures.OperationContract = (OperationContract)NameContext.Current.Scope;

                // Text
                ensures.Text = node.Text;

                // Rule
                ensures.Rule = this.Process(node.Rule);
                ensures.Rule.ExpectedType = BuiltInType.Bool;
            }
            if (node.GetBrand() == "Requires")
            {
                Requires requires = new Requires();

                // Map source location and node to object
                requires.AddMetaInfo(new SourceLocationInfo(node, context));
                context.AddObject(node, requires);

                // OperationContract
                requires.OperationContract = (OperationContract)NameContext.Current.Scope;

                // Text
                requires.Text = node.Text;

                // Rule
                requires.Rule = this.Process(node.Rule);
                requires.Rule.ExpectedType = BuiltInType.Bool;

                // Otherwise
                requires.Otherwise = this.Process(node.Otherwise);
                requires.Otherwise.ExpectedType = PseudoType.Object;
            }
        }
示例#4
0
 /// <summary>
 /// Processes return type reference node.
 /// </summary>
 /// <remarks>
 /// Searches for pseudo types, built-in types, structs or enums and arrays or nullable types from them.
 /// </remarks>
 /// <param name="node">The node.</param>
 /// <returns>The type that matches the name.</returns>
 /// <exception cref="NameNotFoundException">If no matching type is not found.</exception>
 /// <exception cref="NameCollisionException">If more than one matching type is found.</exception>
 private Type Process_ReturnTypeReference(dynamic node)
 {
     if (node.GetBrand() == "VoidType")
     {
         return (node.Async) ? PseudoType.Async : PseudoType.Void;
     }
     else
     {
         return this.Process_TypeReference(node);
     }
 }
示例#5
0
        /// <summary>
        /// Processes operation authorization statement node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_OperationAuthorizationStatement(dynamic node)
        {
            if (node.GetBrand() == "Demand")
            {
                Demand demand = new Demand();

                // Map source location and node to object
                demand.AddMetaInfo(new SourceLocationInfo(node, context));
                context.AddObject(node, demand);

                // OperationContract
                demand.OperationAuthorization = (OperationAuthorization)NameContext.Current.Scope;

                // Text
                demand.Text = node.Text;

                // Rule
                demand.Rule = this.Process(node.Rule);
                demand.Rule.ExpectedType = BuiltInType.Bool;
            }
        }