public Routine( NodeKind kind, Cursor cursor, SymbolDefinition name, Profile profile, Block block ) : base(kind, cursor, name) { _profile = profile; _profile.Above = this; _block = block; _block.Above = this; }
/** Creates a default getter for use in a field or a guard. */ private GetStatement CreateDefaultGetter(Cursor cursor, string value) { // Create profile of the default getter. Profile profile = new Profile( position, new NamedType(position, new SymbolReference(position, PathKind.Instance, value)), new Parameter[0] ); // Create sole embedded statement; a return statement that returns the value of the data member. Statement statement = new ReturnExpressionStatement( position, new NamedExpression(position, new SymbolReference(position, PathKind.Instance, value)) ); Statement[] statements = new Statement[1]{ statement }; Block block = new Block(position, statements); return new GetStatement( position, new SymbolDefinition(position, "get", SymbolKind.Getter), profile, block ); }
public override object Visit(Profile that, object value) { var result = new System.Text.StringBuilder(256); // Output the signature of Braceless v0.x encoded/mangled names. result.Append(marker + "b0" + marker); result.Append(((Definition) that.Above).Name.Symbol); result.Append(marker); // Encode number of parameters. result.Append(that.Parameters.Length.ToString()); result.Append(marker); foreach (Parameter parameter in that.Parameters) { parameter.Visit(this, (object) result); result.Append(marker); } /** \note Don't encode the return type as we do like C++ and C#: Overloads cannot differ only in return type. */ return result.ToString(); }
public override object Visit(Profile that, object value) { _writer.Write("("); foreach (Parameter parameter in that.Parameters) { parameter.Visit(this); if (parameter != that.Parameters[that.Parameters.Length - 1]) _writer.Write(", "); } _writer.Write(")"); if (that.Type.Kind != NodeKind.NoneType) { _writer.Write(" is "); that.Type.Visit(this); } _writer.WriteLine(':'); return null; }
public override object Visit(Profile that, object value = null) { PrintPrologue(that); PrintNodeId("Type", that.Type); PrintSequence("Parameters", that.Parameters); PrintEpilogue(that); that.Type.Visit(this); foreach (Parameter parameter in that.Parameters) parameter.Visit(this); return null; }
public override object Visit(Profile that, object value) { // Decide if it is a declaration or a definition. if (that.Above.Kind == NodeKind.ExternalStatement) _writer.Write("declare "); else _writer.Write("define "); // Output return type. that.Type.Visit(this); _writer.Write(' '); Routine routine = (Routine) that.Above; _writer.Write(EncodeRoutine(routine.Name.Path, routine.Encoded)); _writer.Write("("); // Output each parameter in turn. foreach (Parameter parameter in that.Parameters) { if (parameter != that.Parameters[0]) _writer.Write(", "); parameter.Visit(this); } _writer.WriteLine(")"); return null; }
public EntryStatement(Cursor cursor, SymbolDefinition name, Profile profile, Block block) : base(NodeKind.EntryStatement, cursor, name, profile, block) { }
public override object Visit(Profile that, object value = null) { foreach (Parameter parameter in that.Parameters) parameter.Visit(this); that.Type.Visit(this); return null; }
/** Creates a default setter for use in a field or a guard. */ private SetStatement CreateDefaultSetter(Cursor cursor, string value) { /** Create the \c value parameter. */ /** \todo Move creation of the \c value parameter to a suitable pass. */ Parameter parameter = new Parameter( position, new SymbolDefinition(position, "value", SymbolKind.Parameter), DirectionKind.In, new UnknownType(position) ); /** Create the profile of the setter. */ Profile profile = new Profile(position, new NoneType(position), new Parameter[1]{ parameter }); /** Create the body of the setter: let .value := value. */ Statement statement = new LetStatement( position, AssignmentKind.Identity, new NamedExpression(position, new SymbolReference(position, PathKind.Instance, value)), new NamedExpression(position, new SymbolReference(position, PathKind.Relative, "value")) ); Statement[] statements = new Statement[1]{ statement }; Block block = new Block(position, statements); return new SetStatement( position, new SymbolDefinition(position, "set", SymbolKind.Setter), profile, block ); }
/** Parses a \c set accessor (a setter). */ private SetStatement ParseSetRoutine(Type type) { Token start = _matcher.Match(TokenKind.Keyword_Set); _matcher.Match(TokenKind.Colon); _matcher.Match(TokenKind.EndOfLine); _matcher.Match(TokenKind.Indent); Block block = ParseBlock(); _matcher.Match(TokenKind.Dedent); // Create a synthetic profile for general consistency and simplicity of handling setters. Profile profile = new Profile(start.Cursor, type, new Parameter[0]); return new SetStatement( start.Cursor, new SymbolDefinition(start.Cursor, "set", SymbolKind.Setter), profile, block ); }