public virtual QuoteFile CreateRandomFile(Identifiers allowedIdentifiers, int lineCount)
 {
     var quoteFile = new QuoteFile();
     var randomQuotes = this.QuoteFactory.CreateListOfRandomQuotes(allowedIdentifiers, lineCount);
     quoteFile.AddRange(randomQuotes);
     return quoteFile;
 }
 public virtual List<Quote> CreateListOfRandomQuotes(Identifiers allowedIdentifiers, int count)
 {
     var list = new List<Quote>();
     for (var i = 0; i < count; i++)
     {
         var quote = this.CreateRandomQuote(allowedIdentifiers);
         list.Add(quote);
     }
     return list;
 }
        public void CreateRandomQuote_respects_my_authority()
        {
            // arrange
            var factory = new QuoteFactory();
            var allowedIdentifiers = new Identifiers(new List<string> { "SBUX" });
            // act
            var quote = factory.CreateRandomQuote(allowedIdentifiers);

            // assert
            Assert.That(quote.Identifier, Is.EqualTo("SBUX"));
        }
        public void SetUpSampleData(string containerName, int numFiles, int fileLineCount, Identifiers allowedIdentifiers)
        {
            var provider = new BlobProvider();
            var factory = new QuoteFileFactory();

            for (var n = 0; n < numFiles; n++)
            {
                var fileName = "stock" + n.ToString() + ".txt";

                var file = factory.CreateRandomFile(allowedIdentifiers, fileLineCount);
                provider.CreateBlob(containerName, fileName, file.ToString());
            }
        }
        public void CreateRandomFile_creates_expected_number_of_lines()
        {
            // arrange
            var factory = new QuoteFileFactory();
            var allowedIdentifiers = new List<string> {"MSFT", "CSCO", "AMZN", "SBUX"};
            var identifiers = new Identifiers(allowedIdentifiers);
            var expectedLines = 100;

            // act
            var file = factory.CreateRandomFile(identifiers, expectedLines);

            // assert
            var fileContents = file.ToString();
            AssertHelper.AssertHasLines(fileContents, expectedLines);
        }
        public virtual Quote CreateRandomQuote(Identifiers allowedIdentifiers)
        {
            var count = allowedIdentifiers.Count;
            var rand = this.Rand.Next(0, count);
            var chosenIdentifier = allowedIdentifiers[rand];

            var ticker = this.TickerFactory.CreateRandomTicker();
            var quoteDate = this.DateUtils.GetRandomDate();
            var quote = new Quote
            {
                Identifier = chosenIdentifier,
                Price = ticker.Price,
                QuoteDate = quoteDate,
            };
            return quote;
        }
        public void OneTimeSetup_Method()
        {
            var identifiers = new Identifiers(
                                  new List<string>
                                  {
                                      "MSFT",
                                      "AMZN",
                                      "SBUX",
                                      "CSCO",
                                      "F",
                                      "X",
                                      "T",
                                      "BA",
                                      "ANTHONY",
                                      "CLOUD302"
                                  });

            var writer = new StockDataWriter();
            writer.SetUpSampleData("stockdata2", 2, 100000, identifiers);
        }
 static TimePickerIsDropDownOpenDesignModeValueProvider()
 {
     _propertyIdentifier = new PropertyIdentifier(typeof(SSWC.TimePicker), "IsDropDownOpen");
     Identifiers.Add(typeof(SSWC.TimePicker), _propertyIdentifier);
 }
