Exemple #1
0
        private int ExtractStructMembers(StructInfo temp, ParseTreeNode specifier)
        {
            if (specifier == null)
            {
                return(0);
            }

            // second child is struct type name
            if (!ExtractName(temp, specifier.ChildNodes [1]))
            {
                return(0);
            }
            // third child is list of member inside
            if (ExtractMembers(temp, specifier.ChildNodes [2]))
            {
                // TODO : case sensitive ????
                var key = temp.Name.ToLowerInvariant();
                if (!mBlocks.ContainsKey(key))
                {
                    mBlocks.Add(key, temp);
                }
                return(1);
            }
            else
            {
                return(0);
            }
        }
Exemple #2
0
        private bool CheckForUniformTag(StructInfo info, ParseTreeNode child)
        {
            if (child.Term != mLanguage.TypeQualifier)
            {
                return(false);
            }

            var qualifierlist = child.ChildNodes.Find((p) => p.Term == mLanguage.LayoutQualifierIdList);

            if (qualifierlist == null)
            {
                return(false);
            }

            info.Layout = new LayoutInformation();
            ExtractLayout(info.Layout, qualifierlist);

            var uniformTag = child.ChildNodes [1].Token;

            if (uniformTag.ValueString != "uniform")
            {
                return(false);
            }
            return(true);
        }
