private COOPClass calculateLowestMemberCoopClass(ParseNode o, COOPClass p) { if (!o.Equals("<member>")) { return(null); } if (!o.Contains("<member>")) { return(variablesToType[o.terminals]); } ParseNode ptr = o; COOPClass current = p; while (ptr.Contains("<member>")) { string memberName = ptr["<symbol>"].terminals; if (o.Contains("<function_call>")) { current = current.Functions[memberName].ReturnType; } else { current = current.VarNames[memberName]; } ptr = ptr["<member>"]; } return(current); }
private CallNode convertMember(CallNode parent, ParseNode m) { if (!m.Equals("<member>")) { return(null); } bool hasFunctionCall = m.Contains("<function_call>"), hasMember = m.Contains("<member>"); CallNode output; if (hasFunctionCall) { output = createObjectFunctionCall(parent, m["<symbol>"], m["<function_call>"]); } else { output = createSymbolNode(parent, m["<symbol>"]); } if (hasMember) { output = convertMember(output, m["<member>"]); } return(output); }
private SymbolNode createSymbolNode(CallNode parent, ParseNode s) { if (!s.Equals("<symbol>")) { return(null); } return(new SymbolNode(parent.type.VarNames[s.terminals], s.terminals)); }
private SymbolNode createSymbolNode(ParseNode s) { if (!s.Equals("<symbol>")) { return(null); } return(new SymbolNode(variablesToType[s.terminals], s.terminals)); }
private bool ContainsNode(ParseNode startNode, ParseNode nodeToFind) { if (startNode.Equals(nodeToFind)) { return(true); } return(startNode.GetChildren().Exists(x => ContainsNode(x, nodeToFind))); }
private static string ConvertJoinObjectToString(ParseNode p) { if (!p.Equals("<join_object>")) { throw new IncompatableParseNodeException(); } if (p.Contains("<join_info_full>")) { return($"({ConvertJoinInfoNodeToString(p[0])})({Parser.ConvertColumnsOneString(p["<columns>"])})"); } return($"{p["<table_name>"][0][0]}({Parser.ConvertColumnsOneString(p["<columns>"])})"); }
private static string ConvertJoinInfoNodeToString(ParseNode p) { if (!p.Equals("<join_info_full>")) { throw new IncompatableParseNodeException(); } string output = ""; output += ConvertJoinObjectToString(p[0]); output += p[1][0].Data; output += ConvertJoinObjectToString(p[2]); return(output); }
private ObjectFunctionCallNode createObjectFunctionCall(CallNode parent, ParseNode s, ParseNode f) { if (!s.Equals("<symbol>") || !f.Equals("<function_call>")) { return(null); } COOPClass type = getReturnTypeForFunction(parent.type, s.terminals); ObjectFunctionCallNode output = new ObjectFunctionCallNode( type, s.terminals, parent ); foreach (ParseNode node in Parser.ConvertListNodeToListOfListObjects(f["<list_object>"])) { output.parameters.Add(createCallNodeChain(node)); } return(output); }
private CallReturn calculateObject(ParseNode o) { if (!o.Equals("<object>")) { return(null); } CallChain c = new CallChain(originalNameAndInputTypesToMangledName, originalNameAndInputTypesToisStatic, functionToReturnType, availableClasses, variablesToType, isClassDict, parentClass, hierarchy); CallChain.CallNode n = c.createCallNodeChain(o); Console.WriteLine(n); COOPClass returnType = n.type; string fixedForC = c.fixForC(n); return(new CallReturn(fixedForC, returnType)); }
public CallNode createCallNodeChain(ParseNode o) { if (!o.Equals("<object>")) { return(null); } bool hasFunctionCall = o.Contains("<function_call>"), hasMember = o.Contains("<member>"), isStatic = hasFunctionCall && parentClass.Functions[o["<symbol>"].terminals].IsStatic; CallNode output; if (hasFunctionCall) { if (isStatic) { output = createStaticFunctionCall(o["<symbol>"], o["<function_call>"]); } else { output = createObjectFunctionCall(new ClassCallNode(parentClass), o["<symbol>"], o["<function_call>"]); } } else { output = createSymbolNode(o["<symbol>"]); } if (hasMember) { output = convertMember(output, o["<member>"]); } return(output); }
public CommandTable ConvertTable(ParseNode parseNode) { if (!parseNode.Equals("<table>")) { throw new IncompatableParseNodeException(); } Table tableOutput; if (parseNode["<list_selection>"] != null) { string[] selections, projections; ParseNode tableNode = parseNode["<table>"]; if (parseNode.Contains("<columns>")) { projections = ConvertColumns(parseNode["<columns>"]); } else { projections = new string[0]; } ParseNode[] selectionNodes = ConvertListNodeToListOfListObjects(parseNode["<list_selection>"]).ToArray(); selections = new string[selectionNodes.Length]; for (int i = 0; i < selectionNodes.Length; i++) { selections[i] = $"{selectionNodes[i][0][0].Data}={selectionNodes[i][1][0].Data}"; } if (tableNode.Contains("<join_info_full>")) { var tree = new AlgebraNodeTree(db, projections, selections, tableNode["<join_info_full>"]); tableOutput = tree.TableAply(); tree.PrintTree(); } else if (tableNode.Contains("<table>")) { Table t = ConvertTable(tableNode["<table>"]).Data as Table; var tree = new AlgebraNodeTree(t, projections, selections); tableOutput = tree.TableAply(); tree.PrintTree(); } else { var tree = new AlgebraNodeTree(db, projections, selections, tableNode["<string>"][0].Data); tableOutput = tree.TableAply(); tree.PrintTree(); } } else if (parseNode.Contains("<join_info_full>")) { var tree = new AlgebraNodeTree(db, new string[0], new string[0], parseNode["<join_info_full>"]); tableOutput = tree.TableAply(); tree.PrintTree(); } else { string tableInfo = parseNode["<string>"][0].Data; if (variables.ContainsKey(tableInfo)) { tableOutput = variables[tableInfo].Data as Table; if (tableOutput == null) { tableOutput = db[tableInfo]; } } else { tableOutput = db[tableInfo]; } } return(new CommandTable(tableOutput)); }