Beispiel #1
0
        public virtual object VisitInterfaceDeclaration(InterfaceNode interfaceDeclaration, object data)
        {
            stackMap.Push(interfaceDeclaration);
            interfaceDeclaration.Attributes.AcceptVisitor(this, data);

            interfaceDeclaration.BaseClasses.AcceptVisitor(this, data);

            interfaceDeclaration.Events.AcceptVisitor(this, data);

            if (interfaceDeclaration.Generic != null)
            {
                interfaceDeclaration.Generic.AcceptVisitor(this, data);
            }

            interfaceDeclaration.Indexers.AcceptVisitor(this, data);

            interfaceDeclaration.Methods.AcceptVisitor(this, data);

            if (interfaceDeclaration.Partials != null)
            {
                interfaceDeclaration.Partials.AcceptVisitor(this, data);
            }

            interfaceDeclaration.Properties.AcceptVisitor(this, data);

            stackMap.Pop();
            return(null);
        }
Beispiel #2
0
		private void ParseInterface()										
		{
			InterfaceNode node = new InterfaceNode(curtok);
			curInterface = node;

            node.IsPartial = nextIsPartial;
            nextIsPartial = false;

			uint interfaceMask = ~(uint)Modifier.InterfaceMods;
			if (((uint)curmods & interfaceMask) != (uint)Modifier.Empty)
				ReportError("Interface contains illegal modifiers");
			
			if (curAttributes.Count > 0)
			{
				node.Attributes = curAttributes;
				curAttributes = new NodeCollection<AttributeNode>();
			}

			node.Modifiers = curmods;
			curmods = Modifier.Empty;

            if ((node.Modifiers & Modifier.Unsafe) != Modifier.Empty)
            {
                //unsafe modifier -> unsafe type.
                isUnsafe++;
                node.IsUnsafeDeclared = true;
            }
                //the interface is declared in an unsafe type ?
                node.IsUnsafe = isUnsafe > 0;

			Advance(); // advance over Interface token
            node.Name = (IdentifierExpression)ParseIdentifierOrKeyword(false, false, false, true);

            ParsePossibleTypeParameterNode(true, true, false);
            ApplyTypeParameters(node);

			if (curtok.ID == TokenID.Colon) // for base members
			{
				Advance();
				node.BaseClasses.Add(ParseType());
				while (curtok.ID == TokenID.Comma)
				{
					Advance();
					node.BaseClasses.Add(ParseType());
				}
			}

            ParsePossibleTypeParameterConstraintNode(node);
            ApplyTypeParameterConstraints(node);

            CheckTypeUnicityAndAdd(node);

            if (node.IsGeneric)
            {
                this.nameTable.AddIdentifier(new InterfaceName(node.Name.Identifier,
                    ToVisibilityRestriction(node.Modifiers), 
                    node.Generic.TypeParameters.ConvertAll<string>(delegate(TypeParameterNode input) { return input.Identifier.Identifier; }).ToArray(),
                    this.currentContext));
            }
            else
            {
                this.nameTable.AddIdentifier(new InterfaceName(node.Name.Identifier,
                    ToVisibilityRestriction(node.Modifiers),
                    this.currentContext));
            }

            this.currentContext.Enter(node.Name.Identifier, false);

            ClassNode cl = typeStack.Count == 0 ? null : typeStack.Peek();

            if (cl == null)
            {
                namespaceStack.Peek().Interfaces.Add(node);
            }
            else
            {
                cl.Interfaces.Add(node);
            }

			AssertAndAdvance(TokenID.LCurly);

			while (curtok.ID != TokenID.RCurly) // guard for empty
			{
				ParseInterfaceMember();
			}

			AssertAndAdvance(TokenID.RCurly);

            if ((node.Modifiers & Modifier.Unsafe) != Modifier.Empty)
            {
                //unsafe modifier -> unsafe type.
                isUnsafe--;
            }

            this.currentContext.Leave();

			curInterface = null;

		}
Beispiel #3
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);

            //}



        }
Beispiel #4
0
        private string GetTableName(InterfaceNode type)
        {
            string mClassName = type.Name.Identifier.Substring(1, type.Name.Identifier.Length - 1);
            foreach (AttributeNode attr in type.Attributes)
            {
               
                if (attr.Name.GenericIdentifier.ToLower() == "table")
                {
                    if (attr.Arguments.Count > 0)
                    {

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

                        }

                    }
                    else
                    {
                        return  mClassName;
                    }
                }
            }
             return  mClassName;
        }
        public virtual object VisitInterfaceDeclaration(InterfaceNode interfaceDeclaration, object data)
        {
            stackMap.Push(interfaceDeclaration);
            interfaceDeclaration.Attributes.AcceptVisitor(this, data);

            interfaceDeclaration.BaseClasses.AcceptVisitor(this, data);
            
            interfaceDeclaration.Events.AcceptVisitor(this, data);

            if (interfaceDeclaration.Generic != null)
            {
                interfaceDeclaration.Generic.AcceptVisitor(this, data);
            }

            interfaceDeclaration.Indexers.AcceptVisitor(this, data);

            interfaceDeclaration.Methods.AcceptVisitor(this, data);

            if (interfaceDeclaration.Partials != null)
            {
                interfaceDeclaration.Partials.AcceptVisitor(this, data);
            }

            interfaceDeclaration.Properties.AcceptVisitor(this, data);

            stackMap.Pop();
            return null;

        }