public static LLVMValueRef Literal(TokenType tokenType, string value, PrimitiveType type) { // Token value is an integer. if (tokenType == TokenType.LiteralInteger) { return(LLVM.ConstInt(type.Emit(), ulong.Parse(value), false)); } // Token value is a decimal. else if (tokenType == TokenType.LiteralDecimal) { return(LLVM.ConstReal(type.Emit(), double.Parse(value))); } // Token value is a string. else if (tokenType == TokenType.LiteralString) { return(LLVM.ConstString(value, (uint)value.Length, false)); } // Token value is a boolean. else if (TokenIdentifier.IsBoolean(tokenType)) { // Create the boolean value. uint boolValue; // True. if (tokenType == TokenType.KeywordTrue) { boolValue = 1; } // False. else if (tokenType == TokenType.KeywordFalse) { boolValue = 0; } // Ensure token type is a boolean representative. else { throw new Exception($"Unexpected boolean value; Expected true or false token type but got {tokenType}"); } // Create and return the resulting constant. return(LLVM.ConstInt(type.Emit(), boolValue, false)); } // At this point, type is unsupported. throw new Exception("Cannot resolve unsupported type"); }
public static bool IsType(Token token, ParserContext context) { return(TokenIdentifier.IsPrimitiveType(token.Type) || context.SymbolTable.structs.Contains(token.Value)); }
/// <summary> /// Determine if the provided token is /// representing a type /// </summary> public static bool IsPrimitiveType(Token token) { return(TokenIdentifier.IsPrimitiveType(token.Type)); }
public static bool IsBoolean(Token token) { return(TokenIdentifier.IsBoolean(token.Type)); }
public static bool IsNumeric(Token token) { return(TokenIdentifier.IsNumeric(token.Type)); }