public virtual void Visit(InvokeStatement stmt) { if (stmt.InvokeExp != null) { stmt.InvokeExp.AcceptVisitor(this); } }
public override void Visit(InvokeStatement stmt) { cb.WriteIndent(); base.Visit(stmt); cb.Write(';'); cb.WriteLine(); }
public override void Visit(InvokeStatement stmt) { if (stmt.InvokeExp != null) { cb.WriteIndent(); stmt.InvokeExp.AcceptVisitor(this); cb.Write(";"); cb.WriteLine(); } }
private string EmitInvokeConstructor(InvokeStatement invoke, List <Type> sourceTypes, Type type, string theAssembly) { string r = ""; int i; string paramList = ""; Type[] types = new Type[sourceTypes.Count]; for (i = 0; i < sourceTypes.Count; i++) { types[i] = sourceTypes[i]; if (paramList.Length > 0) { paramList += ","; } paramList += ILType(sourceTypes[i].FullName); } ConstructorInfo constructor = type.GetConstructor(types); if (constructor == null) { Console.WriteLine("Could not find constuctor with matching types for " + type.FullName + " in " + theAssembly); } if (invoke.Returning != null) { r += " " + ILAddress(1) + "ldarg.0\n"; } i = 0; ParameterInfo[] parameters = constructor.GetParameters(); foreach (Source source in invoke.Using) { ParameterInfo p = parameters[i] as ParameterInfo; bool boxThisParam = true; if (p.ParameterType.ToString().Equals(types[i].ToString())) { boxThisParam = false; } r += EmitLoadSource(source, source.ByReference, boxThisParam); i++; } r += " " + ILAddress(5); r += "newobj instance void class [" + theAssembly + "]" + type + "::.ctor(" + paramList + ")"; r += "\n"; if (invoke.Returning != null) { r += EmitStore(invoke.Returning); } return(r); }
/// <summary> /// Construeix les instruccions coresponents a una accio. /// </summary> /// <param name="action">La accio.</param> /// <returns>La llista d'instruccions.</returns> /// private StatementList MakeActionStatements(Model.Action action) { if (action.Activities == null) { return(null); } else { StatementList statements = new StatementList(); foreach (var activity in action.Activities) { if (activity is RunActivity callActivity) { Statement statement = new InvokeStatement( new InvokeExpression( new IdentifierExpression(String.Format("owner->do{0}", callActivity.ProcessName)))); statements.Add(statement); } } return(statements); } }
private static IToken BuildCodeElementFromType(CodeElementType type, Token lastTokenBeforeError, string informationText) { CodeElement codeElement = null; switch (type) { case CodeElementType.ProgramIdentification: codeElement = new ProgramIdentification(); break; case CodeElementType.ProgramEnd: codeElement = new ProgramEnd(); break; case CodeElementType.ClassIdentification: codeElement = new ClassIdentification(); break; case CodeElementType.ClassEnd: codeElement = new ClassEnd(); break; case CodeElementType.FactoryIdentification: codeElement = new FactoryIdentification(); break; case CodeElementType.FactoryEnd: codeElement = new FactoryEnd(); break; case CodeElementType.ObjectIdentification: codeElement = new ObjectIdentification(); break; case CodeElementType.ObjectEnd: codeElement = new ObjectEnd(); break; case CodeElementType.MethodIdentification: codeElement = new MethodIdentification(); break; case CodeElementType.MethodEnd: codeElement = new MethodEnd(); break; case CodeElementType.EnvironmentDivisionHeader: codeElement = new EnvironmentDivisionHeader(); break; case CodeElementType.DataDivisionHeader: codeElement = new DataDivisionHeader(); break; case CodeElementType.ProcedureDivisionHeader: codeElement = new ProcedureDivisionHeader(); break; case CodeElementType.DeclarativesHeader: codeElement = new DeclarativesHeader(); break; case CodeElementType.DeclarativesEnd: codeElement = new DeclarativesEnd(); break; case CodeElementType.SectionHeader: codeElement = new SectionHeader(); break; case CodeElementType.ConfigurationSectionHeader: codeElement = new ConfigurationSectionHeader(); break; case CodeElementType.InputOutputSectionHeader: codeElement = new InputOutputSectionHeader(); break; case CodeElementType.FileSectionHeader: codeElement = new FileSectionHeader(); break; case CodeElementType.WorkingStorageSectionHeader: codeElement = new WorkingStorageSectionHeader(); break; case CodeElementType.LocalStorageSectionHeader: codeElement = new LocalStorageSectionHeader(); break; case CodeElementType.LinkageSectionHeader: codeElement = new LinkageSectionHeader(); break; case CodeElementType.ParagraphHeader: codeElement = new ParagraphHeader(); break; case CodeElementType.FileControlParagraphHeader: codeElement = new FileControlParagraphHeader(); break; case CodeElementType.IOControlParagraphHeader: codeElement = new IOControlParagraphHeader(); break; case CodeElementType.SentenceEnd: codeElement = new SentenceEnd(); break; case CodeElementType.FileDescriptionEntry: codeElement = new FileDescriptionEntry(); break; case CodeElementType.DataDescriptionEntry: codeElement = new DataDescriptionEntry(); break; case CodeElementType.DataRedefinesEntry: codeElement = new DataRedefinesEntry(); break; case CodeElementType.DataRenamesEntry: codeElement = new DataRenamesEntry(); break; case CodeElementType.DataConditionEntry: codeElement = new DataConditionEntry(); break; case CodeElementType.FileControlEntry: codeElement = new FileControlEntry(); break; case CodeElementType.IOControlEntry: codeElement = new RerunIOControlEntry(); break; case CodeElementType.SourceComputerParagraph: codeElement = new SourceComputerParagraph(); break; case CodeElementType.ObjectComputerParagraph: codeElement = new ObjectComputerParagraph(); break; case CodeElementType.SpecialNamesParagraph: codeElement = new SpecialNamesParagraph(); break; case CodeElementType.RepositoryParagraph: codeElement = new RepositoryParagraph(); break; case CodeElementType.AcceptStatement: codeElement = new AcceptFromInputDeviceStatement(); break; case CodeElementType.AddStatement: codeElement = new AddSimpleStatement(); break; case CodeElementType.AlterStatement: codeElement = new AlterStatement(); break; case CodeElementType.CallStatement: codeElement = new CallStatement(); break; case CodeElementType.CancelStatement: codeElement = new CancelStatement(); break; case CodeElementType.CloseStatement: codeElement = new CloseStatement(); break; case CodeElementType.ComputeStatement: codeElement = new ComputeStatement(); break; case CodeElementType.ContinueStatement: codeElement = new ContinueStatement(); break; case CodeElementType.DeleteStatement: codeElement = new DeleteStatement(); break; case CodeElementType.DisplayStatement: codeElement = new DisplayStatement(); break; case CodeElementType.DivideStatement: codeElement = new DivideSimpleStatement(); break; case CodeElementType.EntryStatement: codeElement = new EntryStatement(); break; case CodeElementType.EvaluateStatement: codeElement = new EvaluateStatement(); break; case CodeElementType.ExecStatement: codeElement = new ExecStatement(); break; case CodeElementType.ExitMethodStatement: codeElement = new ExitMethodStatement(); break; case CodeElementType.ExitProgramStatement: codeElement = new ExitProgramStatement(); break; case CodeElementType.ExitStatement: codeElement = new ExitStatement(); break; case CodeElementType.GobackStatement: codeElement = new GobackStatement(); break; case CodeElementType.GotoStatement: codeElement = new GotoSimpleStatement(); break; case CodeElementType.IfStatement: codeElement = new IfStatement(); break; case CodeElementType.InitializeStatement: codeElement = new InitializeStatement(); break; case CodeElementType.InspectStatement: codeElement = new InspectTallyingStatement(); break; case CodeElementType.InvokeStatement: codeElement = new InvokeStatement(); break; case CodeElementType.MergeStatement: codeElement = new MergeStatement(); break; case CodeElementType.MoveStatement: codeElement = new MoveSimpleStatement(null, null, null); break; case CodeElementType.MultiplyStatement: codeElement = new MultiplySimpleStatement(); break; case CodeElementType.NextSentenceStatement: codeElement = new NextSentenceStatement(); break; case CodeElementType.OpenStatement: codeElement = new OpenStatement(); break; case CodeElementType.PerformProcedureStatement: codeElement = new PerformProcedureStatement(); break; case CodeElementType.PerformStatement: codeElement = new PerformStatement(); break; case CodeElementType.ReadStatement: codeElement = new ReadStatement(); break; case CodeElementType.ReleaseStatement: codeElement = new ReleaseStatement(); break; case CodeElementType.ReturnStatement: codeElement = new ReturnStatement(); break; case CodeElementType.RewriteStatement: codeElement = new RewriteStatement(); break; case CodeElementType.SearchStatement: codeElement = new SearchSerialStatement(); break; case CodeElementType.SetStatement: codeElement = new SetStatementForAssignment(); break; case CodeElementType.SortStatement: codeElement = new SortStatement(); break; case CodeElementType.StartStatement: codeElement = new StartStatement(); break; case CodeElementType.StopStatement: codeElement = new StopStatement(); break; case CodeElementType.StringStatement: codeElement = new StringStatement(); break; case CodeElementType.SubtractStatement: codeElement = new SubtractSimpleStatement(); break; case CodeElementType.UnstringStatement: codeElement = new UnstringStatement(); break; case CodeElementType.UseStatement: codeElement = new UseAfterIOExceptionStatement(); break; case CodeElementType.WriteStatement: codeElement = new WriteStatement(); break; case CodeElementType.XmlGenerateStatement: codeElement = new XmlGenerateStatement(); break; case CodeElementType.XmlParseStatement: codeElement = new XmlParseStatement(); break; case CodeElementType.AtEndCondition: codeElement = new AtEndCondition(); break; case CodeElementType.NotAtEndCondition: codeElement = new NotAtEndCondition(); break; case CodeElementType.AtEndOfPageCondition: codeElement = new AtEndOfPageCondition(); break; case CodeElementType.NotAtEndOfPageCondition: codeElement = new NotAtEndOfPageCondition(); break; case CodeElementType.OnExceptionCondition: codeElement = new OnExceptionCondition(); break; case CodeElementType.NotOnExceptionCondition: codeElement = new NotOnExceptionCondition(); break; case CodeElementType.OnOverflowCondition: codeElement = new OnOverflowCondition(); break; case CodeElementType.NotOnOverflowCondition: codeElement = new NotOnOverflowCondition(); break; case CodeElementType.InvalidKeyCondition: codeElement = new InvalidKeyCondition(); break; case CodeElementType.NotInvalidKeyCondition: codeElement = new NotInvalidKeyCondition(); break; case CodeElementType.OnSizeErrorCondition: codeElement = new OnSizeErrorCondition(); break; case CodeElementType.NotOnSizeErrorCondition: codeElement = new NotOnSizeErrorCondition(); break; case CodeElementType.ElseCondition: codeElement = new ElseCondition(); break; case CodeElementType.WhenCondition: codeElement = new WhenCondition(); break; case CodeElementType.WhenOtherCondition: codeElement = new WhenOtherCondition(); break; case CodeElementType.WhenSearchCondition: codeElement = new WhenSearchCondition(); break; case CodeElementType.AddStatementEnd: codeElement = new AddStatementEnd(); break; case CodeElementType.CallStatementEnd: codeElement = new CallStatementEnd(); break; case CodeElementType.ComputeStatementEnd: codeElement = new ComputeStatementEnd(); break; case CodeElementType.DeleteStatementEnd: codeElement = new DeleteStatementEnd(); break; case CodeElementType.DivideStatementEnd: codeElement = new DivideStatementEnd(); break; case CodeElementType.EvaluateStatementEnd: codeElement = new EvaluateStatementEnd(); break; case CodeElementType.IfStatementEnd: codeElement = new IfStatementEnd(); break; case CodeElementType.InvokeStatementEnd: codeElement = new InvokeStatementEnd(); break; case CodeElementType.MultiplyStatementEnd: codeElement = new MultiplyStatementEnd(); break; case CodeElementType.PerformStatementEnd: codeElement = new PerformStatementEnd(); break; case CodeElementType.ReadStatementEnd: codeElement = new ReadStatementEnd(); break; case CodeElementType.ReturnStatementEnd: codeElement = new ReturnStatementEnd(); break; case CodeElementType.RewriteStatementEnd: codeElement = new RewriteStatementEnd(); break; case CodeElementType.SearchStatementEnd: codeElement = new SearchStatementEnd(); break; case CodeElementType.StartStatementEnd: codeElement = new StartStatementEnd(); break; case CodeElementType.StringStatementEnd: codeElement = new StringStatementEnd(); break; case CodeElementType.SubtractStatementEnd: codeElement = new SubtractStatementEnd(); break; case CodeElementType.UnstringStatementEnd: codeElement = new UnstringStatementEnd(); break; case CodeElementType.WriteStatementEnd: codeElement = new WriteStatementEnd(); break; case CodeElementType.XmlStatementEnd: codeElement = new XmlStatementEnd(); break; case CodeElementType.LibraryCopy: codeElement = new LibraryCopyCodeElement(); break; case CodeElementType.FunctionDeclarationHeader: codeElement = new FunctionDeclarationHeader(null, AccessModifier.Private, FunctionType.Undefined); break; case CodeElementType.FunctionDeclarationEnd: codeElement = new FunctionDeclarationEnd(); break; default: throw new NotImplementedException(); } if (lastTokenBeforeError != null) { var missingToken = new MissingToken(TokenType.InvalidToken, informationText, lastTokenBeforeError.TokensLine, lastTokenBeforeError.StopIndex); codeElement.ConsumedTokens.Add(missingToken); } return(codeElement); }
private string EmitInvokeStatement(InvokeStatement invoke) { string r = ""; //TODO: theAssembly should be set based on the CLASS definition for the object bool methodIsStatic = false; ClassDefinition classDef = null; //Console.WriteLine("Name = "+invoke.Object.Name); if (invoke.Object.Definition == null) { //It's a class rather than an object. //(eg Static) methodIsStatic = true; classDef = _program.ClassDeclarations[invoke.Object.Name] as ClassDefinition; //Console.WriteLine("Type: Class"); if (classDef == null) { //TODO: Exception //TODO: This should be done in contextual analyzer Console.WriteLine("Class not defined: " + invoke.Object.Name); } } else { classDef = invoke.Object.Definition.ClassDefinition; //Console.WriteLine("Type: Object"); } string theClass = classDef.NetName.Value; string theMethod = invoke.Method.Value; //Console.WriteLine("theClass = "+theClass); //Console.WriteLine("theMethod = "+theMethod); //Get a list of the types of parameters used in this call List <Type> sourceTypes = new List <Type>(); foreach (Source source in invoke.Using) { Type thisType; if (source.GetType() == typeof(Identifier)) { Identifier src = source as Identifier; if (src.Definition.IsClass) { //typeName = src.Definition.ClassDefinition.NetName.Value; thisType = src.Definition.ClassDefinition.Type; } else { thisType = GetType(src.Definition.Type); } } else { Literal lit = source as Literal; thisType = GetType(lit.Type); } sourceTypes.Add(thisType); //Console.WriteLine(" ParamType: "+thisType); } Type type = classDef.Type; string theAssembly = "mscorlib"; //The default theAssembly = classDef.CILAssemblyName; if (invoke.Method.Value.ToUpper() == "NEW") { r += EmitInvokeConstructor(invoke, sourceTypes, type, theAssembly); } else { r += EmitInvokeMethod(invoke, sourceTypes, type, theAssembly, methodIsStatic); } return(r); }
private string EmitInvokeMethod(InvokeStatement invoke, List <Type> sourceTypes, Type type, string theAssembly, bool methodIsStatic) { string r = ""; ParameterInfo[] parameters; PropertyInfo matchingProperty = null; MethodInfo bestMatchingMethod = null; string theMethod = invoke.Method.Value; Type[] types = new Type[sourceTypes.Count]; for (int i = 0; i < sourceTypes.Count; i++) { types[i] = sourceTypes[i]; //Console.WriteLine("Type: "+types[i]); } MethodInfo mi = type.GetMethod(theMethod, types); if (mi == null) { } else { bestMatchingMethod = mi; } if (invoke.Returning != null) { //Need a pointer to this for storing the result r += " " + ILAddress(1) + "ldarg.0\n"; } if (bestMatchingMethod == null) { PropertyInfo[] properties = type.GetProperties(); //Console.WriteLine("Looking at type: "+type.FullName); //Console.WriteLine("Looking for property: "+theMethod); foreach (PropertyInfo prop in properties) { //Console.WriteLine("Property: "+prop.Name); if (prop.Name == theMethod) { matchingProperty = prop; } } if (matchingProperty == null) { throw new Compiler.Exceptions.CompilerException("Could not find property or method '" + theMethod + "' with matching parameter types."); } //Test this with both static and non-static properties if (methodIsStatic) { r += " "; r += ILAddress(5); string returnType = ILType(matchingProperty.PropertyType.ToString()); r += "call " + returnType + " [" + theAssembly + "]" + type + "::get_" + theMethod + "()"; r += "\n"; } else { r += " " + ILAddress(1) + "ldarg.0\n"; r += EmitLoadField(invoke.Object, false, true); r += " " + ILAddress(5); string returnType = ILType(matchingProperty.PropertyType.ToString()); r += "callvirt instance " + returnType + " class [" + theAssembly + "]" + type + "::get_" + theMethod + "()"; r += "\n"; } } else { //Console.WriteLine("Method: "+theMethod); string parms = ""; parameters = bestMatchingMethod.GetParameters(); int i = 0; foreach (ParameterInfo p in parameters) { if (i > 0) { parms += ", "; } Type paramType = p.ParameterType; parms += ILType(paramType.ToString()); i++; } if (!methodIsStatic) { r += " " + ILAddress(1) + "ldarg.0\n"; r += EmitLoadField(invoke.Object, false, true); } i = 0; foreach (Source source in invoke.Using) { ParameterInfo p = parameters[i] as ParameterInfo; bool boxThisParam = true; //Console.WriteLine(" p="+p.ParameterType); //Console.WriteLine(" s="+(sourceTypes[i] as string)); if (p.ParameterType.ToString().Equals(sourceTypes[i].ToString())) { boxThisParam = false; } r += EmitLoadSource(source, source.ByReference, boxThisParam); i++; } //Test this with both static and non-static methods if (methodIsStatic) { r += " "; r += ILAddress(5); r += "call void [" + theAssembly + "]" + type + "::" + theMethod + "(" + parms + ")"; r += "\n"; } else { r += " " + ILAddress(5); string returnType = ILType(bestMatchingMethod.ReturnType.ToString()); r += "callvirt instance " + returnType + " [" + theAssembly + "]" + type + "::" + theMethod + "(" + parms + ")"; r += "\n"; } } if (invoke.Returning != null) { //Method's return value is used //TODO: If this is not used in the COBOL program, but the // method does have one, we need to remove it from // the stack. if (bestMatchingMethod != null && bestMatchingMethod.ReturnType != null) { r += EmitStore(invoke.Returning); } else if (matchingProperty != null && matchingProperty.PropertyType != null) { r += EmitStore(invoke.Returning); } else { //TODO: If the property/method has no return value, throw an exception } } return(r); }
public override void Visit(InvokeStatement stmt) { StartElement("callStatement"); stmt.InvokeExp.AcceptVisitor(this); EndElement(); }