| 7756 | } |
| 7757 | |
| 7758 | std::string GeneratorJava::ConvertConstant(const std::string& domain, const std::string& package, const std::string& type, const std::string& value, bool optional) |
| 7759 | { |
| 7760 | if (value == "true") |
| 7761 | return "true"; |
| 7762 | else if (value == "false") |
| 7763 | return "false"; |
| 7764 | else if (value == "null") |
| 7765 | return "null"; |
| 7766 | else if (value == "min") |
| 7767 | { |
| 7768 | if ((type == "byte") || (type == "uint8") || (type == "uint16") || (type == "uint32") || (type == "uint64")) |
| 7769 | return ConvertConstantPrefix(type) + "0" + ConvertConstantSuffix(type); |
| 7770 | else if (type == "int8") |
| 7771 | return ConvertConstantPrefix(type) + "-128" + ConvertConstantSuffix(type); |
| 7772 | else if (type == "int16") |
| 7773 | return ConvertConstantPrefix(type) + "-32768" + ConvertConstantSuffix(type); |
| 7774 | else if (type == "int32") |
| 7775 | return ConvertConstantPrefix(type) + "-2147483648" + ConvertConstantSuffix(type); |
| 7776 | else if (type == "int64") |
| 7777 | return ConvertConstantPrefix(type) + "-9223372036854775808" + ConvertConstantSuffix(type); |
| 7778 | |
| 7779 | yyerror("Unsupported type " + type + " for 'min' constant"); |
| 7780 | return ""; |
| 7781 | } |
| 7782 | else if (value == "max") |
| 7783 | { |
| 7784 | if (type == "byte") |
| 7785 | return ConvertConstantPrefix(type) + "0xFF" + ConvertConstantSuffix(type); |
| 7786 | else if (type == "int8") |
| 7787 | return ConvertConstantPrefix(type) + "127" + ConvertConstantSuffix(type); |
| 7788 | else if (type == "uint8") |
| 7789 | return ConvertConstantPrefix(type) + "0xFF" + ConvertConstantSuffix(type); |
| 7790 | else if (type == "int16") |
| 7791 | return ConvertConstantPrefix(type) + "32767" + ConvertConstantSuffix(type); |
| 7792 | else if (type == "uint16") |
| 7793 | return ConvertConstantPrefix(type) + "0xFFFF" + ConvertConstantSuffix(type); |
| 7794 | else if (type == "int32") |
| 7795 | return ConvertConstantPrefix(type) + "2147483647" + ConvertConstantSuffix(type); |
| 7796 | else if (type == "uint32") |
| 7797 | return ConvertConstantPrefix(type) + "0xFFFFFFFF" + ConvertConstantSuffix(type); |
| 7798 | else if (type == "int64") |
| 7799 | return ConvertConstantPrefix(type) + "9223372036854775807" + ConvertConstantSuffix(type); |
| 7800 | else if (type == "uint64") |
| 7801 | return ConvertConstantPrefix(type) + "0xFFFFFFFFFFFFFFFF" + ConvertConstantSuffix(type); |
| 7802 | |
| 7803 | yyerror("Unsupported type " + type + " for 'max' constant"); |
| 7804 | return ""; |
| 7805 | } |
| 7806 | else if (value == "epoch") |
| 7807 | return ((Version() < 8) ? "new java.util.Date(0)" : "java.time.Instant.EPOCH"); |
| 7808 | else if (value == "utc") |
| 7809 | return ((Version() < 8) ? "new java.util.Date(System.currentTimeMillis())" : "java.time.Instant.now()"); |
| 7810 | else if (value == "uuid0") |
| 7811 | return domain + "fbe.UUIDGenerator.nil()"; |
| 7812 | else if (value == "uuid1") |
| 7813 | return domain + "fbe.UUIDGenerator.sequential()"; |
| 7814 | else if (value == "uuid4") |
| 7815 | return domain + "fbe.UUIDGenerator.random()"; |