Example #1
0
        /// <summary>
        /// Constructs a new course object.
        /// </summary>
        /// <param name="name">The name of the course.</param>
        /// <param name="credits">The credit value of the course.</param>
        /// <param name="groups">An array containing the level groups of the course.</param>
        /// <param name="scoreTable">The table that maps scores to GPA values.</param>
        public StaticCourse(string name, double credits, LevelGroup[] groups, ScoreTable scoreTable)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (credits <= 0)
            {
                throw new ArgumentOutOfRangeException("credits");
            }
            if (groups == null)
            {
                throw new ArgumentNullException("groups");
            }
            if (groups.Length == 0)
            {
                throw new ArgumentException("Must provide at least one level group");
            }
            if (scoreTable == null)
            {
                throw new ArgumentNullException("scoreTable");
            }
            _name       = name;
            _credits    = credits;
            _groups     = groups;
            _scoreTable = scoreTable;

            LevelGroup group = groups[0];

            _selectedLevelGroup = group;
            _selectedLevel      = group.LevelCount > 0 ? group[0] : null;

            NameTranslator = x => x;
        }
        public static BinarySerializer Create()
        {
            var bs = new BinarySerializer();
            var st = new StringTranslator();

            bs.PutReaderTranslator(st);
            bs.PutWriterTranslator(st);
            bs.PutCounterTranslator(st);
            return(bs);
        }
Example #3
0
File: Level.cs Project: apsun/EzGPA
        /// <summary>
        /// Constructs a new level container.
        /// </summary>
        /// <param name="name">The name of the level.</param>
        /// <param name="bonusGpa">The bonus GPA associated with the level.</param>
        public Level(string name, double bonusGpa)
        {
            if (name == null)
                throw new ArgumentNullException("name");
            if (bonusGpa < 0)
                throw new ArgumentOutOfRangeException("bonusGpa");
            _name = name;
            _bonusGpa = bonusGpa;

            NameTranslator = x => x;
        }
 public void SelectAllDataBinary()
 {
     //Setup 
     var t = new StringTranslator(UNIT_TEST_COL_NAME);
     var cmd = CreateTextCommand(SelectTestDataSQL());
     //Act
     var data = t.Translate(ExecuteDataTable(cmd));
     //Assert
     Assert.AreEqual(5, data.Count);
     Assert.AreEqual(TEST_DATA, data[0]);
 }
Example #5
0
        /// <summary>
        /// Constructs a new level group.
        /// </summary>
        /// <param name="groupName">The name of the level group.</param>
        /// <param name="levels">An array of level objects to encapsulate.</param>
        public LevelGroup(string groupName, Level[] levels)
        {
            if (levels == null)
            {
                throw new ArgumentNullException("levels");
            }
            _name   = groupName;
            _levels = levels;

            NameTranslator = x => x;
        }
        public void SelectDataBinaryWithFilter()
        {
            //setup
            const string testvalue = TEST_DATA;
            var t = new StringTranslator(UNIT_TEST_COL_NAME);
            var cmd = CreateTextCommand(SelectTestDataSQL(), "Where col = @testValue");
            cmd.Parameters.Add(testvalue.ToSqlParameter("@testValue"));

            //Act
            var data = t.Translate(ExecuteDataTable(cmd));

            //Asert
            Assert.AreEqual(1, data.Count);
        }
Example #7
0
File: Level.cs Project: apsun/EzGPA
        /// <summary>
        /// Constructs a new level container.
        /// </summary>
        /// <param name="name">The name of the level.</param>
        /// <param name="bonusGpa">The bonus GPA associated with the level.</param>
        public Level(string name, double bonusGpa)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (bonusGpa < 0)
            {
                throw new ArgumentOutOfRangeException("bonusGpa");
            }
            _name     = name;
            _bonusGpa = bonusGpa;

            NameTranslator = x => x;
        }
