コード例 #1
0
ファイル: ReflectorStatic.cs プロジェクト: timonela/mb-unit
 /// <summary>
 /// Get field value.
 /// </summary>
 /// <param name="access">Specify field access modifier.</param>
 /// <param name="obj">Object where field is defined.</param>
 /// <param name="fieldName">Field name.</param>
 /// <param name="lookInBase">Specify if need to look in Base classes.</param>
 /// <returns>Field value</returns>
 public static object GetField(AccessModifier access, object obj, string fieldName, bool lookInBase)
 {
     CheckObject(obj);
     FieldInfo fi = GetField(access, obj.GetType(), fieldName, lookInBase);
     IsMember(obj, fi, fieldName, MemberType.Field);
     return fi.GetValue(obj);
 }
コード例 #2
0
ファイル: Field.cs プロジェクト: ignacio1029/blueprint
 public Field(string name, string type, bool isStatic, AccessModifier am)
 {
     Name = name;
     Type = type;
     Static = isStatic;
     AccessModifier = am;
 }
コード例 #3
0
ファイル: Naming.cs プロジェクト: cmcginn/AIM
 public static string GetModifier(AccessModifier? access, MemberModifier? modifier)
 {
     if (modifier == null)
         return access.ToString().ToLower();
     else
         return string.Format("{0} {1}", access.ToString().ToLower(), modifier.ToString().ToLower());
 }
コード例 #4
0
ファイル: ClassModifier.cs プロジェクト: fengweijp/higlabo
 public ClassModifier(AccessModifier accessModifier)
 {
     this.AccessModifier = accessModifier;
     this.Static = false;
     this.Abstract = false;
     this.Partial = false;
 }
コード例 #5
0
ファイル: Method.cs プロジェクト: ignacio1029/blueprint
 public Method(string name, string retType, bool isStatic, AccessModifier am, params string[] paramTypes)
 {
     Name = name;
     ReturnType = retType;
     Static = isStatic;
     AccessModifier = am;
     ParameterTypes = paramTypes;
 }
コード例 #6
0
		public LanguageItem (Tag tag, Project project)
		{
			this.project = project;
			this.name = tag.Name;
			this.file = tag.File;
			this.pattern = tag.Pattern;
			this.access = tag.Access;
		}
コード例 #7
0
		public LanguageItem (Tag tag, Project project)
		{
			this.project = project;
			this.name = tag.Name;
			this.file = tag.File;
			this.line = tag.Line;
			this.access = tag.Access;
		}
コード例 #8
0
 public FunctionDeclarationHeader(SymbolDefinition name, AccessModifier visibility, FunctionType type)
     : base(CodeElementType.FunctionDeclarationHeader)
 {
     this.FunctionName = name;
     this.Visibility = visibility;
     this.UserDefinedType = type != null ? type : FunctionType.Undefined;
     this.Profile = new ParametersProfile();
 }
コード例 #9
0
ファイル: Constructor.cs プロジェクト: fengweijp/higlabo
 public Constructor(AccessModifier accessModifier, String name)
 {
     this.Modifier = new ConstructorModifier(accessModifier);
     this.Name = name;
     this.Parameters = new List<MethodParameter>();
     this.GenericParameters = new List<String>();
     this.Body = new CodeBlockCollection();
 }
コード例 #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="AccessModifier">Access modifier</param>
 /// <param name="ClassName">Class name</param>
 /// <param name="ParameterList">Parameter list</param>
 /// <param name="Body">Body of the constructor</param>
 /// <param name="Parser">Parser to use</param>
 public Constructor(AccessModifier AccessModifier, string ClassName, IParameter[] ParameterList, string Body, IParser Parser)
     : base(Parser)
 {
     this.AccessModifier = AccessModifier;
     this.ClassName = ClassName;
     this.Parameters = ParameterList.ToList();
     this.Body = Body;
 }
コード例 #11
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="parentNode">Node</param>
        /// <param name="isStart">Is start state</param>
        /// <param name="accMod">Access modifier</param>
        internal void Visit(MachineDeclaration parentNode, bool isStart, AccessModifier accMod)
        {
            var node = new StateDeclaration(base.TokenStream.Program, parentNode,
                isStart, parentNode.IsModel);
            node.AccessModifier = accMod;
            node.StateKeyword = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected state identifier.",
                    new List<TokenType>
                {
                    TokenType.Identifier
                });
            }

            base.TokenStream.CurrentState = base.TokenStream.Peek().Text;
            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                TokenType.StateIdentifier));

            node.Identifier = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".",
                    new List<TokenType>
                {
                    TokenType.LeftCurlyBracket
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                TokenType.StateLeftCurlyBracket));

            node.LeftCurlyBracketToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Program is PSharpProgram)
            {
                this.VisitNextPSharpIntraStateDeclaration(node);
            }
            else
            {
                this.VisitNextPIntraStateDeclaration(node);
            }

            parentNode.StateDeclarations.Add(node);
        }
コード例 #12
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="parentNode">Node</param>
        /// <param name="typeIdentifier">Type identifier</param>
        /// <param name="identifier">Identifier</param>
        /// <param name="accMod">Access modifier</param>
        /// <param name="inhMod">Inheritance modifier</param>
        /// <param name="isAsync">Is async</param>
        /// <param name="isPartial">Is partial</param>
        internal void Visit(MachineDeclaration parentNode, Token typeIdentifier, Token identifier,
            AccessModifier accMod, InheritanceModifier inhMod, bool isAsync, bool isPartial)
        {
            var node = new MethodDeclaration(base.TokenStream.Program, parentNode);
            node.AccessModifier = accMod;
            node.InheritanceModifier = inhMod;
            node.TypeIdentifier = typeIdentifier;
            node.Identifier = identifier;
            node.IsAsync = isAsync;
            node.IsPartial = isPartial;

            node.LeftParenthesisToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            while (!base.TokenStream.Done &&
                base.TokenStream.Peek().Type != TokenType.RightParenthesis)
            {
                base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit));

                node.Parameters.Add(base.TokenStream.Peek());

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            node.RightParenthesisToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket &&
                base.TokenStream.Peek().Type != TokenType.Semicolon))
            {
                throw new ParsingException("Expected \"{\" or \";\".",
                    new List<TokenType>
                {
                    TokenType.LeftCurlyBracket,
                    TokenType.Semicolon
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.LeftCurlyBracket)
            {
                var blockNode = new BlockSyntax(base.TokenStream.Program, parentNode, null);
                new BlockSyntaxVisitor(base.TokenStream).Visit(blockNode);
                node.StatementBlock = blockNode;
            }
            else if (base.TokenStream.Peek().Type == TokenType.Semicolon)
            {
                node.SemicolonToken = base.TokenStream.Peek();
            }

            parentNode.MethodDeclarations.Add(node);
        }
コード例 #13
0
 public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context)
 {
     AccessModifier[] accessModifierArr = new AccessModifier[5];
     accessModifierArr[1] = AccessModifier.Assembly;
     accessModifierArr[2] = AccessModifier.Private;
     accessModifierArr[3] = AccessModifier.Family;
     accessModifierArr[4] = AccessModifier.FamilyOrAssembly;
     return new System.ComponentModel.TypeConverter.StandardValuesCollection(accessModifierArr);
 }
