/* * Finds all function maps and combines into one function map. Looks for multiple main methods. * */ private static InstructionInvocation link(InstructionInvocation[] instructionInvocations) { InstructionInvocation firstInvocation = instructionInvocations[0]; CompliationUnitNode compliationUnitNode = (CompliationUnitNode)firstInvocation.InstructionList[0]; Dictionary <string, Node> functionNodeMap = new Dictionary <string, Node>(); //JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'putAll' method: functionNodeMap.putAll(firstInvocation.FunctionNodeMap); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: long oneMainFunction = functionNodeMap.Keys.stream().filter(f => "main".Equals(f)).count(); if (instructionInvocations.Length > 0) { for (int i = 1; i < instructionInvocations.Length; i++) { compliationUnitNode.Instructions.AddRange(instructionInvocations[i].InstructionList); //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: oneMainFunction += instructionInvocations[i].FunctionNodeMap.Keys.stream().filter(f => "main".Equals(f)).count(); //JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'putAll' method: functionNodeMap.putAll(instructionInvocations[i].FunctionNodeMap); } } if (oneMainFunction == 1) { IList <Node> inst = new List <Node>(); inst.Add(compliationUnitNode); return(new InstructionInvocation(inst, functionNodeMap)); } if (oneMainFunction > 1) { throw new Exception("Multiple main methods were found during linking"); } throw new Exception("No main functions were found during linking"); }
public override Node visitCompileUnit(JuliarParser.CompileUnitContext ctx) { CompliationUnitNode node = new CompliationUnitNode(); try { string nodeName = node.ToString(); callStack.Push(nodeName); symbolTable.addLevel(nodeName); new IterateOverContext(this, ctx, this, node); instructionList.Add(node); popScope(node.Type); //cfa.walkGraph(); //symbolTable.dumpSymbolTable(); } catch (Exception ex) { JuliarLogger.log(ex.Message); } return(node); }