Esempio n. 1
0
        private void ParseClassDeclaration(Class_definitionContext node)
        {
            var members = node.class_body().class_member_declarations().class_member_declaration();

            foreach (var member in members)
            {
                Common_member_declarationContext child = member.GetRuleContext <Common_member_declarationContext>(0);

                if (child is Common_member_declarationContext)
                {
                    Common_member_declarationContext commonMemberContext = child as Common_member_declarationContext;

                    Event_declarationContext        eventContext      = commonMemberContext.event_declaration();
                    Typed_member_declarationContext typeMemberContext = commonMemberContext.typed_member_declaration();
                    Method_declarationContext       methodContext     = commonMemberContext.method_declaration();

                    string type = "";
                    string name = "";

                    if (eventContext != null)
                    {
                        type = "Event";
                        name = eventContext.variable_declarators().GetText();
                    }

                    if (typeMemberContext != null)
                    {
                        Field_declarationContext    field    = typeMemberContext.field_declaration();
                        Property_declarationContext property = typeMemberContext.property_declaration();

                        if (field != null)
                        {
                            type = "Field";
                            name = field.variable_declarators().GetText();
                        }
                        else if (property != null)
                        {
                            type = "Property";
                            name = property.member_name().GetText();
                        }
                    }
                    else if (methodContext != null)
                    {
                        type = "Method";
                        name = methodContext.method_member_name().GetText();
                    }

                    if (!string.IsNullOrEmpty(name))
                    {
                        this.WriteKeyValue(type, name);
                    }
                }
            }
        }
        /// <summary>
        /// Define field, property, of class, struct
        /// </summary>
        /// <param name="context"></param>
        public override void EnterProperty_declaration([NotNull] Property_declarationContext context)
        {
            var propertyIdentityContext = context.member_name().namespace_or_type_name().identifier();
            int identityCount           = propertyIdentityContext.Length;
            var lastedIdentityContext   = propertyIdentityContext[identityCount - 1]; //property name of class, struct

            FieldSymbol fieldSymbol = new FieldSymbol(lastedIdentityContext.GetText())
            {
                DefNode = lastedIdentityContext
            };

            lastedIdentityContext.Symbol = fieldSymbol;
            lastedIdentityContext.Scope  = currentScope;

            Define(fieldSymbol);
        }
Esempio n. 3
0
        public void Enter_Property_declaration(Property_declarationContext context)
        {
            var propName = context.Start.Text;
            var parent   = context.Parent;

            //int anscestorLevel = 4;
            //anscestorLevel > 1 ||
            while (parent.GetType() != typeof(Class_member_declarationsContext))
            {
                parent = parent.Parent;
                //anscestorLevel--;
            }
            var parentInstance = parent as Class_member_declarationsContext;
            var accessMod      = parentInstance.Start.Text;

            CheckPropRuleAndUpdateErrorList(propName, accessMod);
        }
        private List <IdentifierContext> SetTypeForProperty(Property_declarationContext context, IType type)
        {
            //set type for property
            //Example Property: int A.B.C {get; set;}
            var propertyIdentityContext = context.member_name().namespace_or_type_name().identifier();

            //resolve A find B, resolve B, find C.
            IScope parentScope = currentScope;

            for (int i = 0; i < propertyIdentityContext.Length - 1; i++)
            {
                var     item      = propertyIdentityContext[i];
                ISymbol tempScope = parentScope.ResolveType(item.GetText());
                if (tempScope != null)
                {
                    item.Symbol = tempScope;
                    item.Scope  = (IScope)tempScope;
                    parentScope = (IScope)tempScope;
                }
                else
                {
                    //error cannot find symbol in parentScope
                    //AddError(new ErrorInformation());
                    return(null);
                }
            }
            //check c in A.B
            var symbol = parentScope.Resolve(propertyIdentityContext.Last().GetText());

            if (symbol != null)
            {
                //symbol C in A.B then set type for C
                (symbol as FieldSymbol).SetType(type);
                return(new List <IdentifierContext>(new IdentifierContext[] { propertyIdentityContext.Last() }));
            }
            else
            {
                //error, cannot find symbol in parentScope
                //AddError(new ErrorInformation());
                return(null);
            }
        }
        //public override void EnterClass_member_declaration([NotNull] Class_member_declarationContext context)
        //{
        //    base.EnterClass_member_declaration(context);
        //}

        //public override void EnterBase_type([NotNull] Base_typeContext context)
        //{
        //    base.EnterBase_type(context);
        //}

        //const string privatePropertyRegex = "^_[a-z]+[A-Z0-9]+[a-z0-9]*";
        //const string publicPropertyRegex = "^[A-Z]+[a-z0-9]+[A-Z0-9]*[a-z0-9]+";

        public override void EnterProperty_declaration([NotNull] Property_declarationContext context)
        {
            base.EnterProperty_declaration(context);
            _interfaceExtractRule.Enter_Property_declaration(context);

            //var propName = context.Start.Text;
            //var parent = context.Parent;
            ////int anscestorLevel = 4;
            ////anscestorLevel > 1 ||
            //while (parent.GetType() != typeof(Class_member_declarationsContext))
            //{
            //    parent = parent.Parent;
            //    //anscestorLevel--;
            //}

            //var parentInstance = parent as Class_member_declarationsContext;
            //var accessMod = parentInstance.Start.Text;
            //string currentRegexString = string.Empty;
            //switch (accessMod.ToLower())
            //{
            //    case "private":
            //        //startswith _ and followed by camelCase (_fieldName)
            //        currentRegexString = privatePropertyRegex;
            //        break;
            //    case "public":
            //    case "protected":
            //        //PascalCase
            //        currentRegexString = publicPropertyRegex;
            //        //camelCase without _
            //        break;
            //    default:
            //        break;
            //}

            //var match = Regex.Match(propName, currentRegexString);
            //if (match.Length < propName.Length)
            //{
            //    _nameRuleErrors.Add(new NameRuleError(NameRuleViolations.PropertyNameRuleViolation, string.Empty, string.Empty, string.Empty, string.Empty));
            //}
        }
Esempio n. 6
0
	public Property_declarationContext property_declaration() {
		Property_declarationContext _localctx = new Property_declarationContext(_ctx, State);
		EnterRule(_localctx, 26, RULE_property_declaration);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 374; Match(PROPERTY);
			State = 376;
			_la = _input.La(1);
			if (_la==LPAREN) {
				{
				State = 375; property_attributes_declaration();
				}
			}

			State = 378; struct_declaration();
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.ReportError(this, re);
			_errHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}