Esempio n. 1
0
        private static string FixTypename(StructEntry entry)
        {
            if (_aliasedTypes.TryGetValue(entry.Type, out var aliased))
            {
                entry.Type = aliased;
            }

            if (entry.Type == "void")
            {
                entry.IsPointer = false;
                if (entry.IsPointerPointer)
                {
                    entry.IsPointer        = true;
                    entry.IsPointerPointer = false;
                }

                if (entry.ArraySize > 0)
                {
                    //entry.Attribute = "[MarshalAs(UnmanagedType.SysInt)]";
                    return(_sysintname);
                }
            }

            if (_fixedTypes.TryGetValue(entry.Type, out var fixedType))
            {
                return(fixedType);
            }

            return(Fixname(entry.Type).Trim());
        }
Esempio n. 2
0
 public SynScope(StructEntry entry)
 {
     foreach (var mod in entry.Modules)
     {
         var s_mod = new SynModule(mod);
     }
 }
Esempio n. 3
0
        public override int GetHashCode()
        {
            int hashcode = 157;

            unchecked {
                if (__isset.primitiveEntry)
                {
                    hashcode = (hashcode * 397) + PrimitiveEntry.GetHashCode();
                }
                if (__isset.arrayEntry)
                {
                    hashcode = (hashcode * 397) + ArrayEntry.GetHashCode();
                }
                if (__isset.mapEntry)
                {
                    hashcode = (hashcode * 397) + MapEntry.GetHashCode();
                }
                if (__isset.structEntry)
                {
                    hashcode = (hashcode * 397) + StructEntry.GetHashCode();
                }
                if (__isset.unionEntry)
                {
                    hashcode = (hashcode * 397) + UnionEntry.GetHashCode();
                }
                if (__isset.userDefinedTypeEntry)
                {
                    hashcode = (hashcode * 397) + UserDefinedTypeEntry.GetHashCode();
                }
            }
            return(hashcode);
        }
Esempio n. 4
0
        private static string TypeFromBitLength(StructEntry entry)
        {
            if (entry.BitLength == 1)
            {
                return("bool");
            }

            return(FixTypename(entry));
        }
Esempio n. 5
0
        public CompiledSource Compile(ScriptSource s, LogInfo logger = null)
        {
            CompiledSource cs = new CompiledSource();

            var parser = new Parser(s.Tokens, logger);
            //parser.LogOut = logger;

            StructEntry entry = parser.Entry;

            cs.EntryPoint = entry;

            return(cs);
        }
Esempio n. 6
0
        public CompiledSource Compile(ScriptSource s)
        {
            CompiledSource cs = new CompiledSource();


            var parser = new Parser(s.Tokens);

            StructEntry entry = parser.Entry;

            cs.EntryPoint = entry;

            return(cs);
        }
Esempio n. 7
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder("TTypeEntry(");

            sb.Append("PrimitiveEntry: ");
            sb.Append(PrimitiveEntry == null ? "<null>" : PrimitiveEntry.ToString());
            sb.Append(",ArrayEntry: ");
            sb.Append(ArrayEntry == null ? "<null>" : ArrayEntry.ToString());
            sb.Append(",MapEntry: ");
            sb.Append(MapEntry == null ? "<null>" : MapEntry.ToString());
            sb.Append(",StructEntry: ");
            sb.Append(StructEntry == null ? "<null>" : StructEntry.ToString());
            sb.Append(",UnionEntry: ");
            sb.Append(UnionEntry == null ? "<null>" : UnionEntry.ToString());
            sb.Append(",UserDefinedTypeEntry: ");
            sb.Append(UserDefinedTypeEntry == null ? "<null>" : UserDefinedTypeEntry.ToString());
            sb.Append(")");
            return(sb.ToString());
        }
Esempio n. 8
0
        public Holder()
        {
            var node1 = new ClassNode(typeof(Class01), new Class01());
            var node2 = new ClassNode(typeof(Class02), new Class02());
            var node3 = new ClassNode(typeof(Class03), new Class03());

            node1.Next = node2;
            node2.Next = node3;
            nodeRef    = node1;

            structEntriesRef    = new StructEntry[3];
            structEntriesRef[0] = new StructEntry(typeof(Class01), new Class01());
            structEntriesRef[1] = new StructEntry(typeof(Class02), new Class02());
            structEntriesRef[2] = new StructEntry(typeof(Class03), new Class03());

            classEntriesRef    = new ClassEntry[3];
            classEntriesRef[0] = new ClassEntry(typeof(Class01), new Class01());
            classEntriesRef[1] = new ClassEntry(typeof(Class02), new Class02());
            classEntriesRef[2] = new ClassEntry(typeof(Class03), new Class03());
        }
