public InsertLast(CsBody body, params string[] lines) { m_body = body; m_lines = lines; }
public void QueueInsertLast(CsBody body, params string[] lines) { m_refactor.Queue(new InsertLast(body, lines)); }
private object DoInsertLast(CsBody body, string text) { return new InsertLast(body, text.Split('\n')); }
// class-declaration: // attributes? class-modifiers? partial? class identifier type-parameter-list? // class-base? type-parameter-constraints-clauses? class-body ;? private CsType DoParseClassDeclaration(CsAttribute[] attrs, MemberModifiers modifiers, Token first, MemberModifiers defaultAccess) { // partial? if (m_scanner.Token.IsIdentifier("partial")) { m_scanner.Advance(); modifiers |= MemberModifiers.Partial; } // class DoParseKeyword("class"); // identifier Token last = m_scanner.Token; int nameOffset = m_scanner.Token.Offset; string name = DoParseIdentifier(ref last); // type-parameter-list? string gargs = null; if (m_scanner.Token.IsPunct("<")) { gargs = DoScanBody("<", ">", ref last); } // class-base? CsBases bases = DoParseInterfaceTypeList(last); // type-parameter-constraints-clauses? string constraints = DoParseTypeParameterConstraintsClauses(); // class-body var members = new List<CsMember>(); var types = new List<CsType>(); Token open = m_scanner.Token; Token start = m_scanner.Token; DoParseStructBody(members, types, ref open, ref last); Token close = last; // ;? if (m_scanner.Token.IsPunct(";")) { last = m_scanner.Token; m_scanner.Advance(); } CsBody body = new CsBody(name, start.Offset, open.Offset, close.Offset + close.Length - start.Offset, start.Line); CsClass result = new CsClass(nameOffset, body, members.ToArray(), types.ToArray(), bases, constraints, gargs, attrs, modifiers, name, first.Offset, last.Offset + last.Length - first.Offset, first.Line); return result; }
// operator-declaration: // attributes? operator-modifiers operator-declarator operator-body // // conversion-operator-declarator: // implicit operator type ( type identifier ) // explicit operator type ( type identifier ) private void DoParseConversionOperatorDeclaration(bool isImplicit, List<CsMember> members, CsAttribute[] attrs, MemberModifiers modifiers, Token first) { DoParseKeyword("operator"); int nameOffset = m_scanner.Token.Offset; string type = DoParseType(); var parms = new List<CsParameter>(); DoParsePunct("("); DoParseFormalParameterList(parms); DoParsePunct(")"); Token last = m_scanner.Token; CsBody body = null; if (m_scanner.Token.IsPunct(";")) { m_scanner.Advance(); } else { Token f = m_scanner.Token; Token start = m_scanner.Token; DoSkipBody("{", "}", ref f, ref last); body = new CsBody(isImplicit ? "op_Implict" : "op_Explict", start.Offset, f.Offset, last.Offset + last.Length - f.Offset, start.Line); } members.Add(new CsOperator(nameOffset, body, isImplicit, !isImplicit, parms.ToArray(), type, attrs, modifiers, type, first.Offset, last.Offset + last.Length - first.Offset, first.Line)); }
// operator-declaration: // attributes? operator-modifiers operator-declarator operator-body // // operator-declarator: // unary-operator-declarator // binary-operator-declarator // conversion-operator-declarator // // unary-operator-declarator: // type operator overloadable-unary-operator ( type identifier ) // // binary-operator-declarator: // type operator overloadable-binary-operator ( type identifier , type identifier ) // // operator-body: // block // ; private void DoParseOperatorDeclaration(string type, List<CsMember> members, CsAttribute[] attrs, MemberModifiers modifiers, Token first) { int nameOffset = m_scanner.Token.Offset; string name = DoParseOperatorName(); var parms = new List<CsParameter>(); DoParsePunct("("); DoParseFormalParameterList(parms); DoParsePunct(")"); Token last = m_scanner.Token; CsBody body = null; if (m_scanner.Token.IsPunct(";")) { m_scanner.Advance(); } else { Token f = m_scanner.Token; Token start = m_scanner.Token; DoSkipBody("{", "}", ref f, ref last); body = new CsBody(name, start.Offset, f.Offset, last.Offset + last.Length - f.Offset, start.Line); } members.Add(new CsOperator(nameOffset, body, false, false, parms.ToArray(), type, attrs, modifiers, name, first.Offset, last.Offset + last.Length - first.Offset, first.Line)); }
// accessor-declarations: // get-accessor-declaration set-accessor-declaration? // set-accessor-declaration get-accessor-declaration? // // get-accessor-declaration: // attributes? accessor-modifier? get accessor-body // // set-accessor-declaration: // attributes? accessor-modifier? set accessor-body // // accessor-body: // block // ; private void DoParseAccessorDeclarations(string name, ref bool isGetter, ref bool isSetter, ref CsBody getterBody, ref CsBody setterBody, ref CsAttribute[] getAttrs, ref CsAttribute[] setAttrs, ref MemberModifiers getAccess, ref MemberModifiers setAccess ) { CsAttribute[] attrs = DoParseAttributes(); MemberModifiers modifiers = DoParseModifiers(); Token last = m_scanner.Token; if (m_scanner.Token.IsIdentifier("get")) { isGetter = true; getAttrs = attrs; getAccess = modifiers; m_scanner.Advance(); if (m_scanner.Token.IsPunct(";")) { DoParsePunct(";"); } else { Token start = m_scanner.Token; Token first = m_scanner.Token; DoSkipBody("{", "}", ref first, ref last); getterBody = new CsBody("get_" + name, start.Offset, first.Offset, last.Offset + last.Length - start.Offset, start.Line); } } else if (m_scanner.Token.IsIdentifier("set")) { isSetter = true; setAttrs = attrs; setAccess = modifiers; m_scanner.Advance(); if (m_scanner.Token.IsPunct(";")) { DoParsePunct(";"); } else { Token first = m_scanner.Token; Token start = m_scanner.Token; DoSkipBody("{", "}", ref first, ref last); setterBody = new CsBody("set_" + name, start.Offset, first.Offset, last.Offset + last.Length - start.Offset, start.Line); } } else throw new CsParserException("Expected 'get' or 'set' on line {0}, but found '{1}'", m_scanner.Token.Line, m_scanner.Token.Text()); }
public CsOperator(int nameOffset, CsBody body, bool isImplicit, bool isExplicit, CsParameter[] parms, string rtype, CsAttribute[] attrs, MemberModifiers modifiers, string name, int offset, int length, int line) : base(nameOffset, attrs, modifiers, name, offset, length, line) { Contract.Requires(!string.IsNullOrEmpty(rtype), "rtype is null or empty"); ReturnType = rtype.TrimAll(); Parameters = parms; IsImplicit = isImplicit; IsExplicit = isExplicit; Body = body; }
// namespace-declaration: // namespace qualified-identifier namespace-body ;? private void DoParseNamespaceDeclaration(ref Token last, List<CsNamespace> namespaces) { Token first = m_scanner.Token; DoParseKeyword("namespace"); string name = DoParseQualifiedIdentifier(); var externs = new List<CsExternAlias>(); var aliases = new List<CsUsingAlias>(); var uses = new List<CsUsingDirective>(); var childNamespaces = new List<CsNamespace>(); var types = new List<CsType>(); Token open = m_scanner.Token; Token start = m_scanner.Token; DoParseNamespaceBody(externs, aliases, uses, childNamespaces, types, ref open, ref last); Token close = last; if (m_scanner.Token.IsPunct(";")) { last = m_scanner.Token; m_scanner.Advance(); } CsBody body = new CsBody(name, start.Offset, open.Offset, close.Offset + close.Length - start.Offset, start.Line); namespaces.Add(new CsNamespace(body, name, externs.ToArray(), aliases.ToArray(), uses.ToArray(), childNamespaces.ToArray(), types.ToArray(), first.Offset, last.Offset + last.Length - first.Offset, first.Line)); }
public CsMethod(int nameOffset, CsBody body, bool isCtor, bool isDtor, string constraints, CsParameter[] parms, string gargs, string rtype, CsAttribute[] attrs, MemberModifiers modifiers, string name, int offset, int length, int line) : base(nameOffset, attrs, modifiers, name, offset, length, line) { Contract.Requires(!(isCtor && isDtor), "can't be both a ctor and a dtor"); Contract.Requires(parms != null, "parms is null"); Contract.Requires(!string.IsNullOrEmpty(rtype), "rtype is null or empty"); Body = body; IsConstructor = isCtor; IsFinalizer = isDtor; ReturnType = rtype.TrimAll(); Parameters = parms; Constraints = constraints; if (gargs != null) GenericArguments = gargs.TrimAll(); }
public CsNamespace(CsBody body, string name, CsExternAlias[] externs, CsUsingAlias[] aliases, CsUsingDirective[] uses, CsNamespace[] namespaces, CsType[] types, int offset, int length, int line) : base(body, types, offset, length, line) { Contract.Requires(!string.IsNullOrEmpty(name), "name is null or empty"); Contract.Requires(externs != null, "externs is null"); Contract.Requires(aliases != null, "aliases is null"); Contract.Requires(uses != null, "uses is null"); Contract.Requires(namespaces != null, "namespaces is null"); Name = name; Externs = externs; Aliases = aliases; Uses = uses; Namespaces = namespaces; var decs = new List<CsDeclaration>(); decs.AddRange(namespaces); SetDeclarations(decs); foreach (CsNamespace n in Namespaces) n.Namespace = this; foreach (CsType t in Types) t.Namespace = this; }
public CsInterface(int nameOffset, CsBody body, CsMember[] members, CsType[] types, CsBases bases, string constraints, string gargs, CsAttribute[] attrs, MemberModifiers modifiers, string name, int offset, int length, int line) : base(nameOffset, body, bases, members, types, attrs, modifiers, constraints, gargs, name, offset, length, line) { }
public CsIndexer(int nameOffset, CsBody getterBody, CsBody setterBody, MemberModifiers getAccess, MemberModifiers setAccess, string name, CsAttribute[] getAttrs, CsAttribute[] setAttrs, bool hasGet, bool hasSet, CsParameter[] parms, string rtype, CsAttribute[] attrs, MemberModifiers modifiers, int offset, int length, int line) : base(nameOffset, attrs, modifiers, name, offset, length, line) { Contract.Requires(!hasGet || getAttrs != null, "getAttrs is null"); Contract.Requires(!hasSet || setAttrs != null, "setAttrs is null"); Contract.Requires(hasGet || hasSet, "not a getter and not a setter"); Contract.Requires(parms != null, "parms is null"); Contract.Requires(!string.IsNullOrEmpty(rtype), "rtype is null or empty"); Contract.Requires(((int) getAccess & ~CsMember.AccessMask) == 0, "getAccess has more than just acccess set"); Contract.Requires(((int) setAccess & ~CsMember.AccessMask) == 0, "setAccess has more than just acccess set"); HasGetter = hasGet; HasSetter = hasSet; ReturnType = rtype.TrimAll(); Parameters = parms; GetterAttributes = getAttrs; SetterAttributes = setAttrs; GetterAccess = getAccess; SetterAccess = setAccess; GetterBody = getterBody; SetterBody = setterBody; }
public CsGlobalNamespace(CsPreprocess[] preprocess, CsBody body, CsAttribute[] attrs, CsExternAlias[] externs, CsUsingAlias[] aliases, CsUsingDirective[] uses, CsNamespace[] namespaces, CsType[] types, int length) : base(body, "<globals>", externs, aliases, uses, namespaces, types, 0, length, 1) { Contract.Requires(attrs != null, "attrs is null"); Contract.Requires(preprocess != null, "preprocess is null"); Attributes = attrs; Preprocess = preprocess; }
protected CsTypeScope(CsBody body, CsType[] types, int offset, int length, int line) : base(offset, length, line) { Contract.Requires(types != null, "types is null"); Body = body; Delegates = (from m in types let e = m as CsDelegate where e != null select e).ToArray(); Enums = (from m in types let e = m as CsEnum where e != null select e).ToArray(); Classes = (from t in types let e = t as CsClass where e != null select e).ToArray(); Interfaces = (from t in types let e = t as CsInterface where e != null select e).ToArray(); Structs = (from t in types let e = t as CsStruct where e != null select e).ToArray(); Types = types; Contract.Assert(Types.Length == Classes.Length + Interfaces.Length + Structs.Length + Delegates.Length + Enums.Length, "bad types length"); }
protected CsType(int nameOffset, CsBody body, CsBases bases, CsMember[] members, CsType[] types, CsAttribute[] attrs, MemberModifiers modifiers, string constraints, string gargs, string name, int offset, int length, int line) : base(body, types, offset, length, line) { Contract.Requires(members != null, "members is null"); Contract.Requires(types != null, "types is null"); Contract.Requires(attrs != null, "attrs is null"); Contract.Requires(!string.IsNullOrEmpty(name), "name is null or empty"); Contract.Requires(bases != null, "bases is null"); Contract.Requires(nameOffset > offset, "nameOffsetis too small"); Contract.Requires(nameOffset < offset + length, "nameOffsetis too large"); Attributes = attrs; Modifiers = modifiers; Name = name; NameOffset = nameOffset; Constraints = constraints; Bases = bases; if (gargs != null) GenericArguments = gargs.TrimAll(); Events = (from m in members let e = m as CsEvent where e != null select e).ToArray(); Fields = (from m in members let e = m as CsField where e != null select e).ToArray(); Indexers = (from m in members let e = m as CsIndexer where e != null select e).ToArray(); Methods = (from m in members let e = m as CsMethod where e != null select e).ToArray(); Operators = (from m in members let e = m as CsOperator where e != null select e).ToArray(); Properties = (from m in members let e = m as CsProperty where e != null select e).ToArray(); Contract.Assert(members.Length == Events.Length + Fields.Length + Indexers.Length + Methods.Length + Operators.Length + Properties.Length, "bad members length"); Members = members; var decs = new List<CsDeclaration>(); decs.AddRange(Events); decs.AddRange(Fields); decs.AddRange(Indexers); decs.AddRange(Methods); decs.AddRange(Operators); decs.AddRange(Properties); SetDeclarations(decs); foreach (CsMember m in members) m.DeclaringType = this; foreach (CsType t in types) t.DeclaringType = this; }