Beispiel #9
0
 private Purchase(PurchaseData purchaseData, string jsonPurchaseData, string signature)
 {
     _purchaseData    = purchaseData;
     _identifiers     = new Identifiers(_purchaseData.obfuscatedAccountId, _purchaseData.obfuscatedProfileId);
     _purchaseReceipt = new PurchaseReceipt(jsonPurchaseData, signature);
 }
        protected override void Body(dynamic node = null)
        {
            int id = Identifiers.GetInstructionID();

            if (node.ResultType != null || node.ResultType2 != null)
            {
                Lines.AppendLine("using Mosa.Compiler.MosaTypeSystem;");
                Lines.AppendLine();
            }

            Lines.AppendLine("namespace Mosa.Compiler.Framework.IR");
            Lines.AppendLine("{");
            Lines.AppendLine("\t/// <summary>");
            Lines.AppendLine("\t/// " + node.Name);

            if (!string.IsNullOrWhiteSpace(node.Description))
            {
                Lines.AppendLine("\t\t/// " + node.Description);
            }

            Lines.AppendLine("\t/// </summary>");
            Lines.AppendLine("\t/// <seealso cref=\"Mosa.Compiler.Framework.IR.BaseIRInstruction\" />");
            Lines.AppendLine("\tpublic sealed class " + node.Name + " : BaseIRInstruction");
            Lines.AppendLine("\t{");
            Lines.AppendLine("\t\tpublic override int ID { get { return " + id.ToString() + "; } }");
            Lines.AppendLine();
            Lines.AppendLine("\t\tpublic " + node.Name + "()");
            Lines.AppendLine("\t\t\t: base(" + node.OperandCount + ", " + node.ResultCount + ")");
            Lines.AppendLine("\t\t{");
            Lines.AppendLine("\t\t}");

            if (node.FlowControl != null && node.FlowControl != "Next")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override FlowControl FlowControl { get { return FlowControl." + node.FlowControl + "; } }");
            }

            if (node.ResultType != null && node.ResultType != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType { get { return BuiltInType." + node.ResultType + "; } }");
            }

            if (node.ResultType2 != null && node.ResultType2 != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType2 { get { return BuiltInType." + node.ResultType2 + "; } }");
            }

            if (node.IgnoreDuringCodeGeneration != null && node.IgnoreDuringCodeGeneration == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreDuringCodeGeneration { get { return true; } }");
            }

            if (node.IgnoreInstructionBasicBlockTargets != null && node.IgnoreInstructionBasicBlockTargets == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreInstructionBasicBlockTargets { get { return true; } }");
            }

            if (node.VariableOperands != null && node.VariableOperands == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool VariableOperands { get { return true; } }");
            }

            if (node.Commutative != null && node.Commutative == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCommutative { get { return true; } }");
            }

            if (node.MemoryWrite != null && node.MemoryWrite == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryWrite { get { return true; } }");
            }

            if (node.MemoryRead != null && node.MemoryRead == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryRead { get { return true; } }");
            }

            if (node.IOOperation != null && node.IOOperation == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsIOOperation { get { return true; } }");
            }

            if (node.IRUnspecifiedSideEffect != null && node.IRUnspecifiedSideEffect == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool HasIRUnspecifiedSideEffect { get { return true; } }");
            }

            if (node.ParameterLoad != null && node.ParameterLoad == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParameterLoad { get { return true; } }");
            }

            if (node.ParameterStore != null && node.ParameterStore == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParameterStore { get { return true; } }");
            }

            Lines.AppendLine("\t}");
            Lines.AppendLine("}");
        }
Beispiel #11
0
 static AccordionItemIsSelectedDesignModeValueProvider()
 {
     _propertyIdentifier = new PropertyIdentifier(typeof(SSWC.AccordionItem), "IsSelected");
     Identifiers.Add(typeof(SSWC.AccordionItem), _propertyIdentifier);
 }
 public bool HasAnyIdentifiers(IEnumerable <string> identifiers) =>
 Identifiers.HasAny(identifiers);
Beispiel #13
0
 public int GetAvailableIdentifiersCount(DateTime startDate, DateTime endDate, Type userType)
 {
     return(Identifiers.Count(i => i.IsAvailable(startDate, endDate, userType) || i.IsOverridable(startDate, endDate, userType)));
 }
Beispiel #14
0
 internal IEnumerable <Reservation> GetReservationRange(DateTime startDate, DateTime endDate)
 {
     return(Identifiers.SelectMany(i => i.GetDetailRange(startDate, endDate).Select(d => d.Reservation)));
 }
Beispiel #15
0
 public TipRequest()
 {
     identifiers   = new Identifiers();
     parameterMaps = new ParameterMaps();
 }
Beispiel #16
0
 public ParameterMap()
 {
     identifiers = new Identifiers();
     valueList   = new ValueList();
 }
        public void SimpleValuesAreEqual()
        {
            var value = Random.String();

            Identifiers.NhsNumber(value).Should().Be(Identifiers.NhsNumber(value));
        }
Beispiel #18
0
 static TReservation()
 {
     Identifiers
     .Add(x => x.Id)
     ;
 }
        public override void ExitParameterDecl(GolangParser.ParameterDeclContext context)
        {
            List <ParameterInfo> parameters = new List <ParameterInfo>();

            Identifiers.TryGetValue(context.identifierList(), out string[] identifiers);

            // Check for variadic expression
            bool hasVariadicParameter = context.GetText().Contains("...");

            if (!Types.TryGetValue(context.type(), out TypeInfo typeInfo))
            {
                typeInfo = TypeInfo.ObjectType;
            }

            if (identifiers != null)
            {
                for (int i = 0; i < identifiers.Length; i++)
                {
                    string identifier = SanitizedIdentifier(identifiers[i]);

                    // Check for unnamed parameters
                    if (string.IsNullOrWhiteSpace(identifier))
                    {
                        identifier = $"_p{parameters.Count}";
                    }

                    if (i == identifiers.Length - 1 && hasVariadicParameter)
                    {
                        TypeInfo variadicType = ConvertByRefToBasicPointer(typeInfo.Clone());

                        if (variadicType.TypeClass != TypeClass.Array)
                        {
                            variadicType.TypeClass     = TypeClass.Array;
                            variadicType.TypeName     += "[]";
                            variadicType.FullTypeName += "[]";
                        }

                        parameters.Add(new ParameterInfo
                        {
                            Name       = identifier,
                            Type       = variadicType,
                            IsVariadic = true,
                        });
                    }
                    else
                    {
                        parameters.Add(new ParameterInfo
                        {
                            Name       = identifier,
                            Type       = typeInfo,
                            IsVariadic = false
                        });
                    }
                }
            }
            else if (hasVariadicParameter)
            {
                string identifier = $"_p{parameters.Count}";

                // Unnamed variadic parameter
                parameters.Add(new ParameterInfo
                {
                    Name       = identifier,
                    Type       = ConvertByRefToBasicPointer(typeInfo),
                    IsVariadic = true
                });
            }
            else
            {
                string identifier = $"_p{parameters.Count}";

                // Unnamed parameter
                parameters.Add(new ParameterInfo
                {
                    Name       = identifier,
                    Type       = typeInfo,
                    IsVariadic = false
                });
            }

            m_parameterDeclarations[context] = parameters;
        }