コード例 #14
0
ファイル: Function.cs プロジェクト: laurentprudhon/TypeCobol
 /// <summary>Creates functions or procedure</summary>
 public Function(QualifiedName name, IList<ParameterDescription> inputs, IList<ParameterDescription> outputs, IList<ParameterDescription> inouts, ParameterDescription returning, AccessModifier visibility = AccessModifier.Private)
 {
     QualifiedName = name;
     Profile = new ParametersProfile();
     Profile.InputParameters  = inputs  ?? new List<ParameterDescription>();
     Profile.OutputParameters = outputs ?? new List<ParameterDescription>();
     Profile.InoutParameters  = inouts  ?? new List<ParameterDescription>();
     Profile.ReturningParameter = returning;
     Visibility = visibility;
 }
コード例 #15
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="AccessModifier">Access modifier</param>
 /// <param name="Modifier">Modifier</param>
 /// <param name="Type">Type</param>
 /// <param name="FunctionName">Function name</param>
 /// <param name="ParameterList">Parameter list</param>
 /// <param name="Body">Body of the function</param>
 /// <param name="Parser">Parser to use</param>
 public Function(AccessModifier AccessModifier, Modifiers Modifier, string Type,
     string FunctionName, IParameter[] ParameterList, string Body, IParser Parser)
     : base(Parser)
 {
     this.AccessModifier = AccessModifier;
     this.Modifier = Modifier;
     this.Type = Type;
     this.Name = FunctionName;
     this.Parameters = ParameterList.ToList();
     this.Body = Body;
 }
コード例 #16
0
ファイル: IMember.Shared.cs プロジェクト: fiinix00/Saltarelle
		public static string WriteDeclarator(AccessModifier am, string type, string name) {
			string s;
			switch (am) {
				case AccessModifier._Public:            s = "public "; break;
				case AccessModifier._Protected:         s = "protected "; break;
				case AccessModifier._Private:           s = "private "; break;
				case AccessModifier._Internal:          s = "internal "; break;
				case AccessModifier._ProtectedInternal: s = "protected internal "; break;
				case AccessModifier._None:              s = ""; break;
				default: throw Utils.ArgumentException("am");
			}
			return s + type + " " + name;
		}
コード例 #17
0
ファイル: Class.cs プロジェクト: fengweijp/higlabo
 public Class(AccessModifier modifier, String name)
 {
     this.Modifier = new ClassModifier(modifier);
     this.Name = name;
     this.ImplementInterfaces = new List<TypeName>();
     this.Fields = new List<Field>();
     this.Properties = new List<Property>();
     this.Constructors = new List<Constructor>();
     this.Methods = new List<Method>();
     this.Interfaces = new List<Interface>();
     this.Classes = new List<Class>();
     this.Enums = new List<Enum>();
 }
コード例 #18
0
 public Class(AccessModifier AccessModifier, Modifiers Modifier, string ClassName,
     string Namespace)
     : base()
 {
     Properties = new List<IProperty>();
     Usings = new List<Using>();
     Constructors = new List<IFunction>();
     Functions = new List<IFunction>();
     this.ClassName = ClassName;
     this.AccessModifier = AccessModifier;
     this.Modifier = Modifier;
     this.Namespace = Namespace;
 }
コード例 #19
0
        public virtual void AddProperty(AccessModifier accessModifier, VirtualModifier virtualModifier,
            [NotNull] string propertyTypeName, [NotNull] string propertyName, [NotNull] IndentedStringBuilder sb)
        {
            Check.NotEmpty(propertyTypeName, nameof(propertyTypeName));
            Check.NotEmpty(propertyName, nameof(propertyName));
            Check.NotNull(sb, nameof(sb));

            AppendAccessModifier(accessModifier, sb);
            AppendVirtualModifier(virtualModifier, sb);
            sb.Append(propertyTypeName);
            sb.Append(" ");
            sb.Append(propertyName);
            sb.AppendLine(" { get; set; }");
        }
コード例 #20
0
        public override void Write(AccessModifier modifier)
        {
            var writer = this.TextWriter;

            switch (modifier)
            {
                case AccessModifier.Public: writer.Write("Public"); break;
                case AccessModifier.Private: writer.Write("Private"); break;
                case AccessModifier.Protected: writer.Write("Protected"); break;
                case AccessModifier.Internal: writer.Write("Internal"); break;
                case AccessModifier.ProtectedInternal: writer.Write("Protected Internal"); break;
                default: throw new NotSupportedException();
            }
        }
コード例 #21
0
		public PropertyMember(string name, string serverType, string clientType, AccessModifier accessModifier, string backingFieldName, string backingFieldServerType, string backingFieldClientType, bool hasGetter, bool hasSetter, string valueChangedHookName, bool clientInject) {
			if (string.IsNullOrEmpty(name)) throw Utils.ArgumentException("name");
			if (string.IsNullOrEmpty(backingFieldName)) throw Utils.ArgumentException("backingFieldName");
			if (!hasGetter && !hasSetter) throw Utils.ArgumentException("Must have getter or setter.");
			if (string.IsNullOrEmpty(serverType) != string.IsNullOrEmpty(backingFieldServerType)) throw Utils.ArgumentException("serverType and backingFieldServerType must both be either null or non-null.");
			if (string.IsNullOrEmpty(clientType) != string.IsNullOrEmpty(backingFieldClientType)) throw Utils.ArgumentException("clientType and backingFieldClientType must both be either null or non-null.");
			if (valueChangedHookName != null && !ParserUtils.IsValidUnqualifiedName(valueChangedHookName)) throw Utils.ArgumentException("valueChangedHookName");
			
			this.name = name;
			this.serverType = serverType;
			this.clientType = clientType;
			this.accessModifier = accessModifier;
			this.backingFieldName = backingFieldName;
			this.backingFieldServerType = backingFieldServerType;
			this.backingFieldClientType = backingFieldClientType;
			this.hasGetter = hasGetter;
			this.hasSetter = hasSetter;
			this.valueChangedHookName = valueChangedHookName;
			this.clientInject = clientInject;
		}
コード例 #22
0
        public virtual void BeginClass(AccessModifier accessModifier, [NotNull] string className,
            bool isPartial, [NotNull] IndentedStringBuilder sb, [CanBeNull] ICollection<string> inheritsFrom = null)
        {
            Check.NotEmpty(className, nameof(className));
            Check.NotNull(sb, nameof(sb));

            AppendAccessModifier(accessModifier, sb);
            if (isPartial)
            {
                sb.Append("partial ");
            }
            sb.Append("class ");
            sb.Append(className);
            if (inheritsFrom != null && inheritsFrom.Count > 0)
            {
                sb.Append(" : ");
                sb.Append(string.Join(", ", inheritsFrom));
            }
            sb.AppendLine();
            sb.AppendLine("{");
            sb.IncrementIndent();
        }
コード例 #23
0
ファイル: Tag.cs プロジェクト: Kalnor/monodevelop
		public Tag (string name,
		            string file,
		            UInt64 line,
		            TagKind kind,
		            AccessModifier access,
		            string field_class,
		            string field_namespace,
		            string field_struct,
		            string field_union,
		            string field_enum,
		            string field_signature)
		{
			this.name = name;
			this.file = file;
			this.line = line;	
			this.kind = kind;
			this.access = access;
			this.field_class = field_class;
			this.field_namespace = field_namespace;
			this.field_struct = field_struct;
			this.field_union = field_union;
			this.field_enum = field_enum;
			this.field_signature = field_signature;
		}
