bool ParameterList::DoInfix(Infix *what) // ---------------------------------------------------------------------------- // Check if we match an infix operator // ---------------------------------------------------------------------------- { // Check if we match a type, e.g. 2 vs. 'K : integer' if (what->name == ":") { // Check the variable name, e.g. K in example above if (Name *varName = what->left->AsName()) { // Enter a name in the parameter list with adequate machine type llvm_type mtype = unit->MachineType(what->right); llvm_type ntype = unit->ExpressionMachineType(varName); if (mtype != ntype) { Ooops("Conflicting machine type for declaration $1", what); return false; } return EnterName(varName, false); } else { // We ar specifying the type of the expression, e.g. (X+Y):integer if (returned || defined) { Ooops("Cannot specify type of $1", what->left); return false; } // Remember the specified returned value returned = unit->ExpressionMachineType(what); // Keep going with the left-hand side return what->left->Do(this); } } // If this is the first one, this is what we define if (!defined) { defined = what; name = what->name; } // Otherwise, test left and right if (!what->left->Do(this)) return false; if (!what->right->Do(this)) return false; return true; }
Tree *FontParsingAction::Do (Tree *what) // ---------------------------------------------------------------------------- // Default action on trees - Do nothing? // ---------------------------------------------------------------------------- { Ooops("Unexpected font entry $1", what); return what; }
XL_BEGIN bool ParameterList::EnterName(Name *what, bool untyped) // ---------------------------------------------------------------------------- // Enter a name in the parameter list // ---------------------------------------------------------------------------- { // We only allow names here, not symbols (bug #154) if (what->value.length() == 0 || !isalpha(what->value[0])) { Ooops("The pattern variable $1 is not a name", what); return false; } // Check the LLVM type for the given form llvm_type type = unit->ExpressionMachineType(what); // Check if the name already exists in parameter list, e.g. in 'A+A' text name = what->value; Parameters::iterator it; for (it = parameters.begin(); it != parameters.end(); it++) { if ((*it).name->value == name) { llvm_type nameType = unit->ExpressionMachineType((*it).name); if (type == nameType) return true; Ooops("Conflicting machine types for $1", what); return false; } } // Check if the name already exists in context, e.g. 'false' if (untyped) if (unit->context->scope->Bound(what)) return true; // We need to record a new parameter parameters.push_back(Parameter(what, type)); return true; }
double xl_real_arg(Tree *value) // ---------------------------------------------------------------------------- // Return a real value // ---------------------------------------------------------------------------- { if (Real *rval = value->AsReal()) return rval->value; Ooops("Value $1 is not a real", value); return 0.0; }
int xl_character_arg(Tree *value) // ---------------------------------------------------------------------------- // Return a character value // ---------------------------------------------------------------------------- { if (Text *tval = value->AsText()) if (tval->opening == "'" && tval->value.length() == 1) return tval->value[0]; Ooops("Value $1 is not a character", value); return 0; }
text xl_text_arg(Tree *value) // ---------------------------------------------------------------------------- // Return a text value // ---------------------------------------------------------------------------- { if (Text *tval = value->AsText()) if (tval->opening != "'") return tval->value; Ooops("Value $1 is not a text", value); return ""; }
bool xl_boolean_arg(Tree *value) // ---------------------------------------------------------------------------- // Return a boolean truth value // ---------------------------------------------------------------------------- { if (value == xl_true) return true; else if (value == xl_false) return false; Ooops("Value $1 is not a boolean value", value); return false; }
Opcode * Opcode::Find(Tree *self, text name) // ---------------------------------------------------------------------------- // Find an opcode that matches the name if there is one // ---------------------------------------------------------------------------- { for (Opcodes::iterator o = opcodes->begin(); o != opcodes->end(); o++) { Opcode *opcode = *o; if (opcode->OpID() == name) return opcode; } Ooops("Invalid opcode name in $1", self); return NULL; }
XL_BEGIN // ============================================================================ // // Helper functions for native code // // ============================================================================ longlong xl_integer_arg(Tree *value) // ---------------------------------------------------------------------------- // Return an integer value // ---------------------------------------------------------------------------- { if (Integer *ival = value->AsInteger()) return ival->value; Ooops("Value $1 is not an integer", value); return 0; }