MCPcopy Create free account
hub / github.com/GJDuck/e9patch / compare

Method compare

src/e9tool/e9action.cpp:1898–1952  ·  view source on GitHub ↗

* Value comparison. */

Source from the content-addressed store, hash-verified

1896 * Value comparison.
1897 */
1898int MatchVal::compare(const MatchVal &val) const
1899{
1900 if (val.type < type)
1901 return 1;
1902 if (val.type > type)
1903 return -1;
1904 switch (type)
1905 {
1906 case MATCH_TYPE_NIL:
1907 return 0;
1908 case MATCH_TYPE_INTEGER:
1909 return (val.i < i? 1:
1910 (val.i > i? -1: 0));
1911 case MATCH_TYPE_OPERAND:
1912 return (val.op < op? 1:
1913 (val.op > op? -1: 0));
1914 case MATCH_TYPE_ACCESS:
1915 return (val.access < access? 1:
1916 (val.access > access? -1: 0));
1917 case MATCH_TYPE_REGISTER:
1918 return (val.reg < reg? 1:
1919 (val.reg > reg? -1: 0));
1920 case MATCH_TYPE_MEMORY:
1921 if (val.mem.seg != mem.seg)
1922 return (val.mem.seg < mem.seg? 1: -1);
1923 if (val.mem.base != mem.base)
1924 return (val.mem.base < mem.base? 1: -1);
1925 if (val.mem.index != mem.index)
1926 return (val.mem.index < mem.index? 1: -1);
1927 if (val.mem.scale != mem.scale)
1928 return (val.mem.scale < mem.scale? 1: -1);
1929 if (val.mem.disp != mem.disp)
1930 return (val.mem.disp < mem.disp? 1: -1);
1931 if (val.mem.size != mem.size)
1932 return (val.mem.size < mem.size? 1: -1);
1933 return 0;
1934 case MATCH_TYPE_STRING:
1935 {
1936 int cmp = strcmp(str, val.str);
1937 return (cmp < 0? -1: (cmp > 0? 1: 0));
1938 }
1939 case MATCH_TYPE_REGEX:
1940 {
1941 std::string str1, str2;
1942 dumpVal(*this, str1);
1943 dumpVal(val, str2);
1944 error("regular exression values %s and %s cannot be compared",
1945 str1.c_str(), str2.c_str());
1946 }
1947 case MATCH_TYPE_SET:
1948 return setCompare(&val, this);
1949 default:
1950 error("unknown type (0x%x)", type);
1951 }
1952}
1953
1954/*
1955 * Get number of operands.

Callers 1

hasSuffixFunction · 0.80

Calls 4

strcmpFunction · 0.85
dumpValFunction · 0.85
errorFunction · 0.85
setCompareFunction · 0.85

Tested by

no test coverage detected