コード例 #24
0
 private ConstructorBuilder()
 {
     _modifier = AccessModifier.Public;
 }
コード例 #25
0
 public Identifier(AccessModifier access, int id)
 {
     this.Access = access;
     this.Id     = id.ToString();
 }
コード例 #26
0
ファイル: MethodUtil.cs プロジェクト: NDK313/CM3D2
 /// <summary>
 ///     MethodData 구조체의 새 인스턴스를 초기화합니다.
 /// </summary>
 /// <param name="methodAccessModifier">저장할 메서드의 접근 제한자입니다.</param>
 /// <param name="data">저장할 메서드의 데이터입니다.</param>
 public MethodData(AccessModifier methodAccessModifier, byte[] data)
 {
     this.methodAccessModifier = methodAccessModifier;
     this.data = data;
 }
コード例 #27
0
 /// <summary>
 /// Sets accessibilty modifier of the field being built.
 /// </summary>
 public FieldBuilder WithAccessModifier(AccessModifier accessModifier)
 {
     Field = Field.With(accessModifier: Option.Some(accessModifier));
     return(this);
 }
コード例 #28
0
 public MethodCode SetAccessModifier(AccessModifier acesMdfr)
 {
     accessModifier = acesMdfr;
     return(this);
 }
コード例 #29
0
 public JsonFieldsCollector1(JToken token, AccessModifier accessModifier)
 {
     fields = new Dictionary <string, JValue>();
     CollectFields(token);
 }
コード例 #30
0
        /// <summary>
        /// This method parses and returns the children within the public/protected/private block under a C++ class, 
        /// and sets the specified access modifier on the children that support it.
        /// </summary>
        private IEnumerable<Statement> ParseClassChildren(XElement accessBlockElement, ParserContext context, AccessModifier accessModifier) {
            if(accessBlockElement == null)
                throw new ArgumentNullException("accessBlockElement");
            if(!(new[] {SRC.Public, SRC.Protected, SRC.Private}.Contains(accessBlockElement.Name)))
                throw new ArgumentException("Not a valid accessibility block element", "accessBlockElement");
            if(context == null)
                throw new ArgumentNullException("context");

            var children = accessBlockElement.Elements().Select(e => ParseStatement(e, context)).ToList();
            foreach(var ne in children.OfType<INamedEntity>()) {
                ne.Accessibility = accessModifier;
            }
            return children;
        }
コード例 #31
0
 public Injector To(AccessModifier modifiers, bool recursive = false)
 {
     return(To(TargetField.Name, modifiers, recursive));
 }