Example #8
0
        public static void Start(ProgramOptions programOptions)
        {
            Console.WriteLine(programOptions);
            Settings.SetProgramOptions(programOptions);
            var outputPath = SetupOutputFile();

            streamWriter.WriteLine(Resource.GetResourceAsString("TinyBCT.Resources.Prelude.bpl"));

            if (Settings.AsyncSupport || Settings.AsyncSupportGenerics)
            {
                streamWriter.WriteLine(Resource.GetResourceAsString("TinyBCT.Resources.CommonAsyncPrelude.bpl"));
            }

            if (Settings.AsyncSupport)
            {
                streamWriter.WriteLine(Resource.GetResourceAsString("TinyBCT.Resources.AsyncPrelude.bpl"));
            }

            if (Settings.AsyncSupportGenerics)
            {
                streamWriter.WriteLine(Resource.GetResourceAsString("TinyBCT.Resources.AsyncPreludeGeneric.bpl"));
            }

            using (var host = new PeReader.DefaultHost())
            {
                #region Load assemblies
                ISet <Assembly> inputAssemblies = new HashSet <Assembly>();
                foreach (string inputFile in Settings.InputFiles)
                {
                    Assembly assembly = new Assembly(host);
                    assembly.Load(inputFile);
                    inputAssemblies.Add(assembly);
                }
                #endregion

                #region Execute CHA
                var CHAnalysis = new ClassHierarchyAnalysis(host);
                CHAnalysis.Analyze();
                #endregion

                #region Initialize host types
                Types.Initialize(host);
                #endregion

                // TODO(diegog): Analysis not integrated yet
                // This can be used to obtain the allocated types and delegates
                //var allocationsAndDelelegatesAnalysis = new TypesAndDelegatesCollector(host);

                #region Write three address code for debugging
                TACWriter.WriteTAC(inputAssemblies);
                #endregion

                #region Look for references (used in mixed memory model)
                if (Settings.MemoryModel == ProgramOptions.MemoryModelOption.Mixed)
                {
                    ReferenceFinder.TraverseForFields(inputAssemblies);
                }
                #endregion

                #region Translate defined types and add axioms about subtyping
                TypeDefinitionTranslator.TranslateTypes(inputAssemblies);
                #endregion

                #region Translate defined methods
                MethodTranslator.TranslateAssemblies(inputAssemblies, CHAnalysis);
                #endregion

                #region Create main wrapper with static fields initialization and static constructors calls
                StaticInitializer.SearchStaticConstructorsAndMain(inputAssemblies);
                streamWriter.WriteLine(StaticInitializer.CreateInitializeGlobals());
                streamWriter.WriteLine(StaticInitializer.CreateMainWrappers());
                streamWriter.WriteLine(StaticInitializer.CreateStaticVariablesAllocProcedure());
                streamWriter.WriteLine(StaticInitializer.CreateDefaultValuesStaticVariablesProcedure());
                streamWriter.WriteLine(StaticInitializer.CreateStaticConstructorsCallsProcedure());
                #endregion

                #region Translate types that are referenced but not defined in the input assemblies
                TypeDefinitionTranslator.DefineUndeclaredSuperClasses();
                TypeDefinitionTranslator.ParametricTypeDeclarations();
                #endregion

                #region Translate string constants
                BoogieLiteral.Strings.WriteStringConsts(streamWriter);
                #endregion

                #region Translate delegates
                streamWriter.WriteLine(DelegateStore.DefineMethodsIdentifiers());
                streamWriter.WriteLine(DelegateStore.CreateDelegateMethod());
                streamWriter.WriteLine(DelegateStore.InvokeDelegateMethod());
                #endregion

                // CreateAllAsyncMethods(streamWriter);
                #region Heuristic to catch getters & setters. If they are in our input assemblies we generate a body using a field associated to that property
                IEnumerable <IMethodReference> usedProperties = new List <IMethodReference>();
                if (Settings.StubGettersSetters || Settings.StubGettersSettersWhitelist.Count > 0)
                {
                    GetterSetterStub getterSetterStub = new GetterSetterStub();
                    usedProperties = getterSetterStub.Stub(inputAssemblies, streamWriter);
                }
                #endregion

                #region Generate stubs for async methods
                if (Settings.AsyncSupport)
                {
                    AsyncStubs asyncStubs = new AsyncStubs(inputAssemblies);
                    streamWriter.WriteLine(asyncStubs.AsyncMethodBuilderStartStub(false));
                    streamWriter.WriteLine(asyncStubs.AsyncStubsScheduleTask(false));
                }

                if (Settings.AsyncSupportGenerics)
                {
                    AsyncStubs asyncStubs = new AsyncStubs(inputAssemblies);
                    streamWriter.WriteLine(asyncStubs.AsyncMethodBuilderStartStub(true));
                    streamWriter.WriteLine(asyncStubs.AsyncStubsScheduleTask(true));
                }

                if (!Settings.AsyncSupport && Settings.AsyncSupportGenerics)
                {
                    // this is only in AsyncSupport prelude
                    // we can't add it to AsyncSupportGenerics because we are not always sure there will be all defined types and functions

                    bool hasEventually = inputAssemblies.GetAllDefinedMethods().Any(m => m.Name.Value.Equals("Eventually"));
                    if (hasEventually)
                    {
                        AsyncStubs asyncStubs = new AsyncStubs(inputAssemblies);
                        streamWriter.WriteLine(asyncStubs.EventuallyStub());
                    }
                }

                #endregion

                streamWriter.WriteLine(StringTranslator.Stubs());

                #region Translate called methods as extern (bodyless methods or methods not present in our input assemblies)

                var externMethods = InstructionTranslator.CalledMethods.Except(inputAssemblies.GetAllDefinedMethods().Where(m => m.Body.Size > 0)).Except(usedProperties);
                externMethods = externMethods.Where(m => !StringTranslator.GetBoogieNamesForStubs().Contains(BoogieMethod.From(m).Name));
                foreach (var methodRef in externMethods)
                {
                    var head = Helpers.GetExternalMethodDefinition(Helpers.GetUnspecializedVersion(methodRef));
                    streamWriter.WriteLine(head);
                }

                #endregion

                #region Translate class fields
                // we declare read or written fields
                foreach (var field in FieldTranslator.GetFieldDefinitions())
                {
                    streamWriter.WriteLine(field);
                }
                #endregion

                streamWriter.Close();

                #region Append bpl input files
                foreach (var bplInputFile in Settings.BplInputFiles)
                {
                    var output = new FileStream(outputPath, FileMode.Append, FileAccess.Write);

                    using (var inputStream = File.OpenRead(bplInputFile))
                    {
                        inputStream.CopyTo(output);
                    }

                    output.Close();
                }
                #endregion
            }
        }
Example #9
0
        /// <summary>
        /// Constructs a new course object.
        /// </summary>
        /// <param name="name">The name of the course.</param>
        /// <param name="credits">The credit value of the course.</param>
        /// <param name="groups">An array containing the level groups of the course.</param>
        /// <param name="scoreTable">The table that maps scores to GPA values.</param>
        public StaticCourse(string name, double credits, LevelGroup[] groups, ScoreTable scoreTable)
        {
            if (name == null)
                throw new ArgumentNullException("name");
            if (credits <= 0)
                throw new ArgumentOutOfRangeException("credits");
            if (groups == null)
                throw new ArgumentNullException("groups");
            if (groups.Length == 0)
                throw new ArgumentException("Must provide at least one level group");
            if (scoreTable == null)
                throw new ArgumentNullException("scoreTable");
            _name = name;
            _credits = credits;
            _groups = groups;
            _scoreTable = scoreTable;

            LevelGroup group = groups[0];
            _selectedLevelGroup = group;
            _selectedLevel = group.LevelCount > 0 ? group[0] : null;

            NameTranslator = x => x;
        }