/// <summary> /// PR_LeaveFunction /// </summary> private int LeaveFunction() { if (this._Depth <= 0) { Utilities.Error("prog stack underflow"); } // restore locals from the stack var c = this.xFunction.locals; this._LocalStackUsed -= c; if (this._LocalStackUsed < 0) { this.RunError("PR_ExecuteProgram: locals stack underflow\n"); } for (var i = 0; i < c; i++) { this.Set(this.xFunction.parm_start + i, this._LocalStack[this._LocalStackUsed + i]); } //((int*)pr_globals)[pr_xfunction->parm_start + i] = localstack[localstack_used + i]; // up stack this._Depth--; this.xFunction = this._Stack[this._Depth].f; return(this._Stack[this._Depth].s); }
/// <summary> /// PR_LeaveFunction /// </summary> private Int32 LeaveFunction() { if (_Depth <= 0) { Utilities.Error("prog stack underflow"); } // restore locals from the stack var c = xFunction.locals; _LocalStackUsed -= c; if (_LocalStackUsed < 0) { RunError("PR_ExecuteProgram: locals stack underflow\n"); } for (var i = 0; i < c; i++) { Set(xFunction.parm_start + i, _LocalStack[_LocalStackUsed + i]); //((int*)pr_globals)[pr_xfunction->parm_start + i] = localstack[localstack_used + i]; } // up stack _Depth--; xFunction = _Stack[_Depth].f; return(_Stack[_Depth].s); }
public void TestFunctionSignature_F() { ProgramFile programFile = new ProgramFile("path", "name", "text"); ProgramClassTypeCollection expectedClassTypeCollection = new ProgramClassTypeCollection(); ProgramClassTypeCollection actualClassTypeCollection = new ProgramClassTypeCollection(); CodeProcessor codeProcessor = new CodeProcessor(programFile, actualClassTypeCollection); ProgramClass expectedProgramClass; ProgramClass actualProgramClass; ProgramFunction expectedProgramFunction; ProgramFunction actualProgramFunction; string[] fileTextDataArray = { "class", "ClassName", " ", "{", " ", "public", "virtual", "(", "List", "<", "int", ">", ",", "bool", ",", "float",")", "Test", "<", "Object", ">", "(", "double", "n", ",", "double", "m", ")", " ", "{", " ", "return", "(", "0", ",", "0",")", ";", " ", "}", " ", "}" }; programFile.FileTextData.AddRange(fileTextDataArray); string name = "Test"; List <string> empty = new List <string>(); List <string> ModF = new List <string>(); List <string> RetF = new List <string>(); List <string> GenF = new List <string>(); List <string> ParF = new List <string>(); ModF.Add("public"); ModF.Add("virtual"); RetF.Add("List"); RetF.Add("<"); RetF.Add("int"); RetF.Add(">"); RetF.Add(","); RetF.Add("bool"); RetF.Add(","); RetF.Add("float"); GenF.Add("Object"); ParF.Add("double"); ParF.Add("n"); ParF.Add(","); ParF.Add("double"); ParF.Add("m"); expectedProgramClass = new ProgramClass("ClassName", empty, empty); expectedProgramFunction = new ProgramFunction(name, ModF, RetF, GenF, ParF, empty); expectedProgramClass.ChildList.Add(expectedProgramFunction); expectedClassTypeCollection.Add(expectedProgramClass); codeProcessor.ProcessFileCode(); CollectionAssert.AreEqual(expectedClassTypeCollection, actualClassTypeCollection); actualProgramClass = (ProgramClass)actualClassTypeCollection[0]; Assert.AreEqual(expectedProgramClass.ChildList.Count, actualProgramClass.ChildList.Count); actualProgramFunction = (ProgramFunction)actualProgramClass.ChildList[0]; Assert.AreEqual(expectedProgramFunction.Name, actualProgramFunction.Name); CollectionAssert.AreEqual(expectedProgramFunction.Modifiers, actualProgramFunction.Modifiers); CollectionAssert.AreEqual(expectedProgramFunction.ReturnTypes, actualProgramFunction.ReturnTypes); CollectionAssert.AreEqual(expectedProgramFunction.Generics, actualProgramFunction.Generics); CollectionAssert.AreEqual(expectedProgramFunction.Parameters, actualProgramFunction.Parameters); }
public void TestFunctionSignature_B() { ProgramFile programFile = new ProgramFile("path", "name", "text"); ProgramClassTypeCollection expectedClassTypeCollection = new ProgramClassTypeCollection(); ProgramClassTypeCollection actualClassTypeCollection = new ProgramClassTypeCollection(); CodeProcessor codeProcessor = new CodeProcessor(programFile, actualClassTypeCollection); ProgramClass expectedProgramClass; ProgramClass actualProgramClass; ProgramFunction expectedProgramFunction; ProgramFunction actualProgramFunction; string[] fileTextDataArray = { "class", "ClassName", " ", "{", " ", "void", "Test", "<", "V", ",", "W", ">", "(", "int", "x", ")", " ", "{"," ","return", "(", "0", ",", "0", ")", ";", " ", "}", " ", "}" }; programFile.FileTextData.AddRange(fileTextDataArray); string name = "Test"; List <string> empty = new List <string>(); List <string> RetB = new List <string>(); List <string> GenB = new List <string>(); List <string> ParB = new List <string>(); RetB.Add("void"); GenB.Add("V"); GenB.Add(","); GenB.Add("W"); ParB.Add("int"); ParB.Add("x"); expectedProgramClass = new ProgramClass("ClassName", empty, empty); expectedProgramFunction = new ProgramFunction(name, empty, RetB, GenB, ParB, empty); expectedProgramClass.ChildList.Add(expectedProgramFunction); expectedClassTypeCollection.Add(expectedProgramClass); codeProcessor.ProcessFileCode(); CollectionAssert.AreEqual(expectedClassTypeCollection, actualClassTypeCollection); actualProgramClass = (ProgramClass)actualClassTypeCollection[0]; Assert.AreEqual(expectedProgramClass.ChildList.Count, actualProgramClass.ChildList.Count); actualProgramFunction = (ProgramFunction)actualProgramClass.ChildList[0]; Assert.AreEqual(expectedProgramFunction.Name, actualProgramFunction.Name); CollectionAssert.AreEqual(expectedProgramFunction.Modifiers, actualProgramFunction.Modifiers); CollectionAssert.AreEqual(expectedProgramFunction.ReturnTypes, actualProgramFunction.ReturnTypes); CollectionAssert.AreEqual(expectedProgramFunction.Generics, actualProgramFunction.Generics); CollectionAssert.AreEqual(expectedProgramFunction.Parameters, actualProgramFunction.Parameters); }
public void TestFunctionSignature_O() { ProgramFile programFile = new ProgramFile("path", "name", "text"); ProgramClassTypeCollection expectedClassTypeCollection = new ProgramClassTypeCollection(); ProgramClassTypeCollection actualClassTypeCollection = new ProgramClassTypeCollection(); CodeProcessor codeProcessor = new CodeProcessor(programFile, actualClassTypeCollection); ProgramClass expectedProgramClass; ProgramClass actualProgramClass; ProgramFunction expectedProgramFunction; ProgramFunction actualProgramFunction; string[] fileTextDataArray = { "class", "ClassName", " ", "{", " ", "public", "static", "Test", ".", "NewType", "TestFunc", "(", ")", " ", "{"," ", "return", "(", "0", ",", "0", ")", ";", " ", "}", " ", "}" }; programFile.FileTextData.AddRange(fileTextDataArray); string name = "TestFunc"; List <string> empty = new List <string>(); List <string> ModO = new List <string>(); List <string> RetO = new List <string>(); ModO.Add("public"); ModO.Add("static"); RetO.Add("Test"); RetO.Add("."); RetO.Add("NewType"); expectedProgramClass = new ProgramClass("ClassName", empty, empty); expectedProgramFunction = new ProgramFunction(name, ModO, RetO, empty, empty, empty); expectedProgramClass.ChildList.Add(expectedProgramFunction); expectedClassTypeCollection.Add(expectedProgramClass); codeProcessor.ProcessFileCode(); CollectionAssert.AreEqual(expectedClassTypeCollection, actualClassTypeCollection); actualProgramClass = (ProgramClass)actualClassTypeCollection[0]; Assert.AreEqual(expectedProgramClass.ChildList.Count, actualProgramClass.ChildList.Count); actualProgramFunction = (ProgramFunction)actualProgramClass.ChildList[0]; Assert.AreEqual(expectedProgramFunction.Name, actualProgramFunction.Name); CollectionAssert.AreEqual(expectedProgramFunction.Modifiers, actualProgramFunction.Modifiers); CollectionAssert.AreEqual(expectedProgramFunction.ReturnTypes, actualProgramFunction.ReturnTypes); CollectionAssert.AreEqual(expectedProgramFunction.Generics, actualProgramFunction.Generics); CollectionAssert.AreEqual(expectedProgramFunction.Parameters, actualProgramFunction.Parameters); }
/// <summary> /// PR_EnterFunction /// Returns the new program statement counter /// </summary> private unsafe int EnterFunction(ProgramFunction f) { this._Stack[this._Depth].s = this._xStatement; this._Stack[this._Depth].f = this.xFunction; this._Depth++; if (this._Depth >= Programs.MAX_STACK_DEPTH) { this.RunError("stack overflow"); } // save off any locals that the new function steps on var c = f.locals; if (this._LocalStackUsed + c > Programs.LOCALSTACK_SIZE) { this.RunError("PR_ExecuteProgram: locals stack overflow\n"); } for (var i = 0; i < c; i++) { this._LocalStack[this._LocalStackUsed + i] = *( int * )this.Get(f.parm_start + i); } this._LocalStackUsed += c; // copy parameters var o = f.parm_start; for (var i = 0; i < f.numparms; i++) { for (var j = 0; j < f.parm_size[i]; j++) { this.Set(o, *( int * )this.Get(ProgramOperatorDef.OFS_PARM0 + i * 3 + j)); o++; } } this.xFunction = f; return(f.first_statement - 1); // offset the s++ }
/// <summary> /// PR_EnterFunction /// Returns the new program statement counter /// </summary> private unsafe Int32 EnterFunction(ProgramFunction f) { _Stack[_Depth].s = _xStatement; _Stack[_Depth].f = xFunction; _Depth++; if (_Depth >= MAX_STACK_DEPTH) { RunError("stack overflow"); } // save off any locals that the new function steps on var c = f.locals; if (_LocalStackUsed + c > LOCALSTACK_SIZE) { RunError("PR_ExecuteProgram: locals stack overflow\n"); } for (var i = 0; i < c; i++) { _LocalStack[_LocalStackUsed + i] = *( Int32 * )Get(f.parm_start + i); } _LocalStackUsed += c; // copy parameters var o = f.parm_start; for (var i = 0; i < f.numparms; i++) { for (var j = 0; j < f.parm_size[i]; j++) { Set(o, *( Int32 * )Get(ProgramOperatorDef.OFS_PARM0 + i * 3 + j)); o++; } } xFunction = f; return(f.first_statement - 1); // offset the s++ }
public void TestCodeProcessor_ProcessFileCode_FunctionData() { ProgramClassTypeCollection programClassTypeCollection = new ProgramClassTypeCollection(); CodeProcessor codeProcessor; FileProcessor fileProcessor; ProgramFile programFile; List <ProgramFunction> expectedFunctions = new List <ProgramFunction>(); List <string> repeatedFunctionNames = new List <string>(); List <string> empty = new List <string>(); string filePath = Path.GetFullPath("..\\..\\..\\CodeAnalyzerTests\\TestInputFiles\\TestInputFile.cs"); string fileName = "TestInputFile.cs"; string fileText = ""; if (File.Exists(filePath)) { fileText = File.ReadAllText(filePath); } repeatedFunctionNames.Add("Talk"); repeatedFunctionNames.Add("Move"); ProgramFunction Animal = new ProgramFunction("Animal", empty, empty, empty, empty, empty); ProgramFunction Animal_Move = new ProgramFunction("Move", empty, empty, empty, empty, empty); ProgramFunction Pet = new ProgramFunction("Pet", empty, empty, empty, empty, empty); ProgramFunction Dog = new ProgramFunction("Dog", empty, empty, empty, empty, empty); ProgramFunction Dog_Talk = new ProgramFunction("Talk", empty, empty, empty, empty, empty); ProgramFunction Human = new ProgramFunction("Human", empty, empty, empty, empty, empty); ProgramFunction Human_Talk = new ProgramFunction("Talk", empty, empty, empty, empty, empty); ProgramFunction Human_Move = new ProgramFunction("Move", empty, empty, empty, empty, empty); ProgramFunction GoToSchool = new ProgramFunction("GoToSchool", empty, empty, empty, empty, empty); ProgramFunction GraduateSchool = new ProgramFunction("GraduateSchool", empty, empty, empty, empty, empty); ProgramFunction GoToWork = new ProgramFunction("GoToWork", empty, empty, empty, empty, empty); ProgramFunction BuyPet = new ProgramFunction("BuyPet", empty, empty, empty, empty, empty); ProgramFunction BuyDog = new ProgramFunction("BuyDog", empty, empty, empty, empty, empty); ProgramFunction BuyCar = new ProgramFunction("BuyCar", empty, empty, empty, empty, empty); ProgramFunction SellCar = new ProgramFunction("SellCar", empty, empty, empty, empty, empty); ProgramFunction FillCarFuelTank = new ProgramFunction("FillCarFuelTank", empty, empty, empty, empty, empty); ProgramFunction Car = new ProgramFunction("Car", empty, empty, empty, empty, empty); ProgramFunction FillTank = new ProgramFunction("FillTank", empty, empty, empty, empty, empty); string[] Animal_Move_TextDataArray = { " ", "if", "(", "direction", "==", "0", ")", "//", "move", "north", " ", "LocationY", "+=", "seconds", "*", "Speed", ";", " ", "else", "if", "(", "direction", "==", "1", ")", "//", "move", "east", " ", "LocationX", "+=", "seconds", "*", "Speed", ";", " ", "else", "if", "(", "direction", "==", "2", ")", "//", "move", "south", " ", "LocationY", "-=", "seconds", "*", "Speed", ";", " ", "else", "if", "(", "direction", "==", "3", ")", "//", "move", "west", " ", "LocationX", "-=", "seconds", "*", "Speed", ";", " ", "return", "(", "LocationX", ",", "LocationY", ")", ";", " ", "}" }; string[] Human_Move_TextDataArray = { " ", "int", "speed", "=", "Speed", ";", " ", "if", "(", "isDriving", "&&", "car", "!=", "null", ")", "speed", "=", "car", ".", "Speed", ";", " ", "if", "(", "direction", "==", "0", ")", "//", "move", "north", " ", "LocationY", "+=", "seconds", "*", "speed", ";", " ", "else", "if", "(", "direction", "==", "1", ")", "//", "move", "east", " ", "LocationX", "+=", "seconds", "*", "speed", ";", " ", "else", "if", "(", "direction","==", "2", ")", "//", "move", "south", " ", "LocationY", "-=", "seconds", "*", "speed", ";", " ", "else", "if", "(", "direction", "==", "3", ")", "//", "move", "west", " ", "LocationX", "-=", "seconds", "*", "speed", ";", " ", "return", "(", "LocationX", ",", "LocationY", ")", ";", " ", "}" }; string[] Dog_Talk_TextDataArray = { "\"", "Woof", "!", "\"", ";" }; string[] Human_Talk_TextDataArray = { "\"", "Hello", "\"", ";" }; Animal_Move.TextData.AddRange(Animal_Move_TextDataArray); Dog_Talk.TextData.AddRange(Dog_Talk_TextDataArray); Human_Talk.TextData.AddRange(Human_Talk_TextDataArray); Human_Move.TextData.AddRange(Human_Move_TextDataArray); Animal.Size = 3; Animal.Complexity = 0; Animal_Move.Size = 9; Animal_Move.Complexity = 4; Pet.Size = 1; Pet.Complexity = 0; Dog.Size = 1; Dog.Complexity = 0; Dog_Talk.Size = 1; Dog_Talk.Complexity = 0; Human.Size = 2; Human.Complexity = 0; Human_Talk.Size = 1; Human_Talk.Complexity = 0; Human_Move.Size = 11; Human_Move.Complexity = 5; GoToSchool.Size = 6; GoToSchool.Complexity = 1; GraduateSchool.Size = 5; GraduateSchool.Complexity = 1; GoToWork.Size = 4; GoToWork.Complexity = 1; BuyPet.Size = 7; BuyPet.Complexity = 1; BuyDog.Size = 4; BuyDog.Complexity = 1; BuyCar.Size = 8; BuyCar.Complexity = 1; SellCar.Size = 5; SellCar.Complexity = 1; FillCarFuelTank.Size = 8; FillCarFuelTank.Complexity = 2; Car.Size = 5; Car.Complexity = 0; FillTank.Size = 7; FillTank.Complexity = 1; expectedFunctions.Add(Animal); expectedFunctions.Add(Animal_Move); expectedFunctions.Add(Pet); expectedFunctions.Add(Dog); expectedFunctions.Add(Dog_Talk); expectedFunctions.Add(Human); expectedFunctions.Add(Human_Talk); expectedFunctions.Add(Human_Move); expectedFunctions.Add(GoToSchool); expectedFunctions.Add(GraduateSchool); expectedFunctions.Add(GoToWork); expectedFunctions.Add(BuyPet); expectedFunctions.Add(BuyDog); expectedFunctions.Add(BuyCar); expectedFunctions.Add(SellCar); expectedFunctions.Add(FillCarFuelTank); expectedFunctions.Add(Car); expectedFunctions.Add(FillTank); programFile = new ProgramFile(filePath, fileName, fileText); fileProcessor = new FileProcessor(programFile); fileProcessor.ProcessFile(); codeProcessor = new CodeProcessor(programFile, programClassTypeCollection); codeProcessor.ProcessFileCode(); CheckAllChildListsFunctionData(expectedFunctions, repeatedFunctionNames, programFile); }