Ejemplo n.º 1
0
		public CompilationUnitNode(): base(new Token( TokenID.Invalid, 0, 0) )
		{
			this.globalAttributes = new NodeCollection<AttributeNode>();
            this.namespaces = new NodeCollection<NamespaceNode>();

            this.defaultNamespace = new NamespaceNode(RelatedToken);
		}
        public CompilationUnitNode()
            : base(new Token(TokenID.Invalid, 0, 0))
        {
            namespaces = new NodeCollection <NamespaceNode>();

            defaultNamespace = new NamespaceNode(RelatedToken);
        }
    public CompilationUnitNode()
      : base(new Token(TokenID.Invalid, 0, 0))
    {
      namespaces = new NodeCollection<NamespaceNode>();

      defaultNamespace = new NamespaceNode(RelatedToken);
    }
Ejemplo n.º 4
0
        private void BuilderNameSpace(NamespaceNode cn, CompilationUnitNode unit)
        {


            NamespaceNode nspace = new NamespaceNode(new Token(TokenID.Namespace));
            nspace.Name = cn.Name;
            mEntityUnit.Namespaces.Add(nspace);
            foreach (InterfaceNode item in cn.Interfaces)
            {
                BuilderType(item,nspace);
            }

            


        }
Ejemplo n.º 5
0
        //this parse only declared types.
        private void ParseNameSpaceTypes( NamespaceNode ns )
        {
            //first parse all delegate
            foreach (DelegateNode d in ns.Delegates)
            {
                typeStack.PushIdentifierType(d.Name.Identifier, new GraphTypeNode(IdentifierType.Delegate, d));
            }

            //parse enum
            foreach (EnumNode e in ns.Enums)
            {
                typeStack.PushIdentifierType( e.Name.Identifier, new GraphTypeNode(IdentifierType.Enum, e));
            }

            //parse Classes
            foreach (ClassNode cl in ns.Classes)
            {
                typeStack.PushIdentifierType(cl.Name.Identifier, new GraphTypeNode(IdentifierType.Class, cl));
            }

            //parse structs
            foreach (StructNode st in ns.Structs)
            {
                typeStack.PushIdentifierType(st.Name.Identifier, new GraphTypeNode(IdentifierType.Struct, st));
            }

            //parse interfaces
            foreach (InterfaceNode i in ns.Interfaces)
            {
                typeStack.PushIdentifierType(i.Name.Identifier, new GraphTypeNode(IdentifierType.Interface, i));
            }

            //other namespaces
            foreach (NamespaceNode nsChild in ns.Namespaces)
            {
                ParseNameSpaceTypes(nsChild);
            }
        }
Ejemplo n.º 6
0
        //this parse only declared types.
        private void ParseNameSpaceTypes(NamespaceNode ns)
        {
            //first parse all delegate
            foreach (DelegateNode d in ns.Delegates)
            {
                typeStack.PushIdentifierType(d.Name.Identifier, new GraphTypeNode(IdentifierType.Delegate, d));
            }

            //parse enum
            foreach (EnumNode e in ns.Enums)
            {
                typeStack.PushIdentifierType(e.Name.Identifier, new GraphTypeNode(IdentifierType.Enum, e));
            }

            //parse Classes
            foreach (ClassNode cl in ns.Classes)
            {
                typeStack.PushIdentifierType(cl.Name.Identifier, new GraphTypeNode(IdentifierType.Class, cl));
            }

            //parse structs
            foreach (StructNode st in ns.Structs)
            {
                typeStack.PushIdentifierType(st.Name.Identifier, new GraphTypeNode(IdentifierType.Struct, st));
            }

            //parse interfaces
            foreach (InterfaceNode i in ns.Interfaces)
            {
                typeStack.PushIdentifierType(i.Name.Identifier, new GraphTypeNode(IdentifierType.Interface, i));
            }

            //other namespaces
            foreach (NamespaceNode nsChild in ns.Namespaces)
            {
                ParseNameSpaceTypes(nsChild);
            }
        }
Ejemplo n.º 7
0
        public virtual object VisitNamespaceDeclaration(NamespaceNode namespaceDeclaration, object data)
        {
            stackMap.Push(namespaceDeclaration);
            namespaceDeclaration.Attributes.AcceptVisitor(this, data);

            namespaceDeclaration.Classes.AcceptVisitor(this, data);

            namespaceDeclaration.Structs.AcceptVisitor(this, data);

            namespaceDeclaration.Delegates.AcceptVisitor(this, data);

            namespaceDeclaration.Enums.AcceptVisitor(this, data);

            namespaceDeclaration.Interfaces.AcceptVisitor(this, data);

            namespaceDeclaration.ExternAliases.AcceptVisitor(this, data);

            namespaceDeclaration.Namespaces.AcceptVisitor(this, data);

            namespaceDeclaration.UsingDirectives.AcceptVisitor(this, data);

            stackMap.Pop();
            return(null);
        }
