예제 #1
0
        void WorkoutTypes()
        {
            foreach (var c in def.typedefs)
            {
                if (c.Name.StartsWith("uint") || c.Name.StartsWith("int") || c.Name.StartsWith("lint") || c.Name.StartsWith("luint") || c.Name.StartsWith("ulint"))
                {
                    continue;
                }

                // Unused, messers
                if (c.Name == "Salt_t" || c.Name == "compile_time_assert_type" || c.Name == "ValvePackingSentinel_t" || c.Name.Contains("::") || c.Type.Contains("(*)"))
                {
                    continue;
                }

                var type = c.Type;

                type = ToManagedType(type);

                TypeDefs.Add(c.Name, new TypeDef()
                {
                    Name        = c.Name,
                    NativeType  = c.Type,
                    ManagedType = type,
                });
            }
        }
예제 #2
0
 public void RemoveTypeDef(TypeDef td)
 {
     if (!TypeDefs.Remove(td))
     {
         throw new ApplicationException($"Could not remove TypeDef: {td}");
     }
 }
예제 #3
0
 public void RemoveTypeDef(TypeDef td)
 {
     if (!TypeDefs.Remove(td))
     {
         throw new ApplicationException(string.Format("Could not remove TypeDef: {0}", td));
     }
 }
예제 #4
0
        public void AddTypeDef(Type type)
        {
            string name = type.Name;

            if (TypeDefs.ContainsKey(name))
            {
                return;
            }

            ElmAstNode def;

            if (type.IsEnum)
            {
                var t = new AdtDef(name);
                t.Alternatives.AddRange(Array.ConvertAll(type.GetEnumNames(), altName => AdtAlternativeName(type, altName)));
                def = t;
            }
            else
            {
                //Otherwise, a class
                var t = new RecordDef(name);
                def = t;
                foreach (var prop in type.GetProperties(PROP_FLAGS))
                {
                    var jsonAttrs = prop.GetCustomAttributes(typeof(JsonPropertyAttribute));
                    if (jsonAttrs.Any())
                    {
                        t.Fields.Add(ElmRecordFieldName(prop), ElmType(prop.PropertyType));

                        //If the property type is an enum, generate an ADT for it
                        if (prop.PropertyType.IsEnum)
                        {
                            AddTypeDef(prop.PropertyType);
                            AddDecodeFun(prop.PropertyType);
                            AddEncodeFun(prop.PropertyType);
                            AddToStringFun(prop.PropertyType);
                        }
                    }
                }
            }

            TypeDefs.Add(name, def);
        }
예제 #5
0
파일: PProgram.cs 프로젝트: tvrprasad/P
        public void Add(object item)
        {
            if (IgnoreDecl)
            {
                return;
            }

            else if (item is P_Root.MachineSends)
            {
                MachineSends.Add(item as P_Root.MachineSends);
            }
            else if (item is P_Root.MachineReceives)
            {
                MachineReceives.Add(item as P_Root.MachineReceives);
            }
            else if (item is P_Root.MachineProtoDecl)
            {
                MachineProtoDecls.Add(item as P_Root.MachineProtoDecl);
            }
            else if (item is P_Root.FunProtoDecl)
            {
                FunProtoDecls.Add(item as P_Root.FunProtoDecl);
            }
            else if (item is P_Root.MachineExports)
            {
                MachineExports.Add(item as P_Root.MachineExports);
            }
            else if (item is P_Root.EventSetContains)
            {
                EventSetContains.Add(item as P_Root.EventSetContains);
            }
            else if (item is P_Root.EventSetDecl)
            {
                EventSetDecl.Add(item as P_Root.EventSetDecl);
            }
            else if (item is P_Root.InterfaceTypeDef)
            {
                InterfaceTypeDef.Add(item as P_Root.InterfaceTypeDef);
            }
            else if (item is P_Root.ObservesDecl)
            {
                Observes.Add(item as P_Root.ObservesDecl);
            }
            else if (item is P_Root.Annotation)
            {
                Annotations.Add(item as P_Root.Annotation);
            }
            else if (item is P_Root.DoDecl)
            {
                Dos.Add(item as P_Root.DoDecl);
            }
            else if (item is P_Root.AnonFunDecl)
            {
                AnonFunctions.Add(item as P_Root.AnonFunDecl);
            }
            else if (item is P_Root.FunDecl)
            {
                Functions.Add(item as P_Root.FunDecl);
            }
            else if (item is P_Root.TransDecl)
            {
                Transitions.Add(item as P_Root.TransDecl);
            }
            else if (item is P_Root.VarDecl)
            {
                Variables.Add(item as P_Root.VarDecl);
            }
            else if (item is P_Root.StateDecl)
            {
                States.Add(item as P_Root.StateDecl);
            }
            else if (item is P_Root.MachineDecl)
            {
                Machines.Add(item as P_Root.MachineDecl);
            }
            else if (item is P_Root.EventDecl)
            {
                Events.Add(item as P_Root.EventDecl);
            }
            else if (item is P_Root.ModelType)
            {
                ModelTypes.Add(item as P_Root.ModelType);
            }
            else if (item is P_Root.EnumTypeDef)
            {
                EnumTypeDefs.Add(item as P_Root.EnumTypeDef);
            }
            else if (item is P_Root.TypeDef)
            {
                TypeDefs.Add(item as P_Root.TypeDef);
            }
            else if (item is P_Root.DependsOn)
            {
                DependsOn.Add(item as P_Root.DependsOn);
            }
            else if (item is P_Root.FunProtoCreatesDecl)
            {
                FunProtoCreates.Add(item as P_Root.FunProtoCreatesDecl);
            }
            else
            {
                throw new Exception("Cannot add into the Program : " + item.ToString());
            }
        }