Exemple #3
0
        private int FindBlocks(ParseTreeNode node, int level)
        {
            if (node == null)
            {
                return(0);
            }


            if (node.Term.Name == "block_structure")
            {
                var temp = new StructInfo();

                // first child is uniform keyword
                bool isValid = CheckForUniformTag(temp, node.ChildNodes[0]);
                if (isValid)
                {
                    // second child is struct type name
                    if (!ExtractName(temp, node.ChildNodes [1]))
                    {
                        return(0);
                    }

                    // third child is list of member inside
                    if (ExtractMembers(temp, node.ChildNodes [2]))
                    {
                        // TODO : case sensitive ????
                        var key = temp.Name.ToLowerInvariant();
                        if (!mBlocks.ContainsKey(key))
                        {
                            mBlocks.Add(key, temp);
                        }

                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                int total = 0;
                foreach (ParseTreeNode child in node.ChildNodes)
                {
                    total += FindBlocks(child, level + 1);
                }
                return(total);
            }
        }
Exemple #4
0
        private bool ExtractMembers(StructInfo info, ParseTreeNode child)
        {
            if (child.Term.Name == "struct_declaration_list")
            {
                ExtractStructBody(info, child);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #5
0
        public void ExtractStructBody(StructInfo info, ParseTreeNode child)
        {
            var members = child.ChildNodes.FindAll(p => p.Term.Name == "struct_declaration");

            foreach (var member in members)
            {
                var temp = new StructMember();
                temp.TypeString  = member.ChildNodes [0].Token.ValueString;
                temp.ClosestType = mTypeLookup.FindClosestType(temp.TypeString);
                var declarator = member.ChildNodes [1];
                if (declarator.Term.Name == "struct_declarator")
                {
                    // ASSUME type is first child
                    temp.Name = declarator.ChildNodes [0].Token.ValueString;
                }
                info.Members.Add(temp);
            }
        }
        private int FindStructsAndAttributes(ParseTreeNode parent, int level)
        {
            if (parent == null)
            {
                return 0;
            }

            if (parent.Term == mLanguage.SingleDeclaration)
            {
                var node = parent.ChildNodes[0];
                if (node.Term == mLanguage.FullySpecifiedType)
                {
                    var specifier = node.ChildNodes.Find (p => p.Term == mLanguage.StructSpecifier);
                    var typeQualifier = node.ChildNodes.Find (p => p.Term == mLanguage.TypeQualifier);
                    if (specifier != null)
                    {
                        var temp = new StructInfo ();
                        temp.Layout = new LayoutInformation ();
                        ExtractLayout (temp.Layout, typeQualifier);
                        return ExtractStructMembers (temp, specifier);
                    }

                    var inDirection = typeQualifier.ChildNodes.Find (p => p.Term == mLanguage.InTerm);

                    var outDirection = typeQualifier.ChildNodes.Find (p => p.Term == mLanguage.OutTerm);

                    if (inDirection == null && outDirection == null)
                    {
                        return 0;
                    }

                    var attribute = new InputAttribute ();
                    attribute.Direction = (inDirection != null) ? "in" : ((outDirection != null) ? "out" : null);
                    attribute.Layout = new LayoutInformation ();
                    ExtractLayout (attribute.Layout, typeQualifier);
                    var secondNode = node.ChildNodes [1];
                    if (!mLanguage.TypesTerms.Contains (secondNode.Token.KeyTerm))
                    {
                        return 0;
                    }

                    attribute.TypeString = secondNode.Token.ValueString;
                    attribute.ClosestType = mTypeLookup.FindClosestType (attribute.TypeString);

                    var nameSibiling = parent.ChildNodes [1];
                    attribute.Name = nameSibiling.Token.ValueString;

                    // IGNORE
                    if (!mAttributes.ContainsKey (attribute.Name))
                    {
                        mAttributes.Add (attribute.Name, attribute);
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }

                }
                else
                {
                    return 0;
                }
            }
            else
            {
                int total = 0;
                foreach (ParseTreeNode child in parent.ChildNodes)
                {
                    total += FindStructsAndAttributes (child, level + 1);
                }
                return total;
            }
        }
        private int FindBlocks(ParseTreeNode node, int level)
        {
            if (node == null)
            {
                return 0;
            }

            if (node.Term.Name == "block_structure")
            {
                var temp = new StructInfo ();

                // first child is uniform keyword
                bool isValid = CheckForUniformTag(temp, node.ChildNodes[0]);
                if (isValid)
                {
                    // second child is struct type name
                    if (!ExtractName (temp, node.ChildNodes [1]))
                    {
                        return 0;
                    }

                    // third child is list of member inside
                    if (ExtractMembers (temp, node.ChildNodes [2]))
                    {
                        // TODO : case sensitive ????
                        var key = temp.Name.ToLowerInvariant();
                        if (!mBlocks.ContainsKey (key))
                        {
                            mBlocks.Add (key, temp);
                        }

                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                }
                else
                {
                    return 0;
                }

            }
            else
            {
                int total = 0;
                foreach (ParseTreeNode child in node.ChildNodes)
                {
                    total += FindBlocks (child, level + 1);
                }
                return total;
            }
        }
        private int ExtractStructMembers(StructInfo temp, ParseTreeNode specifier)
        {
            if (specifier == null)
            {
                return 0;
            }

            // second child is struct type name
            if (!ExtractName (temp, specifier.ChildNodes [1]))
            {
                return 0;
            }
            // third child is list of member inside
            if (ExtractMembers (temp, specifier.ChildNodes [2]))
            {
                // TODO : case sensitive ????
                var key = temp.Name.ToLowerInvariant ();
                if (!mBlocks.ContainsKey (key))
                {
                    mBlocks.Add (key, temp);
                }
                return 1;
            }
            else
            {
                return 0;
            }
        }
 private bool ExtractName(StructInfo info, ParseTreeNode child)
 {
     info.Name = child.Token.ValueString;
     return true;
 }
        private bool ExtractMembers(StructInfo info, ParseTreeNode child)
        {
            if (child.Term.Name == "struct_declaration_list")
            {
                ExtractStructBody (info, child);

                return true;
            }
            else
            {
                return false;
            }
        }
        private bool CheckForUniformTag(StructInfo info, ParseTreeNode child)
        {
            if (child.Term != mLanguage.TypeQualifier )
            {
                return false;
            }

            var qualifierlist = child.ChildNodes.Find ((p) => p.Term == mLanguage.LayoutQualifierIdList);
            if (qualifierlist == null)
            {
                return false;
            }

            info.Layout = new LayoutInformation ();
            ExtractLayout (info.Layout, qualifierlist);

            var uniformTag = child.ChildNodes [1].Token;
            if (uniformTag.ValueString != "uniform")
            {
                return false;
            }
            return true;
        }
 public void ExtractStructBody(StructInfo info, ParseTreeNode child)
 {
     var members = child.ChildNodes.FindAll (p => p.Term.Name == "struct_declaration");
     foreach (var member in members)
     {
         var temp = new StructMember ();
         temp.TypeString = member.ChildNodes [0].Token.ValueString;
         temp.ClosestType = mTypeLookup.FindClosestType (temp.TypeString);
         var declarator = member.ChildNodes [1];
         if (declarator.Term.Name == "struct_declarator")
         {
             // ASSUME type is first child
             temp.Name = declarator.ChildNodes [0].Token.ValueString;
         }
         info.Members.Add (temp);
     }
 }
Exemple #13
0
 private bool ExtractName(StructInfo info, ParseTreeNode child)
 {
     info.Name = child.Token.ValueString;
     return(true);
 }
Exemple #14
0
        private int FindStructsAndAttributes(ParseTreeNode parent, int level)
        {
            if (parent == null)
            {
                return(0);
            }

            if (parent.Term == mLanguage.SingleDeclaration)
            {
                var node = parent.ChildNodes[0];
                if (node.Term == mLanguage.FullySpecifiedType)
                {
                    var specifier     = node.ChildNodes.Find(p => p.Term == mLanguage.StructSpecifier);
                    var typeQualifier = node.ChildNodes.Find(p => p.Term == mLanguage.TypeQualifier);
                    if (specifier != null)
                    {
                        var temp = new StructInfo();
                        temp.Layout = new LayoutInformation();
                        ExtractLayout(temp.Layout, typeQualifier);
                        return(ExtractStructMembers(temp, specifier));
                    }

                    var inDirection = typeQualifier.ChildNodes.Find(p => p.Term == mLanguage.InTerm);

                    var outDirection = typeQualifier.ChildNodes.Find(p => p.Term == mLanguage.OutTerm);

                    if (inDirection == null && outDirection == null)
                    {
                        return(0);
                    }

                    var attribute = new InputAttribute();
                    attribute.Direction = (inDirection != null) ? "in" : ((outDirection != null) ? "out" : null);
                    attribute.Layout    = new LayoutInformation();
                    ExtractLayout(attribute.Layout, typeQualifier);
                    var secondNode = node.ChildNodes [1];
                    if (!mLanguage.TypesTerms.Contains(secondNode.Token.KeyTerm))
                    {
                        return(0);
                    }

                    attribute.TypeString  = secondNode.Token.ValueString;
                    attribute.ClosestType = mTypeLookup.FindClosestType(attribute.TypeString);

                    var nameSibiling = parent.ChildNodes [1];
                    attribute.Name = nameSibiling.Token.ValueString;

                    // IGNORE
                    if (!mAttributes.ContainsKey(attribute.Name))
                    {
                        mAttributes.Add(attribute.Name, attribute);
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                int total = 0;
                foreach (ParseTreeNode child in parent.ChildNodes)
                {
                    total += FindStructsAndAttributes(child, level + 1);
                }
                return(total);
            }
        }
Exemple #15
0
        private static void AddStruct(CodeNamespace dest, CodeTypeDeclaration folder, StructInfo info)
        {
            var structType = new CodeTypeDeclaration(info.Name);

            //structType.IsClass = false;
            structType.IsStruct       = true;
            structType.TypeAttributes = TypeAttributes.Public | TypeAttributes.SequentialLayout | TypeAttributes.Sealed;

//			structType.CustomAttributes.Add(
//				new CodeAttributeDeclaration(typeof(StructLayoutAttribute),
//				new CodeAttributeArgument(
//					new CodeFieldReferenceExpression(
//							new CodeTypeReferenceExpression(typeof(LayoutKind)), "Sequential")
//					)
//				)
//			);

            dest.Types.Add(structType);

            foreach (var member in info.Members)
            {
                if (member.ClosestType != null)
                {
                    var field1 = new CodeMemberField(member.ClosestType, member.Name);
                    field1.Attributes = MemberAttributes.Public;
                    structType.Members.Add(field1);
                }
            }

//			var localVariable = "m" + alias;
//			var field1 = new CodeMemberField (typeof(string), localVariable);
//			folder.Members.Add (field1);
//
//			CodeMemberProperty property1 = new CodeMemberProperty ();
//			property1.Name = alias;
//			property1.Type = new CodeTypeReference ("System.String");
//			property1.Attributes = MemberAttributes.Public | MemberAttributes.Final;
//			property1.HasGet = true;
//			property1.HasSet = true;
//			property1.GetStatements.Add (new CodeMethodReturnStatement (new CodeFieldReferenceExpression (new CodeThisReferenceExpression (), localVariable)));
//			property1.SetStatements.Add (new CodeAssignStatement (new CodeFieldReferenceExpression (new CodeThisReferenceExpression (), localVariable), new CodePropertySetValueReferenceExpression ()));
//			folder.Members.Add (property1);
        }
        private static void AddStruct(CodeNamespace dest, CodeTypeDeclaration folder, StructInfo info)
        {
            var structType = new CodeTypeDeclaration (info.Name);
            //structType.IsClass = false;
            structType.IsStruct = true;
            structType.TypeAttributes = TypeAttributes.Public | TypeAttributes.SequentialLayout | TypeAttributes.Sealed;

            //			structType.CustomAttributes.Add(
            //				new CodeAttributeDeclaration(typeof(StructLayoutAttribute),
            //				new CodeAttributeArgument(
            //					new CodeFieldReferenceExpression(
            //							new CodeTypeReferenceExpression(typeof(LayoutKind)), "Sequential")
            //					)
            //				)
            //			);

            dest.Types.Add (structType);

            foreach (var member in info.Members)
            {
                if (member.ClosestType != null)
                {
                    var field1 = new CodeMemberField (member.ClosestType, member.Name);
                    field1.Attributes = MemberAttributes.Public;
                    structType.Members.Add (field1);
                }
            }

            //			var localVariable = "m" + alias;
            //			var field1 = new CodeMemberField (typeof(string), localVariable);
            //			folder.Members.Add (field1);
            //
            //			CodeMemberProperty property1 = new CodeMemberProperty ();
            //			property1.Name = alias;
            //			property1.Type = new CodeTypeReference ("System.String");
            //			property1.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            //			property1.HasGet = true;
            //			property1.HasSet = true;
            //			property1.GetStatements.Add (new CodeMethodReturnStatement (new CodeFieldReferenceExpression (new CodeThisReferenceExpression (), localVariable)));
            //			property1.SetStatements.Add (new CodeAssignStatement (new CodeFieldReferenceExpression (new CodeThisReferenceExpression (), localVariable), new CodePropertySetValueReferenceExpression ()));
            //			folder.Members.Add (property1);
        }