Beispiel #20
0
 string GetFormattedIdentifiers(int count)
 {
     return(String.Join(".", (from n in Identifiers.Take(count) select Util.ToPascalCase(n)).ToArray()));
 }
Beispiel #21
0
 string GetJavaIdentifiers(int count)
 {
     return(String.Join(".", Identifiers.Take(count)));
 }
Beispiel #22
0
 public override void ExitVarSpec(GoParser.VarSpecContext context)
 {
     if (!Identifiers.TryGetValue(context.identifierList(), out string[] identifiers))
Beispiel #23
0
 public TipMap()
 {
     parameterMaps = new ParameterMaps();
     identifiers   = new Identifiers();
 }
Beispiel #24
0
        Identifier ReadIdentifer(IdContainer Container, Identifier Parent)
        {
            var IdScope = Container.GetParent <IdentifierScope>();

            if (IdScope == null || IdScope.Identifier != Parent)
            {
                throw new ApplicationException();
            }

            var IdPos = Reader.BaseStream.Position - BeginningPos;

            if (IdPos != ReadLEB128_Long())
            {
                throw new InvalidAssemblyException();
            }

#warning CHECK
            var ParentIdRef = ReadLEB128_Int();

            var Byte           = Reader.ReadByte();
            var DeclaredIdType = (DeclaredIdType)(Byte & 15);
            var Access         = (IdentifierAccess)(Byte >> 4);

            var FlagData       = Reader.ReadUInt16();
            var Flags          = (IdentifierFlags)FlagData & IdentifierFlags.All;
            var HasName        = (FlagData & 16384) != 0;
            var HasOverloads   = (FlagData & 32768) != 0;
            var HasSpecialName = (Flags & IdentifierFlags.SpecialName) != 0;

            var Name         = HasName ? new CodeString(ReadLEB128_String()) : new CodeString();
            var AssemblyName = HasSpecialName ? ReadLEB128_String() : null;

            var StructuredScope = Container as StructuredScope;
            var IsGlobal        = (Flags & IdentifierFlags.Static) != 0 || !(Container.RealContainer is StructuredScope);

            var Ret = (Identifier)null;
            if (DeclaredIdType == DeclaredIdType.Alias)
            {
                Ret = new IdentifierAlias(Container, Name, null);
                ReadReference(Ret, ReferenceDestination.RealId, -1);
                UpdateList.Add(Ret);
            }
            else if (DeclaredIdType == DeclaredIdType.Class || DeclaredIdType == DeclaredIdType.Struct)
            {
                StructuredType Structured;
                if (DeclaredIdType == DeclaredIdType.Class)
                {
                    Ret = Structured = new ClassType(Container, Name);
                }
                else
                {
                    Ret = Structured = new StructType(Container, Name);
                }

                Structured.InstanceSize = ReadLEB128_Int();
                if (Structured.InstanceSize <= 0)
                {
                    throw new InvalidAssemblyException("Invalid size");
                }

                Structured.Align            = ReadLEB128_Int();
                Structured.LayoutCalculated = true;
                if (!DataStoring.VerifyAlign(Structured.Align))
                {
                    throw new InvalidAssemblyException("Invalid alingment");
                }

                if (DeclaredIdType == DeclaredIdType.Struct)
                {
                    Structured.Size = Structured.InstanceSize;
                }

                Structured.Guid = ReadGuid();
                var BaseCount = ReadLEB128_Int();
                Structured.BaseStructures = new StructureBase[BaseCount];
                for (var i = 0; i < BaseCount; i++)
                {
                    ReadReferenceDeclared(Structured, ReferenceDestination.Base, i);
                }

                Structured.FunctionTableIndex = ReadLEB128_Int();
                var Scope = new StructuredScope(Container, new CodeString(), Structured);
                Container.Children.Add(Scope);
                Structured.StructuredScope = Scope;
                ReadIdList(Scope, Structured);
                UpdateList.Add(Ret);
            }
            else if (DeclaredIdType == DeclaredIdType.Enum || DeclaredIdType == DeclaredIdType.Flag)
            {
                EnumType Enum;
                if (DeclaredIdType == Zinnia.DeclaredIdType.Enum)
                {
                    Ret = Enum = new EnumType(Container, Name, new CodeString());
                }
                else
                {
                    Ret = Enum = new FlagType(Container, Name, new CodeString());
                }
                ReadReference(Enum, ReferenceDestination.Children, 0);

                var Scope = new EnumScope(Container, new CodeString(), Enum);
                Container.Children.Add(Scope);
                Enum.EnumScope = Scope;

                var MemberCount = ReadLEB128_Int();
                if (MemberCount != 0)
                {
                    if (MemberCount < 0)
                    {
                        throw new InvalidAssemblyException();
                    }

                    for (var i = 0; i < MemberCount; i++)
                    {
                        var ConstName = new CodeString(ReadLEB128_String());
                        if (!ConstName.IsValidIdentifierName)
                        {
                            throw new InvalidAssemblyException("Invalid identifier name");
                        }

                        if (Identifiers.IsDefined(Scope.IdentifierList, ConstName.ToString()))
                        {
                            throw new InvalidAssemblyException("Identifier already defined");
                        }

                        var Const = new ConstVariable(Container, ConstName, Enum, ReadConst());
                        Scope.IdentifierList.Add(Const);
                    }
                }

                UpdateList.Add(Enum);
            }
            else if (DeclaredIdType == DeclaredIdType.Function || DeclaredIdType == DeclaredIdType.Constructor)
            {
                Function          Function;
                FunctionOverloads Overloads;
                if (DeclaredIdType == Zinnia.DeclaredIdType.Function)
                {
                    Overloads = Container.GetOverload(Name.ToString());
                    if (IsGlobal)
                    {
                        Ret = Function = new Function(Container, Name, null, Overloads);
                    }
                    else
                    {
                        Ret = Function = new MemberFunction(Container, Name, null, Overloads);
                    }
                }
                else
                {
                    if (HasName)
                    {
                        throw new InvalidAssemblyException("Constructors cannot have name");
                    }
                    if (StructuredScope == null)
                    {
                        throw new InvalidAssemblyException("Invalid container");
                    }

                    if (StructuredScope.ConstructorOverloads == null)
                    {
                        StructuredScope.ConstructorOverloads = new FunctionOverloads(null);
                    }

                    Overloads = StructuredScope.ConstructorOverloads;
                    Ret       = Function = new Constructor(Container, null, Overloads, new CodeString());
                }

                ReadReference(Function, ReferenceDestination.Children, 0);

                var OverloadIndex = HasOverloads ? ReadLEB128_Int() : 0;
                for (var i = 0; i < Overloads.Functions.Count; i++)
                {
                    var OverloadFunc = Overloads.Functions[i];
                    if (OverloadFunc.OverloadIndex == OverloadIndex)
                    {
                        throw new InvalidAssemblyException("Function with the same overload index");
                    }

                    /*
                     * if (Function.AreParametersSame(OverloadFunc))
                     *  throw new InvalidAssemblyException("Function with the same name and parameters");*/
                }

                Function.OverloadIndex = OverloadIndex;
                Overloads.Functions.Add(Function);

                if ((Flags & IdentifierFlags.Virtual) != 0)
                {
                    var MemberFunc = Function as MemberFunction;
                    MemberFunc.VirtualIndex = ReadLEB128_Int();
                    if ((Flags & IdentifierFlags.Override) != 0)
                    {
                        ReadReferenceDeclared(MemberFunc, ReferenceDestination.OverriddenId, -1);
                    }
                }

                Function.GlobalPointerIndex = ReadLEB128_Int();
            }
            else if (DeclaredIdType == DeclaredIdType.Destructor)
            {
                if (HasName)
                {
                    throw new InvalidAssemblyException("Destructors cannot have name");
                }
                if (StructuredScope == null)
                {
                    throw new InvalidAssemblyException("Invalid container");
                }

                var Function = new Destructor(Container, null, new CodeString());
                ReadReference(Function, ReferenceDestination.Children, 0);
                Function.GlobalPointerIndex = ReadLEB128_Int();
                Ret = Function;
            }
            else if (DeclaredIdType == DeclaredIdType.Variable)
            {
                if (IsGlobal)
                {
                    Ret = new GlobalVariable(Container, Name, null);
                }
                else
                {
                    Ret = new MemberVariable(Container, Name, null);
                }

                ReadReference(Ret, ReferenceDestination.Children, 0);

                if (!IsGlobal)
                {
                    var MemVar = Ret as MemberVariable;
                    MemVar.Offset = ReadLEB128_Int();
                }
                else
                {
                    var Global = Ret as GlobalVariable;
                    Global.GlobalPointerIndex = ReadLEB128_Int();
                }
            }
            else if (DeclaredIdType == DeclaredIdType.Constant)
            {
                var Const = new ConstVariable(Container, Name, null, null);
                ReadReference(Const, ReferenceDestination.Children, 0);
                Const.ConstInitValue = ReadConst();
                Ret = Const;
            }
            else if (DeclaredIdType == DeclaredIdType.Property)
            {
                var Property = new Property(Container, Name, (Type)null);
                var PScope   = new PropertyScope(Container, new CodeString(), Property);
                Container.Children.Add(PScope);
                Property.PropertyScope = PScope;
                ReadReference(Property, ReferenceDestination.Children, 0);
                ReadParameterReferences(Property);

                var Data = Reader.ReadByte();
                if ((Data & 1) != 0)
                {
                    PScope.Getter = ReadIdentifer(PScope, Property) as Function;
                }
                if ((Data & 2) != 0)
                {
                    PScope.Setter = ReadIdentifer(PScope, Property) as Function;
                }
                Ret = Property;
            }
            else if (DeclaredIdType == DeclaredIdType.Namespace)
            {
                var Scope = Container as NamespaceScope;
                if (Scope == null)
                {
                    throw new InvalidAssemblyException("Invalid container");
                }
                if (Access != IdentifierAccess.Public)
                {
                    throw new InvalidAssemblyException("Invalid access");
                }

                var Options = new GetIdOptions()
                {
                    Func = x => x is Namespace
                };
                var Namespace = Identifiers.GetMember(State, Parent, Name, Options) as Namespace;
                if (Namespace == null)
                {
                    Ret = Namespace = new Namespace(Container, Name);
                }

                var NewScope = new NamespaceScope(Container, new CodeString(), Namespace);
                Container.Children.Add(NewScope);
                Namespace.AddScope(NewScope);

                ReadIdList(NewScope, Namespace);
            }
            else
            {
                throw new InvalidAssemblyException("Invalid identifier type");
            }

            if (Ret != null)
            {
                if (HasSpecialName)
                {
                    Ret.AssemblyName = AssemblyName;
                }

                Ret.Access       = Access;
                Ret.Flags        = Flags;
                Ret.DescPosition = IdPos;
                CurrentAssembly.Ids.Add(IdPos, Ret);
            }

            return(Ret);
        }
 public void CompositeValuesAreEqual()
 {
     Identifiers.Name("One", "Two")
     .Should().Be(Identifiers.Name("One", "Two"));
 }
Beispiel #26
0
 public IEnumerable <MaterialIdentifier> GetAvailableIdentifiers(DateTime startDate, DateTime endDate, Type userType)
 {
     return(Identifiers.Where(i => i.IsAvailable(startDate, endDate, userType)));
 }
Beispiel #27
0
 public void Reset()
 {
     Identifiers.Clear();
     IsMatch = false;
 }
Beispiel #28
0
 static TreeViewItemIsExpandedDesignModeValueProvider()
 {
     _propertyIdentifier = new PropertyIdentifier(typeof(SSWC.TreeViewItem), "IsExpanded");
     Identifiers.Add(typeof(SSWC.TreeViewItem), _propertyIdentifier);
 }
        public void SimpleValuesWithDifferentValuesAreNotEqual()
        {
            var value = Random.String();

            Identifiers.NhsNumber(value).Should().NotBe(Identifiers.NhsNumber(Random.String()));
        }
 public bool HasIdentifier(string identifier) =>
 Identifiers.Has(identifier);
Beispiel #31
0
        PluginResult ForceContinue_MemberNode(ref ExpressionNode Node,
                                              OverloadSelectionData OverloadData = new OverloadSelectionData())
        {
            var Ch = Node.Children;

            bool Static;
            var  Ch0Type = GetType(Ch[0], out Static);

            if (Ch0Type == null)
            {
                return(PluginResult.Succeeded);
            }

            var MemberName = Ch[1].Code;
            var Options    = GetIdOptions.Default;

            Options.OverloadData = OverloadData;

            if (Ch0Type is NamespaceType && !Static)
            {
                var IdCh0     = Ch[0] as IdExpressionNode;
                var Namespace = IdCh0.Identifier as Namespace;

                var List = Identifiers.SearchMember(Container, Namespace, MemberName.ToString());
                var Id   = Identifiers.SelectIdentifier(State, List, MemberName, Options);
                if (Id == null)
                {
                    return(PluginResult.Failed);
                }

                Node = Parent.NewNode(new IdExpressionNode(Id, Node.Code));
                if (Node == null || ResolveNode(ref Node) == PluginResult.Failed)
                {
                    return(PluginResult.Failed);
                }

                return(PluginResult.Ready);
            }
            else if (Ch0Type is EnumType && Static)
            {
                var EnumType = Ch0Type as EnumType;
                var Ret      = EnumType.GetValue(State, MemberName);
                if (Ret == null)
                {
                    return(PluginResult.Failed);
                }

                Node = Parent.NewNode(new IdExpressionNode(Ret, Node.Code));
                if (Node == null || ResolveNode(ref Node) == PluginResult.Failed)
                {
                    return(PluginResult.Failed);
                }

                return(PluginResult.Ready);
            }
            else
            {
                var List = Identifiers.SearchMember(Container, Ch0Type, MemberName.ToString());
                var Id   = Identifiers.SelectIdentifier(State, List, MemberName, Options);
                if (Id == null)
                {
                    return(PluginResult.Failed);
                }

                if (!Identifiers.VerifyAccess(Container, Id, MemberName))
                {
                    return(PluginResult.Failed);
                }

                var IdNode = Parent.NewNode(new IdExpressionNode(Id, Node.Code));
                if (IdNode == null)
                {
                    return(PluginResult.Failed);
                }

                if (Static)
                {
                    Node = IdNode;
                    if (ResolveNode(ref Node) == PluginResult.Failed)
                    {
                        return(PluginResult.Failed);
                    }

                    return(PluginResult.Ready);
                }
                else
                {
                    Ch[1] = IdNode;
                }
            }

            return(PluginResult.Succeeded);
        }
        private bool tokenizer()
        {
            token newtoken = new token();

            tokens.Clear();
            int idCount = 0;

            foreach (String nLexemes in lexemes)
            {
                if (isKeyword(nLexemes))
                {
                    newtoken = new token(nLexemes, "Keyword");
                    tokens.AddLast(newtoken);
                }
                else if (isOperator(nLexemes))
                {
                    newtoken = new token(nLexemes, "Operator");
                    tokens.AddLast(newtoken);
                }
                else if (isRelop(nLexemes))
                {
                    newtoken = new token(nLexemes, "RelOp");
                    tokens.AddLast(newtoken);
                }
                else if (isPunctuation(nLexemes))
                {
                    newtoken = new token(nLexemes, "Punctuation");
                    tokens.AddLast(newtoken);
                }
                else if (isNumber(nLexemes))
                {
                    newtoken = new token(nLexemes, "NUM");
                    tokens.AddLast(newtoken);
                }
                else if (nLexemes == terminator)
                {
                    newtoken = new token(nLexemes, "Terminator");
                    tokens.AddLast(newtoken);
                }
                else if (isLiteral(nLexemes))
                {
                    newtoken = new token(nLexemes, "Literals");
                    tokens.AddLast(newtoken);
                }
                else if (isId(nLexemes))
                {
                    // using System.CodeDom.Compiler;
                    CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");
                    if (provider.IsValidIdentifier(nLexemes))
                    {
                        int i = 0;
                        foreach (Identifiers id in identifier)
                        {
                            if (id.identifierName == nLexemes)
                            {
                                newtoken = new token(id.identifierName, id.identifierToken);
                                i        = 1;
                            }
                        }
                        if (i == 0)
                        {
                            Identifiers newId = new Identifiers(nLexemes, "ID" + idCount);
                            newtoken = new token(nLexemes, "ID" + idCount);
                            identifier.AddLast(newId);
                            idCount++;
                        }
                        tokens.AddLast(newtoken);
                    }
                    else
                    {
                        MessageBox.Show("Invalid Identifier: " + nLexemes);
                    }
                }
                else
                {
                    toolStripStatusLabel1.Text = "Invalid Token";
                }
            }
            return(true);
        }
Beispiel #33
0
        public override PluginResult NewNode(ref ExpressionNode Node)
        {
            for (var i = 0; i < Node.LinkedNodes.Count; i++)
            {
                var LNode = Node.LinkedNodes[i];
                LNode.Node = ResolveNode(LNode.Node);
                if (LNode.Node == null)
                {
                    return(PluginResult.Failed);
                }
            }

            if (Node is StrExpressionNode)
            {
                return(PluginResult.Interrupt);
            }
            else if (Node is LinkingNode)
            {
                return(PluginResult.Interrupt);
            }
            else if (Node is IdExpressionNode)
            {
                var IdNode = Node as IdExpressionNode;
                var Id     = IdNode.Identifier.RealId;

                if (Id is LocalVariable)
                {
                    if (!Container.IsSubContainerOf(Id.Container) && Container != Id.Container)
                    {
                        throw new ApplicationException();
                    }
                }

                if (Id is ConstVariable)
                {
                    var Const = Id as ConstVariable;
                    if (Const.ConstInitValue == null)
                    {
                        throw new ApplicationException();
                    }

                    Node = Parent.NewNode(new ConstExpressionNode(Const.TypeOfSelf, Const.ConstInitValue, Node.Code));
                    if (Node == null)
                    {
                        return(PluginResult.Failed);
                    }

                    if (ConvertEnums != null && Const.TypeOfSelf == ConvertEnums)
                    {
                        Node = new OpExpressionNode(Operator.Cast, Node.Code)
                        {
                            Children = new ExpressionNode[] { Node },
                            Type     = ConvertEnums.TypeOfValues,
                        };

                        if ((Node = Parent.NewNode(Node)) == null)
                        {
                            return(PluginResult.Failed);
                        }
                    }

                    return(PluginResult.Ready);
                }

                return(PluginResult.Interrupt);
            }
            else if (Node is OpExpressionNode)
            {
                var OpNode = Node as OpExpressionNode;
                var Op     = OpNode.Operator;
                var Ch     = OpNode.Children;

                if (Op == Operator.Assignment)
                {
                    if ((Ch[1] = ResolveNode(Ch[1])) == null)
                    {
                        return(PluginResult.Failed);
                    }

                    if ((Ch[0] = ResolveNode(Ch[0], Ch[1].Type)) == null)
                    {
                        return(PluginResult.Failed);
                    }
                }
                else if (Op == Operator.Call)
                {
                    if (!ResolveParams(Ch))
                    {
                        return(PluginResult.Failed);
                    }

                    var OverloadData = Expressions.GetOverloadSelectData(Ch);
                    Ch[0] = ResolveNode(Ch[0], OverloadData: OverloadData);
                    if (Ch[0] == null)
                    {
                        return(PluginResult.Failed);
                    }

                    var Res = ProcessParams(ref Node);
                    if (Res != PluginResult.Succeeded)
                    {
                        return(Res);
                    }

                    if ((State.Language.Flags & LangaugeFlags.AllowMemberFuncStaticRef) != 0)
                    {
                        var Ch0Id = Expressions.GetIdentifier(Ch[0]);
                        if (Ch0Id != null && Ch0Id.IsInstanceIdentifier)
                        {
                            State.Messages.Add(MessageId.NonStatic, Ch[0].Code);
                            return(PluginResult.Failed);
                        }
                    }
                }
                else if (Op == Operator.NewArray)
                {
                    if (!ResolveParams(Ch))
                    {
                        return(PluginResult.Failed);
                    }

                    if (Ch[0] is StrExpressionNode)
                    {
                        var Type = Container.RecognizeIdentifier(Ch[0].Code, GetIdOptions.DefaultForType);
                        if (Type == null)
                        {
                            return(PluginResult.Failed);
                        }

                        if (Ch.Length < 2)
                        {
                            State.Messages.Add(MessageId.ParamCount, Node.Code);
                            return(PluginResult.Failed);
                        }

                        Node.Type     = new RefArrayType(Container, Type, Ch.Length - 1);
                        Node.Children = Ch.Slice(1);
                        return(PluginResult.Succeeded);
                    }

                    var Ch0Id = Expressions.GetIdentifier(Ch[0]);
                    if (Ch0Id != null && Ch0Id.RealId is Type)
                    {
                        if (Ch.Length < 2)
                        {
                            State.Messages.Add(MessageId.ParamCount, Node.Code);
                            return(PluginResult.Failed);
                        }

                        Node.Type     = new RefArrayType(Container, Ch0Id, Ch.Length - 1);
                        Node.Children = Ch.Slice(1);
                        return(PluginResult.Succeeded);
                    }
                }
                else if (Op == Operator.NewObject)
                {
                    if (!ResolveParams(Ch))
                    {
                        return(PluginResult.Failed);
                    }

                    Identifier ConstructType = null;
                    if (Ch[0] is StrExpressionNode)
                    {
                        ConstructType = Container.RecognizeIdentifier(Ch[0].Code, GetIdOptions.DefaultForType);
                        if (ConstructType == null)
                        {
                            return(PluginResult.Failed);
                        }
                    }
                    else if (Ch[0] is IdExpressionNode)
                    {
                        var IdCh0 = Ch[0] as IdExpressionNode;
                        if (IdCh0.Identifier.RealId is Type)
                        {
                            ConstructType = IdCh0.Identifier;
                        }
                    }

                    if (ConstructType != null)
                    {
                        Node.Type = ConstructType;
                        if (ConstructType.RealId is AutomaticType)
                        {
                            if (!(Ch[0] is IdExpressionNode))
                            {
                                Ch[0] = Parent.NewNode(new IdExpressionNode(ConstructType, Node.Code));
                                if (Ch[0] == null)
                                {
                                    return(PluginResult.Failed);
                                }
                            }

                            Ch[0] = ResolveNode(Ch[0]);
                            return(Ch[0] == null ? PluginResult.Failed : PluginResult.Succeeded);
                        }

                        if (Ch.Length == 1 && !(ConstructType.UnderlyingClassOrRealId is ClassType))
                        {
                            OpNode.Children = Ch = null;
                            return(PluginResult.Succeeded);
                        }

                        var Structured = ConstructType.UnderlyingClassOrRealId as StructuredType;
                        if (Structured == null)
                        {
                            State.Messages.Add(MessageId.ParamCount, Node.Code);
                            return(PluginResult.Failed);
                        }

                        var Options = GetIdOptions.Default;
                        Options.OverloadData = Expressions.GetOverloadSelectData(Ch);
                        Options.Func         = x => x is Constructor;

                        var Constructor = Identifiers.GetMember(State, Structured, null, Node.Code, Options);
                        if (Constructor == null)
                        {
                            return(PluginResult.Failed);
                        }

                        if (!Identifiers.VerifyAccess(Container, Constructor, Node.Code))
                        {
                            return(PluginResult.Failed);
                        }

                        Ch[0] = Parent.NewNode(new IdExpressionNode(Constructor, Ch[0].Code));
                        if (Ch[0] == null)
                        {
                            return(PluginResult.Failed);
                        }
                    }

                    Ch[0] = ResolveNode(Ch[0]);
                    if (Ch[0] == null)
                    {
                        return(PluginResult.Failed);
                    }

                    var Res = ProcessParams(ref Node);
                    if (Res != PluginResult.Succeeded)
                    {
                        return(Res);
                    }
                }
                else if (Op == Operator.Member)
                {
                    if ((Ch[0] = ResolveNode(Ch[0])) == null)
                    {
                        return(PluginResult.Failed);
                    }

                    return(PluginResult.Interrupt);
                }
                else if (Op == Operator.Tuple || Op == Operator.ScopeResolution)
                {
                    return(PluginResult.Interrupt);
                }
                else if (Ch != null)
                {
                    for (var i = 0; i < Ch.Length; i++)
                    {
                        Ch[i] = ResolveNode(Ch[i]);
                        if (Ch[i] == null)
                        {
                            return(PluginResult.Failed);
                        }
                    }

                    return(PluginResult.Succeeded);
                }
            }
            else if (Node.Children != null)
            {
                for (var i = 0; i < Node.Children.Length; i++)
                {
                    Node.Children[i] = ResolveNode(Node.Children[i]);
                    if (Node.Children[i] == null)
                    {
                        return(PluginResult.Failed);
                    }
                }
            }

            return(PluginResult.Succeeded);
        }
Beispiel #34
0
        protected bool autolocalhost = false;           // автоматически подключаться к локальному серверу данных

        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        protected Application()
        {
            try
            {
                ErrorHandler.InitializeErrorHandler();
                ErrorHandler.OnExit += new EventHandler(ErrorHandler_OnExit);

                buffer  = new RSliceBuffer(72000);
                manager = new DataBaseManager();

                projects = new List <Project>();
                commands = new List <BlockViewCommand>();

                parameters = new Parameter[256];
                for (int index = 0; index < parameters.Length; index++)
                {
                    parameters[index]            = new Parameter(index);
                    parameters[index].Identifier = Identifiers.GetGuid(index);
                }

                tech       = new Tech();
                commutator = new Commutator(tech, parameters, buffer);

                panels = new List <ParametersViewPanel>();
//                devManUri = new Uri("net.tcp://localhost:57000");
                devManUri = new Uri("net.tcp://127.0.0.1:57000");

                CheckRegistry();

                LoadUri();

                DevManClient.Uri = devManUri;

                DevManClient.Context.Mode = UserMode.Passive;
                DevManClient.Context.Role = Role.Common;

                client = new devTcpManager();

                Ping        ping    = new Ping();
                PingOptions options = new PingOptions();

                try
                {
                    PingReply reply = ping.Send(devManUri.Host);
                    if (reply.Status == IPStatus.Success)
                    {
                        /*DevManClient.Uri = devManUri;
                         *
                         * DevManClient.Context.Mode = UserMode.Passive;
                         * DevManClient.Context.Role = Role.Common;*/

                        DevManClient.Connect();

                        // client = new devTcpManager();

                        string ip = System.Net.Dns.Resolve(devManUri.Host).AddressList[0].ToString();
                        //string ip = System.Net.Dns.GetHostEntry(devManUri.Host).AddressList[0].ToString();

                        client.Client.Host = ip;
                        client.Client.Port = 56000;

                        client.Client.Connect();
                    }
                    else
                    {
                        /*try
                         * {
                         *  client = null;
                         * }
                         * catch { }*/
                    }
                }
                catch { }
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteToLog(this, new ErrorArgs(ex.Message, ErrorType.Fatal));
            }
        }
Beispiel #35
0
        private void DefineLexem()
        {
            bool f = false;

            switch (currentState)
            {
            case State.Identificator:
                f = SearchInTable(Keywords);
                nextLexem.type = LexemType.Keyword;
                if (!f)
                {
                    f = SearchInTable(Identifiers);
                    nextLexem.type = LexemType.Identifier;
                }
                if (!f)
                {
                    nextLexem.code = lastId++;
                    Identifiers.Add(currentLexem.ToString(), nextLexem.code);
                    nextLexem.type = LexemType.Identifier;
                }
                OutputLexem();
                break;

            case State.Variable:
                f = SearchInTable(Constants);
                if (!f)
                {
                    nextLexem.code = lastConst++;
                    Constants.Add(currentLexem.ToString(), nextLexem.code);
                }
                nextLexem.type = LexemType.Variable;
                OutputLexem();
                break;

            case State.Separtor:
                SearchInTable(Separators);
                nextLexem.type   = LexemType.Separtor;
                nextLexem.line   = CurrentLine;
                nextLexem.column = CurrentColumn;
                OutputLexem();
                break;

            case State.WhiteSpace:
                break;

            case State.MultiSeparator:
                f = SearchInTable(MultiSeparators);
                if (f)
                {
                    nextLexem.type   = LexemType.MultiSymbolicSeparator;
                    nextLexem.line   = CurrentLine - currentLexem.Length;
                    nextLexem.column = CurrentColumn - currentLexem.Length + 1;
                    OutputLexem();
                }
                else
                {
                    int    i          = 1;
                    string separators = currentLexem.ToString();
                    foreach (var item in separators)
                    {
                        currentLexem.Clear();
                        currentLexem.Append(item);
                        nextLexem.line   = CurrentLine;
                        nextLexem.column = CurrentColumn - separators.Length + i;
                        i++;
                        if (SearchInTable(Separators))
                        {
                            nextLexem.type = LexemType.Separtor;
                            OutputLexem();
                        }
                        else
                        {
                            currentState = State.Separtor;
                            DefineError(item);
                        }
                    }
                }
                break;
            }
        }
Beispiel #36
0
 static TIten()
 {
     Identifiers
     .Add(x => x.Id)
     ;
 }
Beispiel #37
0
 public override Statement CloneStatement()
 {
     return(new ReturnAssignment(
                Identifiers.Clone() as ExpressionList,
                Invocation.CloneExpr() as InvocationExpression));
 }