ExprNode FindSymbol(AstScope scope) { if (Arguments == null) { // Simple symbol var symbol = scope.FindSymbol(_name); if (symbol == null) { throw new CodeException($"Unrecognized symbol: '{_name}'", SourcePosition); } var expr = symbol as ExprNode; if (expr == null) { throw new CodeException($"Invalid expression: '{_name}' is not a value", SourcePosition); } return(expr); } else { // Parameterized symbol var symbol = scope.FindSymbol(_name + ExprNodeParameterized.MakeSuffix(Arguments.Length)) as ExprNodeParameterized; if (symbol == null) { throw new CodeException($"Unrecognized symbol: '{_name}' (with {Arguments.Length} arguments)", SourcePosition); } // Resolve it return(symbol.Resolve(SourcePosition, Arguments)); } }
public override void DefineSymbols(AstScope currentScope) { if (_parameters == null) { _parameters = new string[0]; } // Define the symbol currentScope.Define(_name + ExprNodeParameterized.MakeSuffix(_parameters.Length), this); }
public override void DefineSymbols(AstScope currentScope) { if (ParameterNames == null) { // Wrap it in an IP override declaration currentScope.Define(_name, _value); } else { var value = new ExprNodeParameterized(SourcePosition, ParameterNames, _value); currentScope.Define(_name + ExprNodeParameterized.MakeSuffix(ParameterNames.Length), value); } }
public override void Layout(AstScope currentScope, LayoutContext ctx) { // Is it a data declaration? _dataType = currentScope.FindSymbol(_macroOrDataTypeName) as AstType; if (_dataType != null) { // Work out how many elements in total int totalElements = 0; foreach (var n in _operands) { totalElements += n.EnumData(currentScope).Count(); } // Reserve space ctx.ReserveBytes(_reservedBytes = totalElements * _dataType.SizeOf); return; } // Is it a macro invocation? _macroDefinition = currentScope.FindSymbol(_macroOrDataTypeName + ExprNodeParameterized.MakeSuffix(_operands.Count)) as AstMacroDefinition; if (_macroDefinition != null) { // Create resolved scope _resolvedScope = _macroDefinition.Resolve(currentScope, _operands.ToArray()); // Define macro symbols _macroDefinition.DefineSymbolsResolved(_resolvedScope); // Layout _macroDefinition.LayoutResolved(_resolvedScope, ctx); return; } throw new CodeException($"Unrecognized symbol: '{_macroOrDataTypeName}' is not a known data type or macro (with {_operands.Count} arguments)", SourcePosition); }