コード例 #32
0
        /// <summary>
        /// Visits a machine level declaration.
        /// </summary>
        /// <param name="parentNode">Node</param>
        private void VisitMachineLevelDeclaration(MachineDeclaration parentNode)
        {
            AccessModifier      am = AccessModifier.None;
            InheritanceModifier im = InheritanceModifier.None;
            bool isStart           = false;
            bool isModel           = false;
            bool isAsync           = false;

            while (!base.TokenStream.Done &&
                   base.TokenStream.Peek().Type != TokenType.StateDecl &&
                   base.TokenStream.Peek().Type != TokenType.MachineDecl &&
                   base.TokenStream.Peek().Type != TokenType.Void &&
                   base.TokenStream.Peek().Type != TokenType.Object &&
                   base.TokenStream.Peek().Type != TokenType.String &&
                   base.TokenStream.Peek().Type != TokenType.Sbyte &&
                   base.TokenStream.Peek().Type != TokenType.Byte &&
                   base.TokenStream.Peek().Type != TokenType.Short &&
                   base.TokenStream.Peek().Type != TokenType.Ushort &&
                   base.TokenStream.Peek().Type != TokenType.Int &&
                   base.TokenStream.Peek().Type != TokenType.Uint &&
                   base.TokenStream.Peek().Type != TokenType.Long &&
                   base.TokenStream.Peek().Type != TokenType.Ulong &&
                   base.TokenStream.Peek().Type != TokenType.Char &&
                   base.TokenStream.Peek().Type != TokenType.Bool &&
                   base.TokenStream.Peek().Type != TokenType.Decimal &&
                   base.TokenStream.Peek().Type != TokenType.Float &&
                   base.TokenStream.Peek().Type != TokenType.Double &&
                   base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                if (am != AccessModifier.None &&
                    (base.TokenStream.Peek().Type == TokenType.Public ||
                     base.TokenStream.Peek().Type == TokenType.Private ||
                     base.TokenStream.Peek().Type == TokenType.Protected ||
                     base.TokenStream.Peek().Type == TokenType.Internal))
                {
                    throw new ParsingException("More than one protection modifier.",
                                               new List <TokenType>());
                }
                else if (im != InheritanceModifier.None &&
                         base.TokenStream.Peek().Type == TokenType.Abstract)
                {
                    throw new ParsingException("Duplicate abstract modifier.",
                                               new List <TokenType>());
                }
                else if (isStart &&
                         base.TokenStream.Peek().Type == TokenType.StartState)
                {
                    throw new ParsingException("Duplicate start state modifier.",
                                               new List <TokenType>());
                }
                else if (isModel &&
                         base.TokenStream.Peek().Type == TokenType.ModelDecl)
                {
                    throw new ParsingException("Duplicate model method modifier.",
                                               new List <TokenType>());
                }
                else if (isAsync &&
                         base.TokenStream.Peek().Type == TokenType.Async)
                {
                    throw new ParsingException("Duplicate async method modifier.",
                                               new List <TokenType>());
                }

                if (base.TokenStream.Peek().Type == TokenType.Public)
                {
                    am = AccessModifier.Public;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Private)
                {
                    am = AccessModifier.Private;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Protected)
                {
                    am = AccessModifier.Protected;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Internal)
                {
                    am = AccessModifier.Internal;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Abstract)
                {
                    im = InheritanceModifier.Abstract;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Virtual)
                {
                    im = InheritanceModifier.Virtual;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Override)
                {
                    im = InheritanceModifier.Override;
                }
                else if (base.TokenStream.Peek().Type == TokenType.StartState)
                {
                    isStart = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.ModelDecl)
                {
                    isModel = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Async)
                {
                    isAsync = true;
                }

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.StateDecl &&
                 base.TokenStream.Peek().Type != TokenType.MachineDecl &&
                 base.TokenStream.Peek().Type != TokenType.Void &&
                 base.TokenStream.Peek().Type != TokenType.Object &&
                 base.TokenStream.Peek().Type != TokenType.String &&
                 base.TokenStream.Peek().Type != TokenType.Sbyte &&
                 base.TokenStream.Peek().Type != TokenType.Byte &&
                 base.TokenStream.Peek().Type != TokenType.Short &&
                 base.TokenStream.Peek().Type != TokenType.Ushort &&
                 base.TokenStream.Peek().Type != TokenType.Int &&
                 base.TokenStream.Peek().Type != TokenType.Uint &&
                 base.TokenStream.Peek().Type != TokenType.Long &&
                 base.TokenStream.Peek().Type != TokenType.Ulong &&
                 base.TokenStream.Peek().Type != TokenType.Char &&
                 base.TokenStream.Peek().Type != TokenType.Bool &&
                 base.TokenStream.Peek().Type != TokenType.Decimal &&
                 base.TokenStream.Peek().Type != TokenType.Float &&
                 base.TokenStream.Peek().Type != TokenType.Double &&
                 base.TokenStream.Peek().Type != TokenType.Identifier))
            {
                throw new ParsingException("Expected state or method declaration.",
                                           new List <TokenType>
                {
                    TokenType.StateDecl,
                    TokenType.MachineDecl,
                    TokenType.Void,
                    TokenType.Object,
                    TokenType.String,
                    TokenType.Sbyte,
                    TokenType.Byte,
                    TokenType.Short,
                    TokenType.Ushort,
                    TokenType.Int,
                    TokenType.Uint,
                    TokenType.Long,
                    TokenType.Ulong,
                    TokenType.Char,
                    TokenType.Bool,
                    TokenType.Decimal,
                    TokenType.Float,
                    TokenType.Double,
                    TokenType.Identifier
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.StateDecl)
            {
                if (am == AccessModifier.Public)
                {
                    throw new ParsingException("A state cannot be public.",
                                               new List <TokenType>());
                }
                else if (am == AccessModifier.Internal)
                {
                    throw new ParsingException("A state cannot be internal.",
                                               new List <TokenType>());
                }

                if (im == InheritanceModifier.Abstract)
                {
                    throw new ParsingException("A state cannot be abstract.",
                                               new List <TokenType>());
                }
                else if (im == InheritanceModifier.Virtual)
                {
                    throw new ParsingException("A state cannot be virtual.",
                                               new List <TokenType>());
                }
                else if (im == InheritanceModifier.Override)
                {
                    throw new ParsingException("A state cannot be overriden.",
                                               new List <TokenType>());
                }

                if (isModel)
                {
                    throw new ParsingException("A state cannot be a model.",
                                               new List <TokenType>());
                }

                if (isAsync)
                {
                    throw new ParsingException("A state cannot be async.",
                                               new List <TokenType>());
                }

                new StateDeclarationVisitor(base.TokenStream).Visit(parentNode, isStart, am);
            }
            else
            {
                if (am == AccessModifier.Public)
                {
                    throw new ParsingException("A field or method cannot be public.",
                                               new List <TokenType>());
                }
                else if (am == AccessModifier.Internal)
                {
                    throw new ParsingException("A field or method cannot be internal.",
                                               new List <TokenType>());
                }

                new FieldOrMethodDeclarationVisitor(base.TokenStream).Visit(parentNode,
                                                                            isModel, am, im, isAsync);
            }
        }
コード例 #33
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="program">Program</param>
        /// <param name="parentNode">Node</param>
        /// <param name="isMonitor">Is a monitor</param>
        /// <param name="isPartial">Is partial</param>
        /// <param name="accMod">Access modifier</param>
        /// <param name="inhMod">Inheritance modifier</param>
        internal void Visit(IPSharpProgram program, NamespaceDeclaration parentNode, bool isMonitor,
            bool isPartial, AccessModifier accMod, InheritanceModifier inhMod)
        {
            var node = new MachineDeclaration(base.TokenStream.Program,
                parentNode, isMonitor, isPartial);
            node.AccessModifier = accMod;
            node.InheritanceModifier = inhMod;
            node.MachineKeyword = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected machine identifier.",
                    new List<TokenType>
                {
                    TokenType.Identifier
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                TokenType.MachineIdentifier));

            node.Identifier = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Program is PSharpProgram)
            {
                if (base.TokenStream.Done ||
                    (base.TokenStream.Peek().Type != TokenType.Colon &&
                    base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket))
                {
                    throw new ParsingException("Expected \":\" or \"{\".",
                        new List<TokenType>
                    {
                            TokenType.Colon,
                            TokenType.LeftCurlyBracket
                    });
                }

                if (base.TokenStream.Peek().Type == TokenType.Colon)
                {
                    node.ColonToken = base.TokenStream.Peek();

                    base.TokenStream.Index++;
                    base.TokenStream.SkipWhiteSpaceAndCommentTokens();

                    if (base.TokenStream.Done ||
                        base.TokenStream.Peek().Type != TokenType.Identifier)
                    {
                        throw new ParsingException("Expected base machine identifier.",
                            new List<TokenType>
                        {
                                TokenType.Identifier
                        });
                    }

                    while (!base.TokenStream.Done &&
                        base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
                    {
                        if (base.TokenStream.Peek().Type != TokenType.Identifier &&
                            base.TokenStream.Peek().Type != TokenType.Dot &&
                            base.TokenStream.Peek().Type != TokenType.NewLine)
                        {
                            throw new ParsingException("Expected base machine identifier.",
                                new List<TokenType>
                            {
                                    TokenType.Identifier,
                                    TokenType.Dot
                            });
                        }
                        else
                        {
                            node.BaseNameTokens.Add(base.TokenStream.Peek());
                        }

                        base.TokenStream.Index++;
                        base.TokenStream.SkipWhiteSpaceAndCommentTokens();
                    }
                }
            }

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".",
                    new List<TokenType>
                {
                    TokenType.LeftCurlyBracket
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                TokenType.MachineLeftCurlyBracket));

            node.LeftCurlyBracketToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            this.VisitNextPSharpIntraMachineDeclaration(node);
            parentNode.MachineDeclarations.Add(node);

            var stateDeclarations = node.GetAllStateDeclarations();
            if (stateDeclarations.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare at least one state.",
                    new List<TokenType>());
            }

            var startStates = stateDeclarations.FindAll(s => s.IsStart);
            if (startStates.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare a start state.",
                    new List<TokenType>());
            }
            else if (startStates.Count > 1)
            {
                throw new ParsingException("A machine can declare only a single start state.",
                    new List<TokenType>());
            }
        }
コード例 #34
0
 public RDomInvalidMember(string name, AccessModifier accessModifier = AccessModifier.Private)
     : this(null, null, null)
 {
     _name           = name;
     _accessModifier = accessModifier;
 }
コード例 #35
0
 public RDomDestructor(string name, AccessModifier accessModifier = AccessModifier.Private)
     : this(null, null, null)
 {
     _name           = name;
     _accessModifier = accessModifier;
 }