예제 #6
0
 public void Add(object item)
 {
     if (item is P_Root.AnyTypeDecl)
     {
         AnyTypeDecl.Add(item as P_Root.AnyTypeDecl);
     }
     else if (item is P_Root.MachineSends)
     {
         MachineSends.Add(item as P_Root.MachineSends);
     }
     else if (item is P_Root.MachineReceives)
     {
         MachineReceives.Add(item as P_Root.MachineReceives);
     }
     else if (item is P_Root.EventSetContains)
     {
         EventSetContains.Add(item as P_Root.EventSetContains);
     }
     else if (item is P_Root.EventSetDecl)
     {
         EventSetDecl.Add(item as P_Root.EventSetDecl);
     }
     else if (item is P_Root.InterfaceDef)
     {
         InterfaceDef.Add(item as P_Root.InterfaceDef);
     }
     else if (item is P_Root.ObservesDecl)
     {
         Observes.Add(item as P_Root.ObservesDecl);
     }
     else if (item is P_Root.Annotation)
     {
         Annotations.Add(item as P_Root.Annotation);
     }
     else if (item is P_Root.DoDecl)
     {
         Dos.Add(item as P_Root.DoDecl);
     }
     else if (item is P_Root.AnonFunDecl)
     {
         AnonFunctions.Add(item as P_Root.AnonFunDecl);
     }
     else if (item is P_Root.FunDecl)
     {
         Functions.Add(item as P_Root.FunDecl);
     }
     else if (item is P_Root.TransDecl)
     {
         Transitions.Add(item as P_Root.TransDecl);
     }
     else if (item is P_Root.VarDecl)
     {
         Variables.Add(item as P_Root.VarDecl);
     }
     else if (item is P_Root.StateDecl)
     {
         States.Add(item as P_Root.StateDecl);
     }
     else if (item is P_Root.MachineDecl)
     {
         Machines.Add(item as P_Root.MachineDecl);
     }
     else if (item is P_Root.MachineCard)
     {
         MachineCards.Add(item as P_Root.MachineCard);
     }
     else if (item is P_Root.MachineKind)
     {
         MachineKinds.Add(item as P_Root.MachineKind);
     }
     else if (item is P_Root.MachineStart)
     {
         MachineStarts.Add(item as P_Root.MachineStart);
     }
     else if (item is P_Root.EventDecl)
     {
         Events.Add(item as P_Root.EventDecl);
     }
     else if (item is P_Root.EnumTypeDef)
     {
         EnumTypeDefs.Add(item as P_Root.EnumTypeDef);
     }
     else if (item is P_Root.TypeDef)
     {
         TypeDefs.Add(item as P_Root.TypeDef);
     }
     else if (item is P_Root.DependsOn)
     {
         DependsOn.Add(item as P_Root.DependsOn);
     }
     else
     {
         throw new Exception("Cannot add into the Program : " + item);
     }
 }