示例#1
0
 public TripMethod(string name, IdentifierType returnType, IdentifierType argumentType, string argumentName)
 {
     Name = Enforce.IsNotNull<string>(name, "name");
     ReturnType = Enforce.IsNotNull<IdentifierType>(returnType, "returnType");
     ArgumentType = Enforce.IsNotNull<IdentifierType>(argumentType, "argumentType");
     ArgumentName = Enforce.IsNotNull<string>(argumentName, "argumentName");
 }
            private CSharpType FindCSharpTypeFromIdentifierType(IdentifierType id)
            {
                var name = id.Name;
                // the name is [<trip-namespace>.]<trip type>
                var names = new List<string>(name.Split('.'));

                if (names.Count == 0 || names.Count > 3)
                {
                    throw new ArgumentException("Only unqualified and trip-namespace qualified names are allowed!");
                }
                string tripName = names[0];
                string tripNamespace = typeToCSharpConverter._namespace;

                if (names.Count == 2)
                {
                    tripName = names[1];
                    tripNamespace = names[0];
                }

                var csharpTypeName = tripNamespace + "." + TemplateContextGenerator.MangleCSharpTypeName(tripName);
                var csharpType = typeToCSharpConverter.typeRegistry.FindType(csharpTypeName);
                return csharpType;
            }
 public bool IsStructIdentifier(IdentifierType id)
 {
     var csharpType = this.FindCSharpTypeFromIdentifierType(id);
     return csharpType.IsTripStruct;
 }
 public bool IsEnumIdentifier(IdentifierType id)
 {
     var csharpType = this.FindCSharpTypeFromIdentifierType(id);
     return csharpType.IsTripEnum;
 }
 public void Visit(IdentifierType identifierType)
 {
     sb.Append(identifierType.Name);
 }
示例#6
0
 public void Visit(IdentifierType identifierType)
 {
     throw new NotImplementedException();
 }
 public bool IsStructIdentifier(IdentifierType id)
 {
     var javaType = this.FindJavaTypeFromIdentifierType(id);
     return javaType.IsLeanStruct;
 }
 public bool IsEnumIdentifier(IdentifierType id)
 {
     var javaType = this.FindJavaTypeFromIdentifierType(id);
     return javaType.IsLeanEnum;
 }
        public static TripType BuildFieldType(ParseTreeNode fieldTypeNode)
        {
            TripType tripType = null;

            var fieldTypeChildNode = fieldTypeNode.ChildNodes[0];

            if (fieldTypeChildNode.Term.Name == IdlGrammar.TNAME_TIDENTIFIER)
            {
                var identifier = fieldTypeChildNode.Token.Text;
                tripType = new IdentifierType(identifier);
            }
            else if (fieldTypeChildNode.Term.Name == IdlGrammar.NTNAME_TBASE_TYPE)
            {
                var baseTypeKeyword = fieldTypeChildNode.FindTokenAndGetText();
                var bType = ConvertBaseTypeKeywordToBaseType(baseTypeKeyword);
                tripType = new BaseType(bType);
            }
            else if (fieldTypeChildNode.Term.Name == IdlGrammar.NTNAME_TCONTAINER_TYPE)
            {
                var containerTypeNode = fieldTypeChildNode.ChildNodes[0];
                if (containerTypeNode.Term.Name == IdlGrammar.NTNAME_TMAP_TYPE)
                {
                    var keyType = BuildFieldType(containerTypeNode.ChildNodes[0]);
                    var valueType = BuildFieldType(containerTypeNode.ChildNodes[1]);
                    tripType = new MapType(keyType, valueType);
                }
                else if (containerTypeNode.Term.Name == IdlGrammar.NTNAME_TSET_TYPE)
                {
                    var setValueType = BuildFieldType(containerTypeNode.ChildNodes[0]);
                    tripType = new SetType(setValueType);
                }
                else if (containerTypeNode.Term.Name == IdlGrammar.NTNAME_TLIST_TYPE)
                {
                    var listValueType = BuildFieldType(containerTypeNode.ChildNodes[0]);
                    tripType = new ListType(listValueType);
                }
            }

            return tripType;
        }
示例#10
0
        public static List<TripMethod> BuildTripMethods(ParseTreeNode tripMethodNodes)
        {
            List<TripMethod> tripMethods = new List<TripMethod>();
            foreach (var methodNode in tripMethodNodes.ChildNodes)
            {
                IdentifierType returnType = new IdentifierType(methodNode.ChildNodes[0].Token.Text);
                string name = methodNode.ChildNodes[1].Token.Text;
                IdentifierType argumentType = new IdentifierType(methodNode.ChildNodes[2].Token.Text);
                string argumentName = methodNode.ChildNodes[3].Token.Text;
                var tripMethod = new TripMethod(name, returnType, argumentType, argumentName);
                tripMethods.Add(tripMethod);
            }

            return tripMethods;
        }