Esempio n. 9
0
 public void SetEntry(Structs.StructEntry entry)
 {
     Entry = entry;
 }
Esempio n. 10
0
        public void Write(TProtocol oprot)
        {
            TStruct struc = new TStruct("TTypeEntry");

            oprot.WriteStructBegin(struc);
            TField field = new TField();

            if (PrimitiveEntry != null && __isset.primitiveEntry)
            {
                field.Name = "primitiveEntry";
                field.Type = TType.Struct;
                field.ID   = 1;
                oprot.WriteFieldBegin(field);
                PrimitiveEntry.Write(oprot);
                oprot.WriteFieldEnd();
            }
            if (ArrayEntry != null && __isset.arrayEntry)
            {
                field.Name = "arrayEntry";
                field.Type = TType.Struct;
                field.ID   = 2;
                oprot.WriteFieldBegin(field);
                ArrayEntry.Write(oprot);
                oprot.WriteFieldEnd();
            }
            if (MapEntry != null && __isset.mapEntry)
            {
                field.Name = "mapEntry";
                field.Type = TType.Struct;
                field.ID   = 3;
                oprot.WriteFieldBegin(field);
                MapEntry.Write(oprot);
                oprot.WriteFieldEnd();
            }
            if (StructEntry != null && __isset.structEntry)
            {
                field.Name = "structEntry";
                field.Type = TType.Struct;
                field.ID   = 4;
                oprot.WriteFieldBegin(field);
                StructEntry.Write(oprot);
                oprot.WriteFieldEnd();
            }
            if (UnionEntry != null && __isset.unionEntry)
            {
                field.Name = "unionEntry";
                field.Type = TType.Struct;
                field.ID   = 5;
                oprot.WriteFieldBegin(field);
                UnionEntry.Write(oprot);
                oprot.WriteFieldEnd();
            }
            if (UserDefinedTypeEntry != null && __isset.userDefinedTypeEntry)
            {
                field.Name = "userDefinedTypeEntry";
                field.Type = TType.Struct;
                field.ID   = 6;
                oprot.WriteFieldBegin(field);
                UserDefinedTypeEntry.Write(oprot);
                oprot.WriteFieldEnd();
            }
            oprot.WriteFieldStop();
            oprot.WriteStructEnd();
        }