Ejemplo n.º 8
0
		private void ParseNamespace()										
		{
            Advance(); // advance over Namespace token

            NamespaceNode node = new NamespaceNode(curtok);

			if (curmods != Modifier.Empty)
				ReportError("Namespace can not contain modifiers");

            if (namespaceStack.Count == 1 /*one -> default namespace only*/)
            {

                cu.Namespaces.Add(node);
            }
            else
            {
                namespaceStack.Peek().Namespaces.Add(node);
            }

			namespaceStack.Push(node);


            node.Name = ParseQualifiedIdentifier(false, false, false);

			AssertAndAdvance(TokenID.LCurly);

            this.EnterNamespace(node.Name.QualifiedIdentifier);

			ParseNamespaceOrTypes();

            this.LeaveNamespace(node.Name.QualifiedIdentifier);

			AssertAndAdvance(TokenID.RCurly);
			namespaceStack.Pop();
		}
Ejemplo n.º 9
0
        private void BuilderType(InterfaceNode type,NamespaceNode nspace)
        {
            DDW.ClassNode cls = new ClassNode(new Token(TokenID.Public));
            cls.Modifiers = Modifier.Public;
            cls.BaseClasses.Add(new TypeNode(new IdentifierExpression("Peanut.Mappings.DataObject", new Token(TokenID.Typeof))));
            foreach (AttributeNode attr in type.Attributes)
            {
                cls.Attributes.Add(attr);
            }
            mTableName = GetTableName(type);
            mClassName = type.Name.Identifier.Substring(1, type.Name.Identifier.Length - 1);
            cls.Name = new IdentifierExpression(mClassName, new Token(TokenID.String|TokenID.Public));
            cls.IsPartial = true;
            nspace.Classes.Add(cls);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("///<summary>");
            sb.AppendLine("///Peanut Generator Copyright @ FanJianHan 2010-2013");
            sb.AppendLine("///website:http://www.ikende.com");
            if (!string.IsNullOrEmpty(type.Comment))
            {
                sb.AppendLine(type.Comment);
            }
            StringReader sr = new StringReader(type.DocComment);
            string value = sr.ReadLine();
            while (value != null)
            {
                if (value.IndexOf("summary>") == -1)
                {
                    sb.AppendLine(value);
                }
                value = sr.ReadLine();
            }
            sb.AppendLine("///</summary>");
            cls.DocComment = sb.ToString();

            foreach (InterfacePropertyNode property in type.Properties)
            {
                string propertyname = property.Names[0].GenericIdentifier;
                string fieldname= GetFieldName(property);
                FieldNode field = new FieldNode(new Token(TokenID.False));
                field.Modifiers = Modifier.Private;
                QualifiedIdentifierExpression name = new QualifiedIdentifierExpression(new Token(TokenID.String));
                name.Expressions.Add(new IdentifierExpression("m" + property.Names[0].GenericIdentifier, new Token(TokenID.String)));
                field.Names.Add(name);
                field.Type = property.Type;
                cls.Fields.Add(field);

                IType fieldtype=new TypeNode(new IdentifierExpression("Peanut.FieldInfo<"+((TypeNode)property.Type).GenericIdentifier+">", new Token(TokenID.Typeof)));
                field = new FieldNode(new Token(TokenID.False));
                field.Modifiers = Modifier.Public| Modifier.Static;
               
                NodeCollection<ArgumentNode> args = new NodeCollection<ArgumentNode>();
                args.Add(new ArgumentNode(new Token(TokenID.String)));
                args.Add(new ArgumentNode(new Token(TokenID.String)));
                args[0].Expression = new StringPrimitive(mTableName, new Token(TokenID.String));
                args[1].Expression = new StringPrimitive(fieldname, new Token(TokenID.String));

                name = new QualifiedIdentifierExpression(new Token(TokenID.String));
                name.Expressions.Add(new AssignmentExpression(TokenID.Equal,
                    new IdentifierExpression(propertyname.Substring(0, 1).ToLower() + propertyname.Substring(1, propertyname.Length - 1)
                    , new Token(TokenID.String)), new ObjectCreationExpression(fieldtype, args, new Token(TokenID.New))));
                field.Names.Add(name);
                field.Type = fieldtype;
               
                cls.Fields.Add(field);


                PropertyNode pn = new PropertyNode(new Token(TokenID.Newline));
                foreach (AttributeNode attr in property.Attributes)
                {
                    pn.Attributes.Add(attr);
                }
                pn.Names = property.Names;
                pn.Modifiers = Modifier.Public | Modifier.Virtual;
                pn.Type = property.Type;
                pn.Setter = new AccessorNode(true, new Token(TokenID.Newline));
                pn.Setter.Kind = "set";
                ExpressionStatement setvalue = new ExpressionStatement(
                    new AssignmentExpression(TokenID.Equal,
                    new IdentifierExpression("m" + property.Names[0].GenericIdentifier, new Token(TokenID.String))
                    , new IdentifierExpression("value", new Token(TokenID.String)))
                    );
                pn.Setter.StatementBlock.Statements.Add(setvalue);

                args = new NodeCollection<ArgumentNode>();
                args.Add(new ArgumentNode(new Token(TokenID.String)));
                args[0].Expression = new StringPrimitive(propertyname, new Token(TokenID.String));
                QualifiedIdentifierExpression invoke = new QualifiedIdentifierExpression(new Token(TokenID.String));
                invoke.Expressions.Add(new IdentifierExpression("EntityState", new Token(TokenID.String)));
                invoke.Expressions.Add(new InvocationExpression(new IdentifierExpression("FieldChange", new Token(TokenID.Default)), args));
                setvalue = new ExpressionStatement(invoke);
                pn.Setter.StatementBlock.Statements.Add(setvalue);

                pn.Getter = new AccessorNode(true, new Token(TokenID.Newline));
                pn.Getter.Kind = "get";
                ReturnStatement rs = new ReturnStatement(new Token(TokenID.Return));
                rs.ReturnValue = new IdentifierExpression("m" + property.Names[0].GenericIdentifier, new Token(TokenID.String));
                pn.Getter.StatementBlock.Statements.Add(rs);

                sb = new StringBuilder();
                sb.AppendLine("///<summary>");
                sb.AppendLine("///Type:" + ((TypeNode)property.Type).GenericIdentifier);
                if (!string.IsNullOrEmpty(property.Comment))
                {
                    sb.AppendLine(type.Comment);
                }
                sr = new StringReader(property.DocComment);
                value = sr.ReadLine();
                while (value != null)
                {
                    if (value.IndexOf("summary>") == -1)
                    {
                        sb.AppendLine(value);
                    }
                    value = sr.ReadLine();
                }
                sb.AppendLine("///</summary>");
                pn.DocComment = sb.ToString();
                

                cls.Properties.Add(pn);
                
            }
            //CodeTypeDeclaration entity = new CodeTypeDeclaration(mClassName);
            //CodeCommentStatement comm;
            //cns.Types.Add(entity);

           
            //comm = new CodeCommentStatement("<summary>");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //comm = new CodeCommentStatement("Peanut Generator Copyright © FanJianHan 2010-2013");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //comm = new CodeCommentStatement("website:http://www.ikende.com");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //if (!string.IsNullOrEmpty(type.Comment))
            //{
            //    comm = new CodeCommentStatement(type.Comment);
            //    comm.Comment.DocComment = true;
            //    entity.Comments.Add(comm);
            //}

            //StringReader sr = new StringReader(type.DocComment);
            //string value = sr.ReadLine();
            //while (value != null)
            //{
            //    if (value.IndexOf("summary>") == -1)
            //    {
            //        comm = new CodeCommentStatement(value.Replace("///", ""));
            //        comm.Comment.DocComment = true;
            //        entity.Comments.Add(comm);
            //    }
            //    value = sr.ReadLine();
            //}
            //comm = new CodeCommentStatement("</summary>");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //// }
            //entity.BaseTypes.Add(new CodeTypeReference("Peanut.Mappings.DataObject"));
            //entity.BaseTypes.Add(new CodeTypeReference(type.Name.Identifier));
            //entity.Attributes = MemberAttributes.Public;
            //entity.IsPartial = true;
            //entity.CustomAttributes.Add(new CodeAttributeDeclaration("Serializable"));
            //entity.IsClass = true;
            //foreach (AttributeNode aitem in type.Attributes)
            //{
            //    CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(aitem.Name.GenericIdentifier);
            //    entity.CustomAttributes.Add(attribute);
            //    if (attribute.Name.ToLower() == "table")
            //    {
            //        if (aitem.Arguments.Count > 0)
            //        {

            //            DDW.StringPrimitive pe = (DDW.StringPrimitive)aitem.Arguments[0].Expression;
            //            if (pe != null)
            //            {
            //                mTableName = pe.Value.ToString();
            //            }
            //            else
            //            {
            //                mTableName = mClassName;

            //            }
            //            attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(mTableName)));
            //        }
            //        else
            //        {
            //            mTableName = mClassName;
            //        }
            //    }

            //}
            //foreach (InterfacePropertyNode mitem in type.Properties)
            //{


            //    BuilderProperty(entity, mitem);

            //}



        }
Ejemplo n.º 10
0
        public virtual object VisitNamespaceDeclaration(NamespaceNode namespaceDeclaration, object data)
        {
            stackMap.Push(namespaceDeclaration);
            namespaceDeclaration.Attributes.AcceptVisitor(this, data);

            namespaceDeclaration.Classes.AcceptVisitor(this, data);
            
            namespaceDeclaration.Structs.AcceptVisitor(this, data);

            namespaceDeclaration.Delegates.AcceptVisitor(this, data);

            namespaceDeclaration.Enums.AcceptVisitor(this, data);

            namespaceDeclaration.Interfaces.AcceptVisitor(this, data);

            namespaceDeclaration.ExternAliases.AcceptVisitor(this, data);

            namespaceDeclaration.Namespaces.AcceptVisitor(this, data);

             namespaceDeclaration.UsingDirectives.AcceptVisitor(this, data);

             stackMap.Pop();
             return null;

        }