コード例 #36
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="program">Program</param>
        /// <param name="parentNode">Node</param>
        /// <param name="accMod">Access modifier</param>
        internal void Visit(IPSharpProgram program, NamespaceDeclaration parentNode, AccessModifier accMod)
        {
            var node = new EventDeclaration(base.TokenStream.Program);

            node.AccessModifier = accMod;
            node.EventKeyword   = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.Identifier &&
                 base.TokenStream.Peek().Type != TokenType.HaltEvent &&
                 base.TokenStream.Peek().Type != TokenType.DefaultEvent))
            {
                throw new ParsingException("Expected event identifier.",
                                           new List <TokenType>
                {
                    TokenType.Identifier,
                    TokenType.HaltEvent,
                    TokenType.DefaultEvent
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.Identifier)
            {
                base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                                                TokenType.EventIdentifier));
            }

            node.Identifier = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.Assert &&
                 base.TokenStream.Peek().Type != TokenType.Assume &&
                 base.TokenStream.Peek().Type != TokenType.Colon &&
                 base.TokenStream.Peek().Type != TokenType.Semicolon))
            {
                throw new ParsingException("Expected \":\" or \";\".",
                                           new List <TokenType>
                {
                    TokenType.Assert,
                    TokenType.Assume,
                    TokenType.Colon,
                    TokenType.Semicolon
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.Assert ||
                base.TokenStream.Peek().Type == TokenType.Assume)
            {
                bool isAssert = true;
                if (base.TokenStream.Peek().Type == TokenType.Assert)
                {
                    node.AssertKeyword = base.TokenStream.Peek();
                }
                else
                {
                    node.AssumeKeyword = base.TokenStream.Peek();
                    isAssert           = false;
                }

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();

                if (base.TokenStream.Done ||
                    base.TokenStream.Peek().Type != TokenType.Identifier)
                {
                    throw new ParsingException("Expected integer.",
                                               new List <TokenType>
                    {
                        TokenType.Identifier
                    });
                }

                int value;
                if (!int.TryParse(base.TokenStream.Peek().TextUnit.Text, out value))
                {
                    throw new ParsingException("Expected integer.",
                                               new List <TokenType>
                    {
                        TokenType.Identifier
                    });
                }

                if (isAssert)
                {
                    node.AssertValue = value;
                }
                else
                {
                    node.AssumeValue = value;
                }

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();

                if (base.TokenStream.Done ||
                    (base.TokenStream.Peek().Type != TokenType.Colon &&
                     base.TokenStream.Peek().Type != TokenType.Semicolon))
                {
                    throw new ParsingException("Expected \":\" or \";\".",
                                               new List <TokenType>
                    {
                        TokenType.Colon,
                        TokenType.Semicolon
                    });
                }
            }

            if (base.TokenStream.Peek().Type == TokenType.Colon)
            {
                node.ColonToken = base.TokenStream.Peek();

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();

                PBaseType payloadType = null;
                new TypeIdentifierVisitor(base.TokenStream).Visit(ref payloadType);
                node.PayloadType = payloadType;
            }

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Semicolon)
            {
                throw new ParsingException("Expected \";\".",
                                           new List <TokenType>
                {
                    TokenType.Semicolon
                });
            }

            node.SemicolonToken = base.TokenStream.Peek();

            if (base.TokenStream.Program is PSharpProgram)
            {
                parentNode.EventDeclarations.Add(node);
            }
            else
            {
                (program as PProgram).EventDeclarations.Add(node);
            }
        }
コード例 #37
0
ファイル: CSharpLanguage.cs プロジェクト: koenmd/nERD
 public override bool IsValidModifier(AccessModifier modifier) => true;
コード例 #38
0
        public void SetResultAccessModTsWithDependentAccessModProps(
            AccessModifier newAccessModTs,
            bool instancePropsProcessing,
            List <int> newAccessModsDependentPropsClassIndexes = null
            )
        {
            // If there is change to higher value, it's necessary also change all props with lower value:
            ExtClass protectedAccessModDependentPropClass;
            Dictionary <string, Member> protectedAccessModDependentProps;
            Property   protectedAccessModDependentProp;
            List <int> protectedAccessDependentProps;
            List <int> previousAccessModsDependentPropsClassIndexes;
            Store      store;

            if (newAccessModsDependentPropsClassIndexes != null)
            {
                if (!this.dependentProps.ContainsKey(newAccessModTs))
                {
                    this.dependentProps.Add(newAccessModTs, newAccessModsDependentPropsClassIndexes);
                }
                else
                {
                    previousAccessModsDependentPropsClassIndexes = this.dependentProps[newAccessModTs];
                    foreach (int newAccessModsDependentPropsClassIndex in newAccessModsDependentPropsClassIndexes)
                    {
                        if (
                            newAccessModsDependentPropsClassIndex != -1 &&
                            !previousAccessModsDependentPropsClassIndexes.Contains(
                                newAccessModsDependentPropsClassIndex
                                )
                            )
                        {
                            previousAccessModsDependentPropsClassIndexes.Add(
                                newAccessModsDependentPropsClassIndex
                                );
                        }
                    }
                }
            }
            if (newAccessModTs == AccessModifier.PUBLIC && this.AccessModTs == AccessModifier.PROTECTED)
            {
                this.AccessModTs = newAccessModTs;
                if (this.dependentProps.ContainsKey(AccessModifier.PROTECTED))
                {
                    protectedAccessDependentProps = this.dependentProps[AccessModifier.PROTECTED];
                    store = Processor.GetInstance().Store;
                    foreach (int protectedAccessModDependentPropClassIndex in protectedAccessDependentProps)
                    {
                        if (protectedAccessModDependentPropClassIndex == -1)
                        {
                            continue;
                        }
                        protectedAccessModDependentPropClass = store.ExtAllClasses[protectedAccessModDependentPropClassIndex];
                        protectedAccessModDependentProps     = instancePropsProcessing
                                                        ? protectedAccessModDependentPropClass.Members.Properties
                                                        : protectedAccessModDependentPropClass.Members.PropertiesStatic;
                        protectedAccessModDependentProp = protectedAccessModDependentProps[this.Name] as Property;
                        protectedAccessModDependentProp.SetResultAccessModTsWithDependentAccessModProps(
                            AccessModifier.PUBLIC, instancePropsProcessing
                            );
                    }
                }
            }
            else
            {
                this.AccessModTs = newAccessModTs;
            }
        }
コード例 #39
0
        public override Tag ParseTag(string tagEntry)
        {
            string         file;
            UInt64         line;
            string         name;
            string         tagField;
            TagKind        kind;
            AccessModifier access     = AccessModifier.Public;
            string         _class     = null;
            string         _namespace = null;
            string         _struct    = null;
            string         _union     = null;
            string         _enum      = null;
            string         signature  = null;

            int i1 = tagEntry.IndexOf('\t');

            name = tagEntry.Substring(0, tagEntry.IndexOf('\t'));

            i1 += 1;
            int i2 = tagEntry.IndexOf('\t', i1);

            file = tagEntry.Substring(i1, i2 - i1);

            i1   = i2 + 1;
            i2   = tagEntry.IndexOf(";\"", i1);
            line = UInt64.Parse(tagEntry.Substring(i1, i2 - i1));

            i1   = i2 + 3;
            kind = (TagKind)tagEntry[i1];

            i1      += 2;
            tagField = (tagEntry.Length > i1? tagField = tagEntry.Substring(i1) : String.Empty);

            string[] fields = tagField.Split('\t');
            int      index;

            foreach (string field in fields)
            {
                index = field.IndexOf(':');

                // TODO: Support friend modifier
                if (index > 0)
                {
                    string key = field.Substring(0, index);
                    string val = field.Substring(index + 1);

                    switch (key)
                    {
                    case "access":
                        try
                        {
                            access = (AccessModifier)System.Enum.Parse(typeof(AccessModifier), val, true);
                        }
                        catch (ArgumentException)
                        {
                        }
                        break;

                    case "class":
                        _class = val;
                        break;

                    case "namespace":
                        _namespace = val;
                        break;

                    case "struct":
                        _struct = val;
                        break;

                    case "union":
                        _union = val;
                        break;

                    case "enum":
                        _enum = val;
                        break;

                    case "signature":
                        signature = val;
                        break;
                    }
                }
            }

            return(new Tag(name, file, line, kind, access, _class, _namespace, _struct, _union, _enum, signature));
        }
コード例 #40
0
        public BaseStructure GetStructures(CodeBlock block, out ParseError error)
        {
            StructureRule rule = Rules.Find(p => p.Target == block.ParentDirective.Target);

            if (!rule.AllowedInnerInstructions && block.RawLines.Count != 0)
            {
                error = new ParseError(ParseErrorType.Directives_InnerInstructionsAreNotAllowed,
                                       block.ParentDirective.LineIndex, block.ParentDirective.FileName);
                return(null);
            }

            AccessModifier       accessModifier = AccessModifier.Default;
            List <Modifier>      modifiers      = new List <Modifier>();
            List <BaseStructure> childs         = null;

            if (block.ParentDirective.Parameters != null)
            {
                foreach (var modifier in block.ParentDirective.Parameters)
                {
                    var modifierParts = modifier.Split(':');

                    var modifierName  = modifierParts[0];
                    var modifierValue = string.Join(":", modifierParts.Skip(1));

                    Modifier Modifier = rule.Modifiers.Find(p => p.Name == modifierName);

                    if (Modifier == null && !AccessModifiers.Contains(modifier))
                    {
                        error = new ParseError(ParseErrorType.Directives_UnknownModifier,
                                               block.ParentDirective.LineIndex, block.ParentDirective.FileName);
                        return(null);
                    }

                    if (AccessModifiers.Contains(modifier))
                    {
                        if (rule.AvailableAccsessModifiersStrings.Contains(modifier))
                        {
                            accessModifier = rule.AvailableAccsessModifiers.Find(
                                p => p.ToString().ToLower() == modifier);
                        }
                        else
                        {
                            error = new ParseError(ParseErrorType.Directives_NotAllowedAccessModifier,
                                                   block.ParentDirective.LineIndex, block.ParentDirective.FileName);
                            return(null);
                        }

                        continue;
                    }

                    if (Modifier.ValueRequired && string.IsNullOrEmpty(modifierValue))
                    {
                        error = new ParseError(ParseErrorType.Directives_ModifierValueRequired,
                                               block.ParentDirective.LineIndex, block.ParentDirective.FileName);
                        return(null);
                    }

                    modifiers.Add(new Modifier(Modifier, modifierValue));
                }
            }

            if (!rule.Modifiers.FindAll(p => p.IsRequired).All(p => modifiers.Exists(j => j.Name == p.Name)))
            {
                error = new ParseError(ParseErrorType.Directives_SomeRequiredModifiersAreMissing,
                                       block.ParentDirective.LineIndex, block.ParentDirective.FileName);
                return(null);
            }

            childs = new List <BaseStructure>();
            foreach (var child in block.ChildBlocks)
            {
                if (!rule.AllowedChilds.Contains(child.ParentDirective.Target))
                {
                    error = new ParseError(ParseErrorType.Directives_WrongChildTarget,
                                           child.ParentDirective.LineIndex, child.ParentDirective.FileName);
                    return(null);
                }

                childs.Add(GetStructures(child, out error));
                if (error != null)
                {
                    return(null);
                }
            }

            error = null;
            return(new BaseStructure()
            {
                Name = block.ParentDirective.Name,
                AccessModifier = accessModifier,
                Modifiers = modifiers,
                Childs = childs,
                RawLines = block.RawLines,
                Target = rule.Target,
                Directive = block.ParentDirective
            }.Cast());
        }
コード例 #41
0
ファイル: CSharpLanguage.cs プロジェクト: vCipher/NClass
 public override bool IsValidModifier(AccessModifier modifier)
 {
     return(true);
 }
コード例 #42
0
 protected virtual void CopyFrom(TypeBase type)
 {
     name   = type.name;
     access = type.access;
 }
コード例 #43
0
 public RDomPropertyAccessor(IDom parent, string name, AccessorType accessorType, AccessModifier accessModifier = AccessModifier.Private)
     : this(null, AccessorType.Unknown, parent, null)
 {
     _name           = name;
     _accessModifier = accessModifier;
 }
コード例 #44
0
 protected AccessModifierNotAllowedForMemberException(AccessModifier modifier, MemberInfo member, string description)
     : base($"The access modifier(s) [ {modifier.ToString()} ] are not allowed on \"{member.DeclaringType.ReadableName()}.{member.Name}\". {description}")
 {
 }
コード例 #45
0
 internal FieldBuilder(AccessModifier accessModifier, Type type, string name)
     : this(accessModifier, type.Name, name)
 {
 }
コード例 #46
0
 public AccessModifierNotAllowedForCachedValueException(AccessModifier modifier, MemberInfo member)
     : base(modifier, member, $"A field with an attached {nameof(CachedAttribute)} must be private, readonly,"
            + " or be an auto-property with a getter and private (or non-existing) setter.")
 {
 }