Esempio n. 11
0
        private static IReadOnlyList <StructEntry> ParseStruct(string def)
        {
            var pos          = StructPos.Unknown;
            var i            = def.IndexOf('{');
            var sb           = new StringBuilder();
            var entries      = new List <StructEntry>();
            var currentEntry = new StructEntry();

            for (; i < def.Length; ++i)
            {
                var chr   = def[i];
                var ended = false;
                var rest  = def.Substring(i); // for debugging.

                switch (chr)
                {
                case '{' when pos == StructPos.Unknown:
                    pos = StructPos.Type;
                    SkipWhitespace(def, ref i);
                    break;

                case '}' when pos == StructPos.Type:
                    return(entries);

                case '/' when pos == StructPos.Type:
                    currentEntry.Comment = GetComment(def, ref i);
                    break;

                case ' ' when pos == StructPos.Type:
                    var typeFull = sb.ToString().Trim();
                    var typeName = typeFull.TrimEnd('*');
                    var points   = typeFull.Length - typeName.Length;
                    switch (points)
                    {
                    case 1: currentEntry.IsPointer = true; break;

                    case 2: currentEntry.IsPointerPointer = true; break;
                    }
                    currentEntry.Type = typeName;
                    sb.Clear();
                    SkipWhitespace(def, ref i);
                    pos = StructPos.Name;
                    break;

                case ':' when pos == StructPos.Name:
                case ';' when pos == StructPos.Name:
                case '/' when pos == StructPos.Name:
                    currentEntry.Name = sb.ToString().Trim();
                    sb.Clear();
                    SkipWhitespace(def, ref i);
                    if (chr == ':')
                    {
                        ++i;
                        SkipWhitespace(def, ref i);
                        var numsb = new StringBuilder();
                        for (; i < def.Length; ++i)
                        {
                            chr = def[i];
                            if (char.IsDigit(chr))
                            {
                                numsb.Append(chr);
                                continue;
                            }

                            break;
                        }

                        currentEntry.BitLength = int.Parse(numsb.ToString());
                        SkipWhitespace(def, ref i);


                        for (; i < def.Length; ++i)
                        {
                            chr = def[i];
                            var end = false;
                            switch (chr)
                            {
                            case ';': break;

                            case ' ': continue;

                            default: --i; end = true; break;
                            }

                            if (end)
                            {
                                break;
                            }
                        }
                    }
                    pos   = StructPos.Comment;
                    ended = true;
                    break;

                default:
                    switch (pos)
                    {
                    case StructPos.Comment:
                    case StructPos.Name:
                    case StructPos.Type:
                        sb.Append(chr);
                        break;
                    }
                    break;
                }

                if (ended)
                {
                    if (currentEntry.Comment == null)
                    {
                        for (; i < def.Length; ++i)
                        {
                            var chr2 = def[i];
                            if (char.IsWhiteSpace(chr2))
                            {
                                continue;
                            }
                            if (chr2 == '/' && def[i + 1] == '*')
                            {
                                currentEntry.Comment = GetComment(def, ref i);
                                break;
                            }

                            --i;
                            break;
                        }
                    }

                    var match = _typeLength.Match(currentEntry.Name);

                    if (match.Success)
                    {
                        currentEntry.ArraySize = int.Parse(match.Groups["value"].Value);
                    }

                    entries.Add(currentEntry);
                    currentEntry = new StructEntry();
                    pos          = StructPos.Type;
                    sb.Clear();
                    SkipWhitespace(def, ref i);
                }
            }

            return(entries);
        }
Esempio n. 12
0
 public Module(StructEntry entry)
 {
     Mod = entry;
 }
Esempio n. 13
0
        public Parser(TokenStream stream)
        {
            wr = File.CreateText("parserLog.txt");

            Entry = new StructEntry();

            toks = stream;

            Log("Begun parsing source.", 1);

            for (int i = 0; i < stream.Len; i++)
            {
                var tok = stream.Tokes[i];

                switch (tok.Token)
                {
                case Token.Compute:

                    var com = ParseCompute(ref i);
                    Entry.Coms.Add(com);

                    break;

                case Token.ComputeStruct:



                    var com_str = ParseComputeStruct(ref i);
                    //  Entry.ComInputs.Add(com_in);
                    Console.WriteLine("StructCom");
                    Entry.ComStructs.Add(com_str);
                    ComStructs.Add(com_str);


                    break;

                case Token.Func:

                    var func = ParseFunc(ref i);

                    Entry.SystemFuncs.Add(func);

                    break;

                case Token.Module:

                    var mod = ParseModule(ref i);

                    Entry.Modules.Add(mod);

                    break;

                default:
                    //  Error(i, "Expected module/func or similar construct definition");
                    break;
                }
            }

            wr.Flush();
            wr.Close();

            foreach (var com in Entry.Coms)
            {
                com.GenCode();
            }
        }
Esempio n. 14
0
        public Parser(TokenStream stream, LogInfo logger)
        {
            LogOut = logger;
            wr     = File.CreateText("parserLog.txt");

            Log("Toks:" + stream.Tokes.Count);

            foreach (var tok in stream.Tokes)
            {
                Log(tok.ToString(), 1, true);
            }

            Entry = new StructEntry();

            toks = stream;

            Log("Begun parsing source.", 1);

            for (int i = 0; i < stream.Len; i++)
            {
                var tok = stream.Tokes[i];

                switch (tok.Token)
                {
                case Token.Game:

                    Console.WriteLine("Parsing game...");

                    var game_str = ParseGameStruct(ref i);

                    Entry.Game = game_str;

                    Entry.InitState = game_str.InitState;

                    break;

                case Token.Compute:

                    var com = ParseCompute(ref i);
                    Entry.Coms.Add(com);

                    break;

                case Token.ComputeStruct:

                    var com_str = ParseComputeStruct(ref i);
                    //  Entry.ComInputs.Add(com_in);
                    //Console.WriteLine("StructCom");
                    Entry.ComStructs.Add(com_str);
                    ComStructs.Add(com_str);

                    break;

                case Token.Func:

                    var func = ParseFunc(ref i);

                    Entry.SystemFuncs.Add(func);

                    break;

                case Token.Module:

                    var mod = ParseModule(ref i);

                    Entry.Modules.Add(mod);

                    break;

                default:
                    //  Error(i, "Expected module/func or similar construct definition");
                    break;
                }
            }

            wr.Flush();
            wr.Close();

            foreach (var com in Entry.Coms)
            {
                com.GenCode();
            }
        }
