llvm.org GIT mirror llvm / 9ef501b
Refactoring: extract method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50731 91177308-0d34-0410-b5e6-96231b3b80d8 Mikhail Glushenkov 11 years ago
1 changed file(s) with 58 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
945945 throw PropName + ": unknown edge property!";
946946 }
947947
948 // Helper function used by EmitEdgeClasses.
948 // Helper function used by EmitEdgeClass.
949949 void EmitEdgePropertyTest(const std::string& PropName,
950950 const DagInit& Prop,
951951 const GlobalOptionDescriptions& OptDescs,
956956 EmitEdgePropertyTest2Args(PropName, Prop, OptDescs, O);
957957 }
958958
959 // Emit Edge* classes that represent edges in the graph.
959 // Emit a single Edge* class.
960 void EmitEdgeClass(unsigned N, const std::string& Target,
961 ListInit* Props, const GlobalOptionDescriptions& OptDescs,
962 std::ostream& O) {
963 bool IsDefault = false;
964
965 // Class constructor.
966 O << "class Edge" << N << ": public Edge {\n"
967 << "public:\n"
968 << Indent1 << "Edge" << N << "() : Edge(\"" << Target
969 << "\") {}\n\n"
970
971 // Function isEnabled().
972 << Indent1 << "bool isEnabled() const {\n"
973 << Indent2 << "bool ret = false;\n";
974
975 for (size_t i = 0, PropsSize = Props->size(); i < PropsSize; ++i) {
976 const DagInit& Prop = dynamic_cast(*Props->getElement(i));
977 const std::string& PropName = Prop.getOperator()->getAsString();
978
979 if (PropName == "default")
980 IsDefault = true;
981
982 O << Indent2 << "if (ret || (";
983 if (PropName == "and") {
984 O << '(';
985 for (unsigned j = 0, NumArgs = Prop.getNumArgs(); j < NumArgs; ++j) {
986 const DagInit& InnerProp = dynamic_cast(*Prop.getArg(j));
987 const std::string& InnerPropName =
988 InnerProp.getOperator()->getAsString();
989 EmitEdgePropertyTest(InnerPropName, InnerProp, OptDescs, O);
990 if (j != NumArgs - 1)
991 O << ")\n" << Indent3 << " && (";
992 else
993 O << ')';
994 }
995 }
996 else {
997 EmitEdgePropertyTest(PropName, Prop, OptDescs, O);
998 }
999 O << "))\n" << Indent3 << "ret = true;\n";
1000 }
1001
1002 O << Indent2 << "return ret;\n"
1003 << Indent1 << "};\n\n"
1004
1005 // Function isDefault().
1006 << Indent1 << "bool isDefault() const { return ";
1007 if (IsDefault)
1008 O << "true";
1009 else
1010 O << "false";
1011 O <<"; }\n};\n\n";
1012 }
1013
1014 // Emit Edge* classes that represent graph edges.
9601015 void EmitEdgeClasses (Record* CompilationGraph,
9611016 const GlobalOptionDescriptions& OptDescs,
9621017 std::ostream& O) {
9701025 if (Props->empty())
9711026 continue;
9721027
973 O << "class Edge" << i << ": public Edge {\n"
974 << "public:\n"
975 << Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
976 << "\") {}\n\n"
977 << Indent1 << "bool isEnabled() const {\n"
978 << Indent2 << "bool ret = false;\n";
979
980 for (unsigned i = 0; i < Props->size(); ++i) {
981 const DagInit& Prop = dynamic_cast(*Props->getElement(i));
982 const std::string& PropName = Prop.getOperator()->getAsString();
983
984 O << Indent2 << "if (ret || (";
985 if (PropName == "and") {
986 const unsigned NumArgs = Prop.getNumArgs();
987 O << '(';
988 for (unsigned j = 0; j < NumArgs; ++j) {
989 const DagInit& InnerProp = dynamic_cast(*Prop.getArg(j));
990 const std::string& InnerPropName =
991 InnerProp.getOperator()->getAsString();
992 EmitEdgePropertyTest(InnerPropName, InnerProp, OptDescs, O);
993 if (j != NumArgs - 1)
994 O << ")\n" << Indent3 << " && (";
995 else
996 O << ')';
997 }
998 }
999 else {
1000 EmitEdgePropertyTest(PropName, Prop, OptDescs, O);
1001 }
1002 O << "))\n" << Indent3 << "ret = true;\n";
1003 }
1004
1005 O << Indent2 << "return ret;\n"
1006 << Indent1 << "};\n\n"
1007 << Indent1 << "bool isDefault() const { return false; }\n"
1008 << "};\n\n";
1028 EmitEdgeClass(i, B->getName(), Props, OptDescs, O);
10091029 }
10101030 }
10111031