コード例 #47
0
        /// <summary>
        /// Visits a group level declaration.
        /// </summary>
        /// <param name="parentNode">Node</param>
        private void VisitGroupLevelDeclaration(StateGroupDeclaration parentNode)
        {
            AccessModifier      am = AccessModifier.None;
            InheritanceModifier im = InheritanceModifier.None;
            bool isStart           = false;
            bool isHot             = false;
            bool isCold            = false;
            bool isAsync           = false;
            bool isPartial         = false;

            while (!base.TokenStream.Done &&
                   base.TokenStream.Peek().Type != TokenType.StateDecl &&
                   base.TokenStream.Peek().Type != TokenType.StateGroupDecl &&
                   base.TokenStream.Peek().Type != TokenType.MachineDecl)
            {
                if (am != AccessModifier.None &&
                    (base.TokenStream.Peek().Type == TokenType.Public ||
                     base.TokenStream.Peek().Type == TokenType.Private ||
                     base.TokenStream.Peek().Type == TokenType.Protected ||
                     base.TokenStream.Peek().Type == TokenType.Internal))
                {
                    throw new ParsingException("More than one protection modifier.",
                                               new List <TokenType>());
                }
                else if (im != InheritanceModifier.None &&
                         base.TokenStream.Peek().Type == TokenType.Abstract)
                {
                    throw new ParsingException("Duplicate abstract modifier.",
                                               new List <TokenType>());
                }
                else if (isStart &&
                         base.TokenStream.Peek().Type == TokenType.StartState)
                {
                    throw new ParsingException("Duplicate start state modifier.",
                                               new List <TokenType>());
                }
                else if (isHot &&
                         base.TokenStream.Peek().Type == TokenType.HotState)
                {
                    throw new ParsingException("Duplicate hot state modifier.",
                                               new List <TokenType>());
                }
                else if (isCold &&
                         base.TokenStream.Peek().Type == TokenType.ColdState)
                {
                    throw new ParsingException("Duplicate cold state modifier.",
                                               new List <TokenType>());
                }
                else if ((isCold &&
                          base.TokenStream.Peek().Type == TokenType.HotState) ||
                         (isHot &&
                          base.TokenStream.Peek().Type == TokenType.ColdState))
                {
                    throw new ParsingException("State cannot be both hot and cold.",
                                               new List <TokenType>());
                }
                else if (isAsync &&
                         base.TokenStream.Peek().Type == TokenType.Async)
                {
                    throw new ParsingException("Duplicate async method modifier.",
                                               new List <TokenType>());
                }
                else if (isPartial &&
                         base.TokenStream.Peek().Type == TokenType.Partial)
                {
                    throw new ParsingException("Duplicate partial method modifier.",
                                               new List <TokenType>());
                }

                if (base.TokenStream.Peek().Type == TokenType.Public)
                {
                    am = AccessModifier.Public;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Private)
                {
                    am = AccessModifier.Private;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Protected)
                {
                    am = AccessModifier.Protected;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Internal)
                {
                    am = AccessModifier.Internal;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Abstract)
                {
                    im = InheritanceModifier.Abstract;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Virtual)
                {
                    im = InheritanceModifier.Virtual;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Override)
                {
                    im = InheritanceModifier.Override;
                }
                else if (base.TokenStream.Peek().Type == TokenType.StartState)
                {
                    isStart = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.HotState)
                {
                    isHot = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.ColdState)
                {
                    isCold = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Async)
                {
                    isAsync = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Partial)
                {
                    isPartial = true;
                }

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.StateDecl &&
                 base.TokenStream.Peek().Type != TokenType.StateGroupDecl))
            {
                throw new ParsingException("Expected state or group declaration.",
                                           new List <TokenType>
                {
                    TokenType.StateDecl,
                    TokenType.StateGroupDecl
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.StateDecl)
            {
                if (am == AccessModifier.Public)
                {
                    throw new ParsingException("A state cannot be public.",
                                               new List <TokenType>());
                }
                else if (am == AccessModifier.Internal)
                {
                    throw new ParsingException("A state cannot be internal.",
                                               new List <TokenType>());
                }

                if (im == InheritanceModifier.Abstract)
                {
                    throw new ParsingException("A state cannot be abstract.",
                                               new List <TokenType>());
                }
                else if (im == InheritanceModifier.Virtual)
                {
                    throw new ParsingException("A state cannot be virtual.",
                                               new List <TokenType>());
                }
                else if (im == InheritanceModifier.Override)
                {
                    throw new ParsingException("A state cannot be overriden.",
                                               new List <TokenType>());
                }

                if (isAsync)
                {
                    throw new ParsingException("A state cannot be async.",
                                               new List <TokenType>());
                }

                if (isPartial)
                {
                    throw new ParsingException("A state cannot be partial.",
                                               new List <TokenType>());
                }

                new StateDeclarationVisitor(base.TokenStream).Visit(parentNode.Machine,
                                                                    parentNode, isStart, isHot, isCold, am);
            }
            else if (base.TokenStream.Peek().Type == TokenType.StateGroupDecl)
            {
                if (am == AccessModifier.Public)
                {
                    throw new ParsingException("A state group cannot be public.",
                                               new List <TokenType>());
                }
                else if (am == AccessModifier.Internal)
                {
                    throw new ParsingException("A state group cannot be internal.",
                                               new List <TokenType>());
                }

                if (im == InheritanceModifier.Abstract)
                {
                    throw new ParsingException("A state group cannot be abstract.",
                                               new List <TokenType>());
                }
                else if (im == InheritanceModifier.Virtual)
                {
                    throw new ParsingException("A state group cannot be virtual.",
                                               new List <TokenType>());
                }
                else if (im == InheritanceModifier.Override)
                {
                    throw new ParsingException("A state group cannot be overriden.",
                                               new List <TokenType>());
                }

                if (isAsync)
                {
                    throw new ParsingException("A state group cannot be async.",
                                               new List <TokenType>());
                }

                if (isPartial)
                {
                    throw new ParsingException("A state group cannot be partial.",
                                               new List <TokenType>());
                }

                if (isStart)
                {
                    throw new ParsingException("A state group cannot be marked start.",
                                               new List <TokenType>());
                }
                else if (isHot)
                {
                    throw new ParsingException("A state group cannot be hot.",
                                               new List <TokenType>());
                }
                else if (isCold)
                {
                    throw new ParsingException("A state group cannot be cold.",
                                               new List <TokenType>());
                }

                new StateGroupDeclarationVisitor(base.TokenStream).Visit(parentNode.Machine, parentNode, am);
            }
        }
コード例 #48
0
 /// <summary>
 /// Adds a function the the class
 /// </summary>
 /// <param name="AccessModifier">Access modifier</param>
 /// <param name="Modifier">Modifier</param>
 /// <param name="Type">Type returned by the function</param>
 /// <param name="Name">Name of the function</param>
 /// <param name="Body">Body of the function</param>
 /// <param name="ParameterList">Parameter list</param>
 public virtual void AddFunction(AccessModifier AccessModifier, Modifiers Modifier, string Type,
     string Name, string Body, IParameter[] ParameterList)
 {
     Functions.Add(new Function(AccessModifier, Modifier, Type, Name, ParameterList, Body, Parser));
 }
コード例 #49
0
 public Identifier(AccessModifier access, params string[] ids)
 {
     this.Access = access;
     this.Id     = String.Join("/", ids);
 }
コード例 #50
0
 /// <summary>
 /// Adds a property to the class
 /// </summary>
 /// <param name="AccessModifier">Access modifier</param>
 /// <param name="Modifier">Modifier</param>
 /// <param name="PropertyType">Property type</param>
 /// <param name="Name">Property name</param>
 public virtual void AddProperty(AccessModifier AccessModifier, Modifiers Modifier,
     string PropertyType, string Name)
 {
     DefaultProperty Property = new DefaultProperty(Parser);
     Property.AccessModifier = AccessModifier;
     Property.Modifier = Modifier;
     Property.PropertyType = PropertyType;
     Property.Name = Name;
     Properties.Add(Property);
 }
コード例 #51
0
 public AccessModifierNotAllowedForLoaderMethodException(AccessModifier modifier, MemberInfo member)
     : base(modifier, member, $"A method with an attached {nameof(BackgroundDependencyLoaderAttribute)} must be private.")
 {
 }
コード例 #52
0
 public static Constructor WithAccess(this Constructor @this, AccessModifier value) => new Constructor(
     documentation: @this.Documentation,
     access: value,
     parameters: @this.Parameters,
     baseInitializers: @this.BaseInitializers,
     body: @this.Body);
コード例 #53
0
 /// <summary>
 /// Adds a property to the class
 /// </summary>
 /// <param name="AccessModifier">Access modifier</param>
 /// <param name="Modifier">Modifier</param>
 /// <param name="PropertyType">Property type</param>
 /// <param name="Name">Property name</param>
 /// <param name="GetFunction">Get function</param>
 /// <param name="SetFunction">Set function</param>
 public virtual void AddProperty(AccessModifier AccessModifier, Modifiers Modifier, string PropertyType,
     string Name, string GetFunction, string SetFunction)
 {
     Property Property = new Property(Parser);
     Property.AccessModifier = AccessModifier;
     Property.Modifier = Modifier;
     Property.PropertyType = PropertyType;
     Property.Name = Name;
     Property.GetFunction = GetFunction;
     Property.SetFunction = SetFunction;
     Properties.Add(Property);
 }
コード例 #54
0
 public AccessModifierNotAllowedForPropertySetterException(AccessModifier modifier, MemberInfo member)
     : base(modifier, member, $"A property with an attached {nameof(ResolvedAttribute)} must have a private setter.")
 {
 }
コード例 #55
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="program">Program</param>
        /// <param name="parentNode">Node</param>
        /// <param name="isMain">Is main machine</param>
        /// <param name="isModel">Is a model</param>
        /// <param name="isMonitor">Is a monitor</param>
        /// <param name="accMod">Access modifier</param>
        /// <param name="inhMod">Inheritance modifier</param>
        internal void Visit(IPSharpProgram program, NamespaceDeclaration parentNode, bool isMain,
                            bool isModel, bool isMonitor, AccessModifier accMod, InheritanceModifier inhMod)
        {
            var node = new MachineDeclaration(base.TokenStream.Program, isMain, isModel, isMonitor);

            node.AccessModifier      = accMod;
            node.InheritanceModifier = inhMod;
            node.MachineKeyword      = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected machine identifier.",
                                           new List <TokenType>
                {
                    TokenType.Identifier
                });
            }

            base.TokenStream.CurrentMachine = base.TokenStream.Peek().Text;
            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                                            TokenType.MachineIdentifier));

            node.Identifier = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Program is PSharpProgram)
            {
                if (base.TokenStream.Done ||
                    (base.TokenStream.Peek().Type != TokenType.Colon &&
                     base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket))
                {
                    throw new ParsingException("Expected \":\" or \"{\".",
                                               new List <TokenType>
                    {
                        TokenType.Colon,
                        TokenType.LeftCurlyBracket
                    });
                }

                if (base.TokenStream.Peek().Type == TokenType.Colon)
                {
                    node.ColonToken = base.TokenStream.Peek();

                    base.TokenStream.Index++;
                    base.TokenStream.SkipWhiteSpaceAndCommentTokens();

                    if (base.TokenStream.Done ||
                        base.TokenStream.Peek().Type != TokenType.Identifier)
                    {
                        throw new ParsingException("Expected base machine identifier.",
                                                   new List <TokenType>
                        {
                            TokenType.Identifier
                        });
                    }

                    while (!base.TokenStream.Done &&
                           base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
                    {
                        if (base.TokenStream.Peek().Type != TokenType.Identifier &&
                            base.TokenStream.Peek().Type != TokenType.Dot &&
                            base.TokenStream.Peek().Type != TokenType.NewLine)
                        {
                            throw new ParsingException("Expected base machine identifier.",
                                                       new List <TokenType>
                            {
                                TokenType.Identifier,
                                TokenType.Dot
                            });
                        }
                        else
                        {
                            node.BaseNameTokens.Add(base.TokenStream.Peek());
                        }

                        base.TokenStream.Index++;
                        base.TokenStream.SkipWhiteSpaceAndCommentTokens();
                    }
                }
            }

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".",
                                           new List <TokenType>
                {
                    TokenType.LeftCurlyBracket
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                                            TokenType.MachineLeftCurlyBracket));

            node.LeftCurlyBracketToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Program is PSharpProgram)
            {
                this.VisitNextPSharpIntraMachineDeclaration(node);
                parentNode.MachineDeclarations.Add(node);
            }
            else
            {
                this.VisitNextPIntraMachineDeclaration(node);
                (program as PProgram).MachineDeclarations.Add(node);
            }

            if (node.StateDeclarations.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare at least one state.",
                                           new List <TokenType>());
            }

            var initialStates = node.StateDeclarations.FindAll(s => s.IsInitial);

            if (initialStates.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare a start state.",
                                           new List <TokenType>());
            }
            else if (initialStates.Count > 1)
            {
                throw new ParsingException("A machine can declare only a single start state.",
                                           new List <TokenType>());
            }
        }
コード例 #56
0
ファイル: TypeBase.cs プロジェクト: koenmd/nERD
 protected virtual void CopyFrom(TypeBase type)
 {
     _name   = type._name;
     _access = type._access;
 }
コード例 #57
0
ファイル: Member.cs プロジェクト: BachelorEric/ModelFirst
		protected virtual void CopyFrom(Member member)
		{
			name = member.name;
			type = member.type;
			access = member.access;
            comments = member.comments;
		}
コード例 #58
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="parentNode">Node</param>
        /// <param name="accMod">Access modifier</param>
        /// <param name="inhMod">Inheritance modifier</param>
        /// <param name="isAsync">Is async</param>
        /// <param name="isPartial">Is partial</param>
        internal void Visit(MachineDeclaration parentNode, AccessModifier accMod,
                            InheritanceModifier inhMod, bool isAsync, bool isPartial)
        {
            TextUnit textUnit = null;

            new TypeIdentifierVisitor(base.TokenStream).Visit(ref textUnit);
            var typeIdentifier = new Token(textUnit, TokenType.TypeIdentifier);

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected field or method identifier.",
                                           new List <TokenType>
                {
                    TokenType.Identifier
                });
            }

            var identifierToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.LeftParenthesis &&
                 base.TokenStream.Peek().Type != TokenType.Semicolon))
            {
                throw new ParsingException("Expected \"(\" or \";\".",
                                           new List <TokenType>
                {
                    TokenType.LeftParenthesis,
                    TokenType.Semicolon
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.LeftParenthesis)
            {
                new MethodDeclarationVisitor(base.TokenStream).Visit(parentNode, typeIdentifier,
                                                                     identifierToken, accMod, inhMod, isAsync, isPartial);
            }
            else if (base.TokenStream.Peek().Type == TokenType.Semicolon)
            {
                if (inhMod == InheritanceModifier.Abstract)
                {
                    throw new ParsingException("A field cannot be abstract.",
                                               new List <TokenType>());
                }
                else if (inhMod == InheritanceModifier.Virtual)
                {
                    throw new ParsingException("A field cannot be virtual.",
                                               new List <TokenType>());
                }
                else if (inhMod == InheritanceModifier.Override)
                {
                    throw new ParsingException("A field cannot be overriden.",
                                               new List <TokenType>());
                }

                if (isAsync)
                {
                    throw new ParsingException("A field cannot be async.",
                                               new List <TokenType>());
                }

                if (isPartial)
                {
                    throw new ParsingException("A field cannot be partial.",
                                               new List <TokenType>());
                }

                var node = new FieldDeclaration(base.TokenStream.Program, parentNode);
                node.AccessModifier = accMod;
                node.TypeIdentifier = typeIdentifier;
                node.Identifier     = identifierToken;
                node.SemicolonToken = base.TokenStream.Peek();

                parentNode.FieldDeclarations.Add(node);
            }
        }
コード例 #59
0
	public FunctionDeclarationHeader(QualifiedName Name, AccessModifier Visibility)
		: base(CodeElementType.FunctionDeclarationHeader) {
		this.Name = Name;
		this.Visibility = Visibility;
		this.Profile = new ParametersProfile();
	}
コード例 #60
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="program">Program</param>
 /// <param name="machineNode">MachineDeclarationNode</param>
 /// <param name="modSet">Modifier set</param>
 internal FieldDeclaration(IPSharpProgram program, MachineDeclaration machineNode, ModifierSet modSet)
     : base(program)
 {
     this.Machine        = machineNode;
     this.AccessModifier = modSet.AccessModifier;
 }