Esempio n. 15
0
        public override string ToString()
        {
            var  sb      = new StringBuilder("TTypeEntry(");
            bool __first = true;

            if (PrimitiveEntry != null && __isset.primitiveEntry)
            {
                if (!__first)
                {
                    sb.Append(", ");
                }
                __first = false;
                sb.Append("PrimitiveEntry: ");
                sb.Append(PrimitiveEntry == null ? "<null>" : PrimitiveEntry.ToString());
            }
            if (ArrayEntry != null && __isset.arrayEntry)
            {
                if (!__first)
                {
                    sb.Append(", ");
                }
                __first = false;
                sb.Append("ArrayEntry: ");
                sb.Append(ArrayEntry == null ? "<null>" : ArrayEntry.ToString());
            }
            if (MapEntry != null && __isset.mapEntry)
            {
                if (!__first)
                {
                    sb.Append(", ");
                }
                __first = false;
                sb.Append("MapEntry: ");
                sb.Append(MapEntry == null ? "<null>" : MapEntry.ToString());
            }
            if (StructEntry != null && __isset.structEntry)
            {
                if (!__first)
                {
                    sb.Append(", ");
                }
                __first = false;
                sb.Append("StructEntry: ");
                sb.Append(StructEntry == null ? "<null>" : StructEntry.ToString());
            }
            if (UnionEntry != null && __isset.unionEntry)
            {
                if (!__first)
                {
                    sb.Append(", ");
                }
                __first = false;
                sb.Append("UnionEntry: ");
                sb.Append(UnionEntry == null ? "<null>" : UnionEntry.ToString());
            }
            if (UserDefinedTypeEntry != null && __isset.userDefinedTypeEntry)
            {
                if (!__first)
                {
                    sb.Append(", ");
                }
                __first = false;
                sb.Append("UserDefinedTypeEntry: ");
                sb.Append(UserDefinedTypeEntry == null ? "<null>" : UserDefinedTypeEntry.ToString());
            }
            sb.Append(")");
            return(sb.ToString());
        }
Esempio n. 16
0
        public async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                var struc = new TStruct("TTypeEntry");
                await oprot.WriteStructBeginAsync(struc, cancellationToken);

                var field = new TField();
                if (PrimitiveEntry != null && __isset.primitiveEntry)
                {
                    field.Name = "primitiveEntry";
                    field.Type = TType.Struct;
                    field.ID   = 1;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await PrimitiveEntry.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (ArrayEntry != null && __isset.arrayEntry)
                {
                    field.Name = "arrayEntry";
                    field.Type = TType.Struct;
                    field.ID   = 2;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await ArrayEntry.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (MapEntry != null && __isset.mapEntry)
                {
                    field.Name = "mapEntry";
                    field.Type = TType.Struct;
                    field.ID   = 3;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await MapEntry.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (StructEntry != null && __isset.structEntry)
                {
                    field.Name = "structEntry";
                    field.Type = TType.Struct;
                    field.ID   = 4;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await StructEntry.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (UnionEntry != null && __isset.unionEntry)
                {
                    field.Name = "unionEntry";
                    field.Type = TType.Struct;
                    field.ID   = 5;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await UnionEntry.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (UserDefinedTypeEntry != null && __isset.userDefinedTypeEntry)
                {
                    field.Name = "userDefinedTypeEntry";
                    field.Type = TType.Struct;
                    field.ID   = 6;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await UserDefinedTypeEntry.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                await oprot.WriteFieldStopAsync(cancellationToken);

                await oprot.WriteStructEndAsync(cancellationToken);
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }