//constructor public Day(int number) { for (int i = 0; i < 148; i++) { //to adapt with schedule l_activity[i] = new Inside(); } }
//constructor public Day(int _number, Place map_hq) { number = _number; Activity defaultAct = new Inside(0, 147, map_hq); for (int i = 0; i <= 147; i++) //24*6+4 -1 because no activity at 24:40 { //create default activity l_activity[i] = defaultAct; } }
//constructor public Day(int _number, Place _map_hq) { number = _number; map_hq = _map_hq; l_activity = new List<Activity>(); Activity defaultAct = new Inside(0, 147, map_hq); for (int i = 0; i <= 147; i++) //24*6+4 -1 because no activity at 24:40 { //create default activity l_activity.Insert(i, defaultAct); } }
public void modifyHoursActivity(Activity prevActivity, int newStart, int newEnd) { //we have to create a new activity and not only update the previous one not to have problems with sortActivity Activity newActivity; if (prevActivity is Inside) { newActivity = new Inside(newStart, newEnd, prevActivity.Place, prevActivity.Type); } else { newActivity = new Outside(newStart, newEnd, prevActivity.Place, prevActivity.Type); } newActivity.Description = prevActivity.Description; newActivity.L_astronaut = prevActivity.L_astronaut; rmActivity(prevActivity); addActivity(newActivity); }
public void sortActivityList() { //this function sorts a list and its activities in order them to be coherent for (int i = 0; i < l_activity.Count -1 ; i++)//Stop at Count -1 because of i+1 { //if two consecutive activities are different if (!(l_activity[i].Equals(l_activity[i + 1]))) { //but have the same type and place, it is considered as being the same activity // So we merge the both activities if ((l_activity[i].Type.Equals(l_activity[i + 1].Type)) && (l_activity[i].Place.Equals(l_activity[i + 1].Place))) { //extend the end and merge descriptions before merging the entire activity l_activity[i].End = l_activity[i + 1].End; l_activity[i].Description = l_activity[i].Description + l_activity[i + 1].Description; //join the both description l_activity[i + 1] = l_activity[i]; } //elsewise, we reschedule the previous and forward activity activities else { //We have to create a new activity instead of updating the previous one //We check that the current ativity is not already rescheduled not to process twice if (l_activity[i].End != i + 1) { if (l_activity[i] is Inside) { l_activity[i] = new Inside(l_activity[i].Start, i + 1, l_activity[i].Place, l_activity[i].Type); } else { new Inside(l_activity[i].Start, i + 1, l_activity[i].Place, l_activity[i].Type); } for (int j = l_activity[i].Start; j < l_activity[i].End; j++) { l_activity[j] = l_activity[i]; } } //We check that the next ativity is not already rescheduled not to process twice if (l_activity[i + 1].Start != i + 1) { if (l_activity[i + 1] is Inside) { l_activity[i + 1] = new Inside(i + 1, l_activity[i + 1].End, l_activity[i + 1].Place, l_activity[i + 1].Type); } else { new Inside(i + 1, l_activity[i + 1].End, l_activity[i + 1].Place, l_activity[i + 1].Type); } for (int j = l_activity[i + 1].Start; j < l_activity[i + 1].End; j++) { l_activity[j] = l_activity[i + 1]; } } } } } }
void PushQuote(Inside inside) { Inside type; // ignore if in these if ((inside & (Inside.PreProcessor | Inside.Comment | Inside.CharLiteral)) != 0) { return; } if (inside == Inside.VerbatimString) { if (popVerbatim) { // back in the verbatim-string-literal token popVerbatim = false; } else { /* need to see the next char before we pop the * verbatim-string-literal */ popVerbatim = true; } } else if (inside == Inside.StringLiteral) { // check that it isn't escaped if (!isEscaped) { keyword = stack.PeekKeyword(0); stack.Pop(); } } else { // FoldedStatement, Block, Attribute or ParenList if (pc == '@') { type = Inside.VerbatimString; } else { type = Inside.StringLiteral; } // push a new string onto the stack stack.Push(type, keyword, curLineNr, 0); } }
public static void ReadFile() { using (var reader = new StreamReader(@"C:\Users\denni\source\repos\temperature\TemperaturData.csv")) { List <TempData> insideList = new List <TempData>(); List <TempData> outsideList = new List <TempData>(); while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); if (values[1].Equals("Inne")) { string temp = values[2].Replace('.', ','); TempData tempData = new TempData(DateTime.Parse(values[0]), float.Parse(temp), int.Parse(values[3])); insideList.Add(tempData); } else if (values[1].Equals("Ute")) { string temp = values[2].Replace('.', ','); TempData tempData = new TempData(DateTime.Parse(values[0]), float.Parse(temp), int.Parse(values[3])); outsideList.Add(tempData); } } using (var context = new EFContext()) { foreach (TempData tempData in outsideList) { Outside toAdd = new Outside(); toAdd.Date = tempData.Date; toAdd.Moisture = tempData.Moisture; toAdd.Temperature = tempData.Temperature; context.Add(toAdd); } foreach (TempData tempData in insideList) { Inside toAdd = new Inside(); toAdd.Date = tempData.Date; toAdd.Moisture = tempData.Moisture; toAdd.Temperature = tempData.Temperature; context.Add(toAdd); } context.SaveChanges(); } } }
//remove an activity and replace it by an activity by default //it is possible to remove only a part of the activity => when you make it shorter for instance public void rmActivity(Activity prevActivity, int start, int end) { //has to check that the activity is on the list //has to check that the part of the activity to remove is included in activity if ((l_activity.Contains(prevActivity)))// && (prevActivity.Start <= start) && (prevActivity.End >= end)) { //replace the remove activity by the default one which is private at the hq Activity newActivity = new Inside(start, end, map_hq); addActivity(newActivity); } else { //error message } }
private bool CellInRegion(double[] lo, double[] hi, Region region, Inside inside) { double[] x = new double[3]; int n = 0; x[0] = lo[0]; x[1] = lo[1]; x[2] = lo[2]; n += region.Match(x); x[0] = hi[0]; x[1] = lo[1]; x[2] = lo[2]; n += region.Match(x); x[0] = lo[0]; x[1] = hi[1]; x[2] = lo[2]; n += region.Match(x); x[0] = hi[0]; x[1] = hi[1]; x[2] = lo[2]; n += region.Match(x); if (dimension == 3) { x[0] = lo[0]; x[1] = lo[1]; x[2] = hi[2]; n += region.Match(x); x[0] = hi[0]; x[1] = lo[1]; x[2] = hi[2]; n += region.Match(x); x[0] = lo[0]; x[1] = hi[1]; x[2] = hi[2]; n += region.Match(x); x[0] = hi[0]; x[1] = hi[1]; x[2] = hi[2]; n += region.Match(x); } if (inside == Inside.ANY) { if (n != 0) { return(true); } } else if (inside == Inside.ALL) { if (dimension == 2 && n == 4) { return(true); } if (dimension == 3 && n == 8) { return(true); } } return(false); }
public DomainPolicy.IPolicy FromTransport() { List <DomainPolicy.IFence> fences = new List <DomainPolicy.IFence>(); foreach (IFence fence in Fences) { fences.Add(fence.FromTransport()); } return(new DomainPolicy.ConditionalGeoFencePolicy( inside: Inside.FromTransport(), outside: Outside.FromTransport(), fences: fences, denyRootedJailbroken: DenyRootedJailbroken, denyEmulatorSimulator: DenyEmulatorSimulator )); }
void PushCloseParen(Inside inside) { if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) { return; } if (inside != Inside.ParenList) { //Console.WriteLine ("can't pop a '(' if we ain't got one?"); return; } // pop this paren list off the stack keyword = stack.PeekKeyword(0); stack.Pop(); }
void PushOpenSq(Inside inside) { int n = 1; if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) { return; } // push a new attribute onto the stack if (firstNonLwsp != -1) { n += linebuf.Length - firstNonLwsp; } stack.Push(Inside.Attribute, keyword, curLineNr, n); }
public void Push(Inside inside, string keyword, int lineNr, int nSpaces, string indent) { Node node; node.Indent = indent; node.Keyword = keyword; node.NumSpaces = nSpaces; node.LineNr = lineNr; node.Inside = inside; if (size == stack.Length) { Array.Resize <Node> (ref stack, 2 * size); } stack[size++] = node; }
private void createDfaultActList() { Activity sleeping1 = new Inside(0, 7 * 6, map_hq, "sleeping"); Activity sleeping2 = new Inside(22 * 6, 147, map_hq, "sleeping"); Activity eating1 = new Inside(12 * 6, 13 * 6, map_hq, "eating"); Activity eating2 = new Inside(19 * 6, 20 * 6, map_hq, "eating"); Activity defaultAct1 = new Inside(7 * 6, 12 * 6, map_hq, "private"); Activity defaultAct2 = new Inside(13 * 6, 19 * 6, map_hq, "private"); Activity defaultAct3 = new Inside(20 * 6, 22 * 6, map_hq, "private"); for (int i = 0; i <= 147; i++) //24*6+4 -1 because no activity at 24:40 { if (i >= 0 && i < 7 * 6) { l_activity.Insert(i, sleeping1); } else if (i >= 7 * 6 && i < 12 * 6) { l_activity.Insert(i, defaultAct1); } else if (i >= 12 * 6 && i < 13 * 6) { l_activity.Insert(i, eating1); } else if (i >= 13 * 6 && i < 19 * 6) { l_activity.Insert(i, defaultAct2); } else if (i >= 19 * 6 && i < 20 * 6) { l_activity.Insert(i, eating2); } else if (i >= 20 * 6 && i < 22 * 6) { l_activity.Insert(i, defaultAct3); } else if (i >= 22 * 6 && i < 147) { l_activity.Insert(i, sleeping2); } else { l_activity.Insert(i, defaultAct1); } } }
void PushSlash(Inside inside) { // ignore these if ((inside & (Inside.PreProcessor | Inside.StringOrChar)) != 0) { return; } switch (inside) { case Inside.LineComment: stack.Pop(); // pop line comment stack.Push(Inside.DocComment, keyword, curLineNr, 0); break; case Inside.BlockComment: // check for end of multi-line comment block if (pc == '*') { // restore the keyword and pop the multiline comment keyword = stack.PeekKeyword; stack.Pop(); } break; case Inside.NestedComment: if (pc == '+') { keyword = stack.PeekKeyword; stack.Pop(); } break; default: // FoldedStatement, Block, Attribute or ParenList // check for the start of a single-line comment if (pc == '/') { stack.Push(Inside.LineComment, keyword, curLineNr, 0); // drop the previous '/': it belongs to this comment rc = prc; } break; } }
void PushSemicolon(Inside inside) { if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) { return; } if (inside == Inside.FoldedStatement) { // chain-pop folded statements while (stack.PeekInside(0) == Inside.FoldedStatement) { stack.Pop(); } } keyword = String.Empty; }
public void Push(Inside inside, byte keyword, int lineNr, int nSpaces, string indent) { Node node; node.indent = indent; node.keyword = keyword; node.nSpaces = nSpaces; node.lineNr = lineNr; node.inside = inside; node.ifelseBackupStack = null; if (size == stack.Length) { Array.Resize <Node> (ref stack, 2 * size); } stack[size++] = node; }
static void Main(string[] args) { Top.Inside x = new Top.Inside(); x.FirstName = "yona"; Inside y = new Inside(); y.FirstName = "yossi"; Top.InsideTop.Inside z = new Top.InsideTop.Inside(); z.LastName = "ben david"; it.Inside a = new it.Inside(); a.LastName = "levi"; //System.Data.SqlClient.SqlConnection //System.Data.OleDb.OleDbConnection }
public void modifyHoursActivityTest() { Day target = CreateDay(); // TODO: Initialize to an appropriate value Activity prevActivity = new Inside(5,9,target.Map_hq, "coucou"); // TODO: Initialize to an appropriate value int newStart = 6; // TODO: Initialize to an appropriate value int newEnd = 9; // TODO: Initialize to an appropriate value target.modifyHoursActivity(prevActivity, newStart, newEnd); Day test = CreateDay(); List<Activity> expected = test.L_activity; for (int i = 6; i <= 9; i++) { expected[i] = new Inside(6, 9, target.Map_hq, "coucou"); } Assert.AreEqual(expected, target.L_activity); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
void PushOpenParen(Inside inside) { int n = 1; if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) { return; } // push a new paren list onto the stack if (firstNonLwsp != -1) { n += linebuf.Length - firstNonLwsp; } stack.Push(Inside.ParenList, keyword, curLineNr, n); keyword = String.Empty; }
public void TestSimple() { Object obj1 = new Object(); Sample sample = new Sample(); Object obj2 = new Object(); Inside inside = new Inside(); /*Devspace.Commons.Mediator.MediatorSimple mediator = new Devspace.Commons.Mediator.MediatorSimple(); * * mediator.Add( obj1, sample ); * mediator.Add( obj2, inside ); * * NUnit.Framework.Assert.AreEqual( obj1, mediator.Get<Sample, Object>( sample ) ); * NUnit.Framework.Assert.AreEqual( sample, mediator.Get<Object, Sample>( obj1 ) ); * NUnit.Framework.Assert.IsNull( mediator.Get< Object, Object>( new Object())); * NUnit.Framework.Assert.AreEqual( obj2, mediator.Get<Inside, Object>( inside ) ); * NUnit.Framework.Assert.AreEqual( inside, mediator.Get<Object, Inside>( obj2 ) ); */ }
// Handlers for specific characters void PushHash(Inside inside) { // ignore if we are inside a string, char, or comment if ((inside & (Inside.StringOrChar | Inside.Comment)) != 0) { return; } // ignore if '#' is not the first significant char on the line if (rc != '\0') { return; } stack.Push(Inside.PreProcessor, null, curLineNr, 0); curIndent = String.Empty; needsReindent = false; }
CSharpIndentEngine(CSharpIndentEngine prototype) { this.document = prototype.document; this.options = prototype.options; this.textEditorOptions = prototype.textEditorOptions; this.indent = prototype.indent.Clone(); this.thisLineindent = prototype.thisLineindent.Clone(); this.offset = prototype.offset; this.inside = prototype.inside; this.IsLineStart = prototype.IsLineStart; this.pc = prototype.pc; this.parenStack = new Stack<TextLocation>(prototype.parenStack.Reverse ()); this.currentBody = prototype.currentBody; this.nextBody = prototype.nextBody; this.addContinuation = prototype.addContinuation; this.line = prototype.line; this.col = prototype.col; this.popNextParenBlock = prototype.popNextParenBlock; }
public void modifyHoursActivityTest() { Day target = CreateDay(); // TODO: Initialize to an appropriate value Activity prevActivity = new Inside(5, 9, target.Map_hq, "coucou"); // TODO: Initialize to an appropriate value int newStart = 6; // TODO: Initialize to an appropriate value int newEnd = 9; // TODO: Initialize to an appropriate value target.modifyHoursActivity(prevActivity, newStart, newEnd); Day test = CreateDay(); List <Activity> expected = test.L_activity; for (int i = 6; i <= 9; i++) { expected[i] = new Inside(6, 9, target.Map_hq, "coucou"); } Assert.AreEqual(expected, target.L_activity); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
/// <summary> /// Clones the block sounds. /// </summary> /// <returns></returns> public BlockSounds Clone() { BlockSounds sounds = new BlockSounds() { Walk = Walk == null ? null : Walk.Clone(), Inside = Inside == null ? null : Inside.Clone(), Break = Break == null ? null : Break.Clone(), Place = Place == null ? null : Place.Clone(), Hit = Hit == null ? null : Hit.Clone(), Ambient = Ambient == null ? null : Ambient.Clone(), AmbientBlockCount = AmbientBlockCount }; foreach (var val in ByTool) { sounds.ByTool[val.Key] = val.Value.Clone(); } return(sounds); }
void PushAccGrave(Inside inside) { if ((inside & (Inside.PreProcessor | Inside.Comment | Inside.CharLiteral | Inside.StringLiteral | Inside.VerbatimString)) != 0) { return; } if (inside == Inside.AlternateVerbatimString) { if (!isEscaped) { keyword = stack.PeekKeyword; stack.Pop(); } } else { stack.Push(Inside.AlternateVerbatimString, keyword, curLineNr, 0); } }
void PushSQuote(Inside inside) { if (inside == Inside.CharLiteral) { // check that it's not escaped if (isEscaped) { return; } keyword = stack.PeekKeyword(0); stack.Pop(); return; } if ((inside & (Inside.PreProcessor | Inside.String | Inside.Comment)) != 0) { // won't be starting a CharLiteral, so ignore it return; } // push a new char literal onto the stack stack.Push(Inside.CharLiteral, keyword, curLineNr, 0); }
public void Push (Inside inside, string keyword, int lineNr, int nSpaces) { StringBuilder indentBuilder; int sp = size - 1; Node node; int n = 0; indentBuilder = new StringBuilder (); if ((inside & (Inside.Attribute | Inside.ParenList)) != 0) { if (size > 0 && stack[sp].Inside == inside) { while (sp >= 0) { if ((stack[sp].Inside & Inside.FoldedOrBlock) != 0) break; sp--; } if (sp >= 0) { indentBuilder.Append (stack[sp].Indent); if (stack[sp].LineNr == lineNr) n = stack[sp].NumSpaces; } } else { while (sp >= 0) { if ((stack[sp].Inside & Inside.FoldedBlockOrCase) != 0) { indentBuilder.Append (stack[sp].Indent); break; } sp--; } } if (nSpaces - n <= 0) { indentBuilder.Append ('\t'); } else { indentBuilder.Append (' ', nSpaces - n); } } else if (inside == Inside.MultiLineComment) { if (size > 0) { indentBuilder.Append (stack[sp].Indent); if (stack[sp].LineNr == lineNr) n = stack[sp].NumSpaces; } indentBuilder.Append (' ', nSpaces - n); } else if (inside == Inside.Case) { while (sp >= 0) { if ((stack[sp].Inside & Inside.FoldedOrBlock) != 0) { indentBuilder.Append (stack[sp].Indent); break; } sp--; } if (engine.policy.IndentSwitchBody) indentBuilder.Append ('\t'); nSpaces = 0; } else if ((inside & (Inside.FoldedOrBlock)) != 0) { while (sp >= 0) { if ((stack[sp].Inside & Inside.FoldedBlockOrCase) != 0) { indentBuilder.Append (stack[sp].Indent); break; } sp--; } Inside parent = size > 0 ? stack[size - 1].Inside : Inside.Empty; // This is a workaround to make anonymous methods indent nicely if (parent == Inside.ParenList) stack[size - 1].Indent = indentBuilder.ToString (); if (inside == Inside.FoldedStatement) { indentBuilder.Append ('\t'); } else if (inside == Inside.Block) { if (parent != Inside.Case || nSpaces != -1) indentBuilder.Append ('\t'); } nSpaces = 0; } else if ((inside & (Inside.PreProcessor | Inside.StringOrChar)) != 0) { // if these fold, do not indent nSpaces = 0; //pop regions back out if (keyword == "region" || keyword == "endregion") { for (; sp >= 0; sp--) { if ((stack[sp].Inside & Inside.FoldedBlockOrCase) != 0) { indentBuilder.Append (stack[sp].Indent); break; } } } } else if (inside == Inside.LineComment || inside == Inside.DocComment) { // can't actually fold, but we still want to push it onto the stack nSpaces = 0; } else { // not a valid argument? throw new ArgumentOutOfRangeException (); } node.Indent = indentBuilder.ToString (); node.Keyword = keyword; node.NumSpaces = nSpaces; node.LineNr = lineNr; node.Inside = inside; if (size == stack.Length) Array.Resize <Node> (ref stack, 2 * size); stack[size++] = node; }
public void Push(char ch) { if (readPreprocessorExpression) { wordBuf.Append(ch); } if (inside.HasFlag(Inside.VerbatimString) && pc == '"' && ch != '"') { inside &= ~Inside.StringLiteral; } switch (ch) { case '#': if (IsLineStart) inside = Inside.PreProcessor; break; case '/': if (IsInStringOrChar || IsInPreProcessorComment) break; if (pc == '/') { if (inside.HasFlag(Inside.Comment)) { inside |= Inside.DocComment; } else { inside |= Inside.Comment; } } break; case '*': if (IsInStringOrChar || IsInComment || IsInPreProcessorComment) break; if (pc == '/') inside |= Inside.MultiLineComment; break; case ' ': currentIndent.Append(' '); break; case '\t': var nextTabStop = (col - 1 + textEditorOptions.IndentSize) / textEditorOptions.IndentSize; col = 1 + nextTabStop * textEditorOptions.IndentSize; currentIndent.Append('\t'); offset++; return; case '\r': if (readPreprocessorExpression) { if (!eval(wordBuf.ToString())) inside |= Inside.PreProcessorComment; } inside &= ~(Inside.Comment | Inside.String | Inside.CharLiteral | Inside.PreProcessor); CheckKeyword(wordBuf.ToString()); wordBuf.Length = 0; indent.Push(indentDelta); indentDelta = new Indent(textEditorOptions); if (addContinuation) { indent.Push(IndentType.Continuation); } thisLineindent = indent.Clone(); addContinuation = false; IsLineStart = true; readPreprocessorExpression = false; col = 1; line++; currentIndent.Length = 0; break; case '\n': if (pc == '\r') break; goto case '\r'; case '"': if (IsInComment || IsInPreProcessorComment) break; if (inside.HasFlag(Inside.StringLiteral)) { if (pc != '\\') inside &= ~Inside.StringLiteral; break; } if (pc == '@') { inside |= Inside.VerbatimString; } else { inside |= Inside.StringLiteral; } break; case '<': case '[': case '(': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) break; parenStack.Push(new TextLocation(line, col)); popNextParenBlock = true; indent.Push(IndentType.Block); break; case '>': case ']': case ')': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) break; if (popNextParenBlock && parenStack.Count > 0) parenStack.Pop(); if (indent.Count > 0) indent.Pop(); indent.ExtraSpaces = 0; break; case ',': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) break; if (parenStack.Count > 0 && parenStack.Peek().Line == line) { if (indent.Count > 0) indent.Pop(); popNextParenBlock = false; indent.ExtraSpaces = parenStack.Peek().Column - 1 - thisLineindent.CurIndent; } break; case '{': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) break; currentBody = nextBody; if (indent.Count > 0 && indent.Peek() == IndentType.Continuation) indent.Pop(); addContinuation = false; AddIndentation(currentBody); break; case '}': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) break; if (indentDelta.CurIndent > 0) { indentDelta.Pop(); if (indentDelta.Count > 0 && indentDelta.Peek() == IndentType.Continuation) indentDelta.Pop(); } else { if (thisLineindent.Count > 0) thisLineindent.Pop(); if (indent.Count > 0) indent.Pop(); } break; case ';': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) break; if (indent.Count > 0 && indent.Peek() == IndentType.Continuation) indent.Pop(); break; case '\'': if (IsInComment || inside.HasFlag(Inside.StringLiteral) || IsInPreProcessorComment) break; if (inside.HasFlag(Inside.CharLiteral)) { if (pc != '\\') inside &= ~Inside.CharLiteral; } else { inside &= Inside.CharLiteral; } break; } if (!IsInComment && !IsInStringOrChar && !readPreprocessorExpression) { if ((wordBuf.Length == 0 ? char.IsLetter(ch) : char.IsLetterOrDigit(ch)) || ch == '_') { wordBuf.Append(ch); } else { if (inside.HasFlag(Inside.PreProcessor)) { if (wordBuf.ToString() == "endif") { inside &= ~Inside.PreProcessorComment; } else if (wordBuf.ToString() == "if") { readPreprocessorExpression = true; } else if (wordBuf.ToString() == "elif") { inside &= ~Inside.PreProcessorComment; readPreprocessorExpression = true; } } else { CheckKeyword(wordBuf.ToString()); } wordBuf.Length = 0; } } if (addContinuation) { indent.Push(IndentType.Continuation); addContinuation = false; } IsLineStart &= ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'; pc = ch; if (ch != '\n' && ch != '\r') col++; offset++; }
void PushCloseParen (Inside inside) { if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) return; if (inside != Inside.ParenList) { //Console.WriteLine ("can't pop a '(' if we ain't got one?"); return; } // pop this paren list off the stack keyword = stack.PeekKeyword (0); stack.Pop (); }
void PushCloseBrace (Inside inside) { if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) return; if (inside != Inside.Block && inside != Inside.Case) { if (stack.PeekInside (0) == Inside.FoldedStatement) { while (stack.PeekInside (0) == Inside.FoldedStatement) { stack.Pop (); } curIndent = stack.PeekIndent (0); keyword = stack.PeekKeyword (0); inside = stack.PeekInside (0); } //Console.WriteLine ("can't pop a '{' if we ain't got one?"); if (inside != Inside.Block && inside != Inside.Case) return; } if (inside == Inside.Case) { curIndent = stack.PeekIndent (1); keyword = stack.PeekKeyword (0); inside = stack.PeekInside (1); stack.Pop (); } if (inside == Inside.ParenList) { curIndent = stack.PeekIndent (0); keyword = stack.PeekKeyword (0); inside = stack.PeekInside (0); } // pop this block off the stack keyword = stack.PeekKeyword (0); if (keyword != "case" && keyword != "default") keyword = String.Empty; stack.Pop (); while (stack.PeekInside (0) == Inside.FoldedStatement) { stack.Pop (); } if (firstNonLwsp == -1) { needsReindent = true; TrimIndent (); } }
void PushColon (Inside inside) { if (inside != Inside.Block && inside != Inside.Case) return; // can't be a case/label if there's no preceeding text if (wordStart == -1) return; // goto-label or case statement if (keyword == "case" || keyword == "default") { // case (or default) statement if (stack.PeekKeyword (0) != "switch") return; if (inside == Inside.Case) { stack.Pop (); string newIndent = stack.PeekIndent (0); if (curIndent != newIndent) { curIndent = newIndent; needsReindent = true; } } if (!policy.IndentSwitchBody) { needsReindent = true; TrimIndent (); } stack.Push (Inside.Case, "switch", curLineNr, 0); } else if (canBeLabel) { //GotoLabelIndentStyle style = FormattingProperties.GotoLabelIndentStyle; GotoLabelIndentStyle style = GotoLabelIndentStyle.OneLess; // indent goto labels as specified switch (style) { case GotoLabelIndentStyle.LeftJustify: needsReindent = true; // curIndent = " "; break; case GotoLabelIndentStyle.OneLess: needsReindent = true; TrimIndent (); // curIndent += " "; break; default: break; } canBeLabel = false; } else if (pc == ':') { // :: operator, need to undo the "unindent label" operation we did for the previous ':' curIndent = stack.PeekIndent (0); needsReindent = true; } }
void PushOpenSq (Inside inside) { int n = 1; if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) return; // push a new attribute onto the stack if (firstNonLwsp != -1) n += linebuf.Length - firstNonLwsp; stack.Push (Inside.Attribute, keyword, curLineNr, n); }
void PushOpenBrace(Inside inside) { if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) { return; } // push a new block onto the stack if (inside == Inside.FoldedStatement) { string pKeyword; if (firstNonLwsp == -1) { pKeyword = stack.PeekKeyword(0); stack.Pop(); } else { pKeyword = keyword; } while (true) { if (stack.PeekInside(0) != Inside.FoldedStatement) { break; } string kw = stack.PeekKeyword(0); stack.Pop(); TrimIndent(); if (!string.IsNullOrEmpty(kw)) { pKeyword = kw; break; } } if (firstNonLwsp == -1) { curIndent = stack.PeekIndent(0); } stack.Push(Inside.Block, pKeyword, curLineNr, 0); } else if (inside == Inside.Case && (keyword == "default" || keyword == "case")) { if (curLineNr == stack.PeekLineNr(0) || firstNonLwsp == -1) { // e.g. "case 0: {" or "case 0:\n{" stack.Push(Inside.Block, keyword, curLineNr, -1); if (firstNonLwsp == -1) { TrimIndent(); } } else { stack.Push(Inside.Block, keyword, curLineNr, 0); } } else { stack.Push(Inside.Block, keyword, curLineNr, 0); // Destroys one lined expression block 'var s = "".Split (new char[] {' '});' //if (inside == Inside.ParenList) // TrimIndent (); } keyword = String.Empty; if (firstNonLwsp == -1) { needsReindent = true; } }
void PushQuote (Inside inside) { Inside type; // ignore if in these if ((inside & (Inside.PreProcessor | Inside.Comment | Inside.CharLiteral)) != 0) return; if (inside == Inside.VerbatimString) { if (popVerbatim) { // back in the verbatim-string-literal token popVerbatim = false; } else { /* need to see the next char before we pop the * verbatim-string-literal */ popVerbatim = true; } } else if (inside == Inside.StringLiteral) { // check that it isn't escaped if (!isEscaped) { keyword = stack.PeekKeyword (0); stack.Pop (); } } else { // FoldedStatement, Block, Attribute or ParenList if (pc == '@') type = Inside.VerbatimString; else type = Inside.StringLiteral; // push a new string onto the stack stack.Push (type, keyword, curLineNr, 0); } }
public void Command(string[] arg) { Domain domain = sparta.domain; Grid grid = sparta.grid; int narg = arg.Length; if (!domain.box_exist) { sparta.DumpError("Cannot create grid before simulation box is defined"); } if (grid.exist) { sparta.DumpError("Cannot create grid when grid is already defined"); } grid.exist = true; if (narg < 3) { sparta.DumpError("Illegal create_grid command"); } int nx = int.Parse(arg[0]); int ny = int.Parse(arg[1]); int nz = int.Parse(arg[2]); if (nx < 1 || ny < 1 || nz < 1) { sparta.DumpError("Illegal create_grid command"); } if (domain.dimension == 2 && nz != 1) { sparta.DumpError("Create_grid nz value must be 1 for a 2d simulation"); } dimension = domain.dimension; int nlevels = 1; Bstyle bstyle = Bstyle.NONE; int px = 0; int py = 0; int pz = 0; int order; Inside inside = Inside.ANY; int iarg = 3; while (iarg < narg) { sparta.DumpError("Complete CreateGrid.Command optional arguments"); iarg++; } if (bstyle == Bstyle.NONE) { bstyle = Bstyle.LEVEL; } if (bstyle == Bstyle.BLOCK) { sparta.DumpError("Complete CreateGrid.Command Bstyle.Block"); } double time1 = Timer.getTime(); int level = 1; int xlo, xhi, ylo, yhi, zlo, zhi; xlo = xhi = ylo = yhi = zlo = zhi = 1; iarg = 3; Region region = null; Int64 count = 0; int pnx, pny, pnz, ix, iy, iz, nbits, proc; bool pflag; int m, nth, idgrandparent, idparent, idchild; double[] lo = new double[3], hi = new double[3]; Grid.ParentCell p; while (true) { if (level == 1) { grid.AddParentCell(0, -1, nx, ny, nz, domain.boxlo, domain.boxhi); } else { int nparent = grid.nparent; int prevlevel = level - 2; for (int igrandparent = 0; igrandparent < nparent; igrandparent++) { if (grid.pcells[igrandparent].level != prevlevel) { continue; } p = grid.pcells[igrandparent]; idgrandparent = p.id; nbits = p.nbits; pnx = p.nx; pny = p.ny; pnz = p.nz; m = 0; for (iz = 0; iz < pnz; iz++) { for (iy = 0; iy < pny; iy++) { for (ix = 0; ix < pnx; ix++) { m++; idparent = idgrandparent | (m << nbits); grid.IdChildLohi(igrandparent, m, lo, hi); if (region != null) { pflag = CellInRegion(lo, hi, region, inside); } else { pflag = true; if (ix + 1 < xlo || ix + 1 > xhi) { pflag = false; } if (iy + 1 < ylo || iy + 1 > yhi) { pflag = false; } if (iz + 1 < zlo || iz + 1 > zhi) { pflag = false; } } if (pflag) { grid.AddParentCell(idparent, igrandparent, nx, ny, nz, lo, hi); } else { if (count % 1 == 0) { grid.AddChildCell(idparent, igrandparent, lo, hi); } count++; } } } } } } // final level, add current level cells as child cells // loop over all parent cells to find ones at previous level // use their info to generate my child cells at this level // if BSTYLE is set, there is only 1 level, create proc's cells directly if (level == nlevels) { List <Grid.ParentCell> pcells = grid.pcells; int nparent = grid.nparent; int prevlevel = level - 1; for (int iparent = 0; iparent < nparent; iparent++) { if (pcells[iparent].level != prevlevel) { continue; } p = pcells[iparent]; idparent = p.id; nbits = p.nbits; nx = p.nx; ny = p.ny; nz = p.nz; if (bstyle == Bstyle.LEVEL) { int ntotal = (int)nx * ny * nz; int firstproc = (int)count % 1; int ifirst = 0 - firstproc + 1; if (ifirst <= 0) { ifirst += 1; } for (m = ifirst; m <= ntotal; m += 1) { idchild = idparent | (m << nbits); grid.IdChildLohi(iparent, m, lo, hi); grid.AddChildCell(idchild, iparent, lo, hi); } count += ntotal; // loop over all child cells // convert M to Nth based on order // assign each cell to proc based on Nth and STRIDE or CLUMP } else { sparta.DumpError("CreateGrid->Command: more Bstyle"); } } break; } if (level == nlevels) { break; } level++; switch (arg[iarg]) { //case "level" default: sparta.DumpError("CreateGrid->Command: complete this"); break; } } List <Grid.ParentCell> pcells1 = grid.pcells; int nparent1 = grid.nparent; for (int i = 1; i < nparent1; i++) { pcells1[pcells1[i].iparent].grandparent = 1; } if (bstyle == Bstyle.CLUMP || bstyle == Bstyle.BLOCK) { grid.clumped = true; } else { grid.clumped = false; } double time2 = Timer.getTime(); grid.SetupOwned(); grid.AcquireGhosts(); grid.FindNeighbors(); grid.CheckUniform(); double time3 = Timer.getTime(); double time_total = time3 - time1; StringBuilder sb = new StringBuilder(); sb.AppendFormat("Create {0} child grid cells\n", grid.ncell); sb.AppendFormat(" parent cells = {0}\n", grid.nparent); sb.AppendFormat(" CPU time = {0} secs\n", time_total); sb.AppendFormat(" create/ghost percent = {0} {1}\n", 100.0 * (time2 - time1) / time_total, 100.0 * (time3 - time2) / time_total); sparta.DumpMessage(sb.ToString()); }
void PushNewLine(Inside inside) { top: switch (inside) { case Inside.Shebang: case Inside.PreProcessor: // pop the preprocesor state unless the eoln is escaped if (rc != '\\') { keyword = stack.PeekKeyword; stack.Pop(); } break; case Inside.BlockComment: case Inside.NestedComment: // nothing to do break; case Inside.DocComment: case Inside.LineComment: // pop the line comment keyword = stack.PeekKeyword; stack.Pop(); inside = stack.PeekInside(0); goto top; case Inside.AlternateVerbatimString: case Inside.VerbatimString: // nothing to do break; case Inside.StringLiteral: if (isEscaped) { /* I don't think c# allows breaking a * normal string across lines even * when escaping the carriage * return... but how else should we * handle this? */ break; } /* not escaped... error!! but what can we do, * eh? allow folding across multiple lines I * guess... */ break; case Inside.CharLiteral: /* this is an error... what to do? guess we'll * just pretend it never happened */ break; case Inside.Attribute: // nothing to do break; case Inside.ParenList: // nothing to do break; default: // Empty, FoldedStatement, and Block switch (rc) { case '\0': // nothing entered on this line break; case ':': if (keyword == DTokens.Case || keyword == DTokens.Default || !canBeLabel || inside == Inside.Empty) { break; } PushFoldedStatement(); break; case '[': // handled elsewhere break; case ']': // handled elsewhere break; case '(': // handled elsewhere break; case '{': // handled elsewhere break; case '}': // handled elsewhere break; case ';': // handled elsewhere break; case ',': if ((stack.PeekInside(0) == Inside.Block && stack.PeekKeyword == DTokens.Enum) || (inside == Inside.FoldedStatement || inside == Inside.SquareBracketList) ) { break; } goto default; default: if (stack.PeekLineNr(0) == curLineNr) { // is this right? I don't remember why I did this... break; } if (linebuf.Length > 0) { int k = 0; for (; linebuf[k] == ' ' || linebuf[k] == '\t'; k++) { ; } if (linebuf [k] == '@') { break; } } if (inside == Inside.Block) { var peekKw = stack.PeekKeyword; if (peekKw == DTokens.Enum //peekKw == DTokens.Struct || peekKw == DTokens.Assign || peekKw == DTokens.Import ) { /* When breaking on DTokens.Assign here, * stuff like myDeleg = (){...}; will cause issues inside the anonymous method body! */ // just variable/value declarations break; } } else if (inside == Inside.SquareBracketList) { break; } PushFoldedStatement(); break; } break; } linebuf.Length = 0; canBeLabel = true; beganInside = stack.PeekInside(0); curIndent = stack.PeekIndent(0); firstNonLwsp = -1; lastNonLwsp = -1; wordStart = -1; prc = '\0'; pc = '\0'; rc = '\0'; curLineNr++; cursor++; }
public void Push (Inside inside, byte keyword, int lineNr, int nSpaces) { int sp = size - 1; Node node; int n = 0; var indentBuilder = new StringBuilder (); switch (inside) { case Inside.Attribute: case Inside.ParenList: if (size > 0 && stack[sp].inside == inside) { if (!this.ie.Options.NestedCallIndent) { while (sp >= 0) { if ((stack [sp].inside & Inside.FoldedOrBlock) != 0) break; sp--; } } if (sp >= 0) { indentBuilder.Append (stack[sp].indent); if (stack[sp].lineNr == lineNr) n = stack[sp].nSpaces; } } else { while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedBlockOrCase) != 0) { indentBuilder.Append (stack[sp].indent); break; } sp--; } } if (nSpaces - n <= 0) { indentBuilder.Append ('\t'); } else { indentBuilder.Append (' ', nSpaces - n); } break; case Inside.NestedComment: case Inside.BlockComment: if (size > 0) { indentBuilder.Append (stack[sp].indent); if (stack[sp].lineNr == lineNr) n = stack[sp].nSpaces; } indentBuilder.Append (' ', nSpaces - n); break; case Inside.Case: while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedOrBlock) != 0) { indentBuilder.Append (stack[sp].indent); break; } sp--; } if (ie.Options.IndentSwitchBody) indentBuilder.Append ('\t'); nSpaces = 0; break; case Inside.FoldedStatement: case Inside.Block: case Inside.SquareBracketList: // FoldedOrBlock while (sp >= 0) { if ((stack [sp].inside & Inside.FoldedBlockOrCase) != 0 || // If there's myFoo( \n { \n, keep the ( indent + 1 tab // If there's myFoo( \n [ \n, keep the ( indent only if ie.Options.KeepArgumentIndentOnSquareBracketOpen says so. ((inside != Inside.SquareBracketList || ie.Options.KeepArgumentIndentOnSquareBracketOpen) && stack[sp].inside == Inside.ParenList)) { indentBuilder.Append (stack[sp].indent); break; } sp--; } Inside parent = size > 0 ? stack[size - 1].inside : Inside.Empty; // This is a workaround to make anonymous methods indent nicely if (parent == Inside.ParenList && inside != Inside.SquareBracketList) stack[size - 1].indent = indentBuilder.ToString (); if (inside == Inside.FoldedStatement) { indentBuilder.Append ('\t'); } else if (inside == Inside.Block || inside == Inside.SquareBracketList) { if (parent != Inside.Case || nSpaces != -1) indentBuilder.Append ('\t'); } nSpaces = 0; break; case Inside.Shebang: case Inside.PreProcessor: case Inside.CharLiteral: case Inside.StringLiteral: case Inside.VerbatimString: case Inside.AlternateVerbatimString: // if these fold, do not indent case Inside.LineComment: // can't actually fold, but we still want to push it onto the stack case Inside.DocComment: nSpaces = 0; break; default: throw new ArgumentOutOfRangeException (); } // Replace additionally inserted spaces with tabs if (!ie.tabsToSpaces && !ie.keepAlignmentSpaces) { n = 0; for(int i = 0; i < indentBuilder.Length; i++) { if (indentBuilder[i] == ' ') { n++; if (n >= ie.indentWidth) { // Decrement the space count as we're having tabs now. nSpaces -= n; i -= n - 1; indentBuilder.Remove(i, n); indentBuilder.Insert(i, '\t'); n = 0; } } else n = 0; } } node.indent = indentBuilder.ToString (); node.keyword = keyword; node.nSpaces = nSpaces; node.lineNr = lineNr; node.inside = inside; node.ifelseBackupStack = null; if (size == stack.Length) Array.Resize <Node> (ref stack, 2 * size); stack[size++] = node; }
public void Push (Inside inside, byte keyword, int lineNr, int nSpaces, string indent) { Node node; node.indent = indent; node.keyword = keyword; node.nSpaces = nSpaces; node.lineNr = lineNr; node.inside = inside; node.ifelseBackupStack = null; if (size == stack.Length) Array.Resize <Node> (ref stack, 2 * size); stack[size++] = node; }
void PushColon(Inside inside) { if (inside != Inside.Block && inside != Inside.Case) { return; } // can't be a case/label if there's no preceeding text if (wordStart == -1) { return; } // goto-label or case statement if (keyword == "case" || keyword == "default") { // case (or default) statement if (stack.PeekKeyword(0) != "switch") { return; } if (inside == Inside.Case) { stack.Pop(); string newIndent = stack.PeekIndent(0); if (curIndent != newIndent) { curIndent = newIndent; needsReindent = true; } } if (!policy.IndentSwitchBody) { needsReindent = true; TrimIndent(); } stack.Push(Inside.Case, "switch", curLineNr, 0); } else if (canBeLabel) { //GotoLabelIndentStyle style = FormattingProperties.GotoLabelIndentStyle; GotoLabelIndentStyle style = GotoLabelIndentStyle.OneLess; // indent goto labels as specified switch (style) { case GotoLabelIndentStyle.LeftJustify: needsReindent = true; //curIndent = " "; break; case GotoLabelIndentStyle.OneLess: needsReindent = true; TrimIndent(); //curIndent += " "; break; default: break; } canBeLabel = false; } else if (pc == ':') { // :: operator, need to undo the "unindent label" operation we did for the previous ':' curIndent = stack.PeekIndent(0); needsReindent = true; } }
public void Push (Inside inside, byte keyword, int lineNr, int nSpaces) { int sp = size - 1; Node node; int n = 0; var indentBuilder = new StringBuilder (); if ((inside & (Inside.Attribute | Inside.ParenList)) != 0) { if (size > 0 && stack[sp].inside == inside) { while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedOrBlock) != 0) break; sp--; } if (sp >= 0) { indentBuilder.Append (stack[sp].indent); if (stack[sp].lineNr == lineNr) n = stack[sp].nSpaces; } } else { while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedBlockOrCase) != 0) { indentBuilder.Append (stack[sp].indent); break; } sp--; } } if (nSpaces - n <= 0) { indentBuilder.Append ('\t'); } else { indentBuilder.Append (' ', nSpaces - n); } } else if ((inside & (Inside.NestedComment | Inside.BlockComment)) != 0) { if (size > 0) { indentBuilder.Append (stack[sp].indent); if (stack[sp].lineNr == lineNr) n = stack[sp].nSpaces; } indentBuilder.Append (' ', nSpaces - n); } else if (inside == Inside.Case) { while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedOrBlock) != 0) { indentBuilder.Append (stack[sp].indent); break; } sp--; } if (ie.Options.IndentSwitchBody) indentBuilder.Append ('\t'); nSpaces = 0; } else if ((inside & (Inside.FoldedOrBlock)) != 0) { while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedBlockOrCase) != 0) { // Optional: Check for Inside.ParenList to align the following lines like the previous line indentBuilder.Append (stack[sp].indent); break; } sp--; } Inside parent = size > 0 ? stack[size - 1].inside : Inside.Empty; // This is a workaround to make anonymous methods indent nicely if (parent == Inside.ParenList) stack[size - 1].indent = indentBuilder.ToString (); if (inside == Inside.FoldedStatement) { indentBuilder.Append ('\t'); } else if (inside == Inside.Block || inside == Inside.SquareBracketList) { if (parent != Inside.Case || nSpaces != -1) indentBuilder.Append ('\t'); } nSpaces = 0; } else if ((inside & (Inside.Shebang | Inside.PreProcessor | Inside.StringOrChar)) != 0) { // if these fold, do not indent nSpaces = 0; } else if (inside == Inside.LineComment || inside == Inside.DocComment) { // can't actually fold, but we still want to push it onto the stack nSpaces = 0; } else { // not a valid argument? throw new ArgumentOutOfRangeException (); } // Replace additionally inserted spaces with tabs if (!ie.tabsToSpaces && !ie.keepAlignmentSpaces) { n = 0; for(int i = 0; i < indentBuilder.Length; i++) { if (indentBuilder[i] == ' ') { n++; if (n >= ie.indentWidth) { // Decrement the space count as we're having tabs now. nSpaces -= n; i -= n - 1; indentBuilder.Remove(i, n); indentBuilder.Insert(i, '\t'); n = 0; } } else n = 0; } } node.indent = indentBuilder.ToString (); node.keyword = keyword; node.nSpaces = nSpaces; node.lineNr = lineNr; node.inside = inside; if (size == stack.Length) Array.Resize <Node> (ref stack, 2 * size); stack[size++] = node; }
void PushNewLine(Inside inside) { top: switch (inside) { case Inside.PreProcessor: // pop the preprocesor state unless the eoln is escaped if (rc != '\\') { keyword = stack.PeekKeyword(0); stack.Pop(); } break; case Inside.MultiLineComment: // nothing to do break; case Inside.DocComment: case Inside.LineComment: // pop the line comment keyword = stack.PeekKeyword(0); stack.Pop(); inside = stack.PeekInside(0); goto top; case Inside.VerbatimString: // nothing to do break; case Inside.StringLiteral: if (isEscaped) { /* I don't think c# allows breaking a * normal string across lines even * when escaping the carriage * return... but how else should we * handle this? */ break; } /* not escaped... error!! but what can we do, * eh? allow folding across multiple lines I * guess... */ break; case Inside.CharLiteral: /* this is an error... what to do? guess we'll * just pretend it never happened */ break; case Inside.Attribute: // nothing to do break; case Inside.ParenList: // nothing to do break; default: // Empty, FoldedStatement, and Block switch (rc) { case '\0': // nothing entered on this line break; case ':': canBeLabel = canBeLabel && inside != Inside.FoldedStatement; if ((keyword == "default" || keyword == "case") || canBeLabel) { break; } PushFoldedStatement(); break; case '[': // handled elsewhere break; case ']': // handled elsewhere break; case '(': // handled elsewhere break; case '{': // handled elsewhere break; case '}': // handled elsewhere break; case ';': // handled elsewhere break; case ',': // avoid indenting if we are in a list break; default: if (stack.PeekLineNr(0) == curLineNr) { // is this right? I don't remember why I did this... break; } if (inside == Inside.Block) { if (stack.PeekKeyword(0) == "struct" || stack.PeekKeyword(0) == "enum" || stack.PeekKeyword(0) == "=") { // just variable/value declarations break; } } PushFoldedStatement(); break; } break; } linebuf.Length = 0; beganInside = stack.PeekInside(0); curIndent = stack.PeekIndent(0); canBeLabel = true; firstNonLwsp = -1; lastNonLwsp = -1; wordStart = -1; prc = '\0'; pc = '\0'; rc = '\0'; curLineNr++; cursor++; }
void PushStar (Inside inside) { int n; if (pc != '/') return; // got a "/*" - might start a MultiLineComment if ((inside & (Inside.StringOrChar | Inside.Comment)) != 0) { // if ((inside & Inside.MultiLineComment) != 0) // Console.WriteLine ("Watch out! Nested /* */ comment detected!"); return; } // push a new multiline comment onto the stack if (inside != Inside.PreProcessor) n = linebuf.Length - firstNonLwsp; else n = linebuf.Length; stack.Push (Inside.MultiLineComment, keyword, curLineNr, n); // drop the previous '/': it belongs to this comment block rc = prc; }
void PushColon(Inside inside) { if (inside != Inside.Block && inside != Inside.Case) { return; } // can't be a case/label if there's no preceeding text if (wordStart == -1) { return; } // >enum< : uint { a,b,c } if (keyword == DTokens.Enum) { return; } // goto-label or case statement if (keyword == DTokens.Case || keyword == DTokens.Default) { // case (or default) statement if (stack.PeekKeyword != DTokens.Switch) { return; } if (inside == Inside.Case) { stack.Pop(); string newIndent = stack.PeekIndent(0); if (curIndent != newIndent) { curIndent = newIndent; needsReindent = true; } } if (!Policy.IndentSwitchBody) { needsReindent = true; TrimIndent(); } if (Policy.IndentCases) { stack.Push(Inside.Case, DTokens.Switch, curLineNr, 0); } } else if (canBeLabel) { var style = Policy.LabelIndentStyle; // indent goto labels as specified switch (style) { case GotoLabelIndentStyle.LeftJustify: needsReindent = true; // curIndent = " "; break; case GotoLabelIndentStyle.OneLess: needsReindent = true; TrimIndent(); // curIndent += " "; break; default: break; } canBeLabel = false; } }
void PushSQuote (Inside inside) { if (inside == Inside.CharLiteral) { // check that it's not escaped if (isEscaped) return; keyword = stack.PeekKeyword (0); stack.Pop (); return; } if ((inside & (Inside.PreProcessor | Inside.String | Inside.Comment)) != 0) { // won't be starting a CharLiteral, so ignore it return; } // push a new char literal onto the stack stack.Push (Inside.CharLiteral, keyword, curLineNr, 0); }
public void Push(Inside inside, string keyword, int lineNr, int nSpaces) { StringBuilder indentBuilder; int sp = size - 1; Node node; int n = 0; indentBuilder = new StringBuilder(); if ((inside & (Inside.Attribute | Inside.ParenList)) != 0) { if (size > 0 && stack[sp].Inside == inside) { while (sp >= 0) { if ((stack[sp].Inside & Inside.FoldedOrBlock) != 0) { break; } sp--; } if (sp >= 0) { indentBuilder.Append(stack[sp].Indent); if (stack[sp].LineNr == lineNr) { n = stack[sp].NumSpaces; } } } else { while (sp >= 0) { if ((stack[sp].Inside & Inside.FoldedBlockOrCase) != 0) { indentBuilder.Append(stack[sp].Indent); break; } sp--; } } if (nSpaces - n <= 0) { indentBuilder.Append('\t'); } else { indentBuilder.Append(' ', nSpaces - n); } } else if (inside == Inside.MultiLineComment) { if (size > 0) { indentBuilder.Append(stack[sp].Indent); if (stack[sp].LineNr == lineNr) { n = stack[sp].NumSpaces; } } indentBuilder.Append(' ', nSpaces - n); } else if (inside == Inside.Case) { while (sp >= 0) { if ((stack[sp].Inside & Inside.FoldedOrBlock) != 0) { indentBuilder.Append(stack[sp].Indent); break; } sp--; } if (engine.policy.IndentSwitchBody) { indentBuilder.Append('\t'); } nSpaces = 0; } else if ((inside & (Inside.FoldedOrBlock)) != 0) { while (sp >= 0) { if ((stack[sp].Inside & Inside.FoldedBlockOrCase) != 0) { indentBuilder.Append(stack[sp].Indent); break; } sp--; } Inside parent = size > 0 ? stack[size - 1].Inside : Inside.Empty; // This is a workaround to make anonymous methods indent nicely if (parent == Inside.ParenList) { stack[size - 1].Indent = indentBuilder.ToString(); } if (inside == Inside.FoldedStatement) { indentBuilder.Append('\t'); } else if (inside == Inside.Block) { if (parent != Inside.Case || nSpaces != -1) { indentBuilder.Append('\t'); } } nSpaces = 0; } else if ((inside & (Inside.PreProcessor | Inside.StringOrChar)) != 0) { // if these fold, do not indent nSpaces = 0; //pop regions back out if (keyword == "region" || keyword == "endregion") { for (; sp >= 0; sp--) { if ((stack[sp].Inside & Inside.FoldedBlockOrCase) != 0) { indentBuilder.Append(stack[sp].Indent); break; } } } } else if (inside == Inside.LineComment || inside == Inside.DocComment) { // can't actually fold, but we still want to push it onto the stack nSpaces = 0; } else { // not a valid argument? throw new ArgumentOutOfRangeException(); } node.Indent = indentBuilder.ToString(); node.Keyword = keyword; node.NumSpaces = nSpaces; node.LineNr = lineNr; node.Inside = inside; if (size == stack.Length) { Array.Resize <Node> (ref stack, 2 * size); } stack[size++] = node; }
void PushSemicolon (Inside inside) { if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) return; if (inside == Inside.FoldedStatement) { // chain-pop folded statements while (stack.PeekInside (0) == Inside.FoldedStatement) stack.Pop (); } keyword = String.Empty; }
void PushStar(Inside inside) { if (pc != '/') return; // got a "/*" - might start a MultiLineComment if ((inside & (Inside.String | Inside.Comment)) != 0) return; // push a new multiline comment onto the stack int n = linebuf.Length - firstNonLwsp; stack.Push (Inside.MultiLineComment, keyword, currLineNumber, n); // drop the previous '/': it belongs to this comment block rc = prc; }
void PushOpenParen (Inside inside) { int n = 1; if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) return; // push a new paren list onto the stack if (firstNonLwsp != -1) n += linebuf.Length - firstNonLwsp; stack.Push (Inside.ParenList, keyword, curLineNr, n); keyword = String.Empty; }
public void Push(Inside inside, byte keyword, int lineNr, int nSpaces) { int sp = size - 1; Node node; int n = 0; var indentBuilder = new StringBuilder(); if ((inside & (Inside.Attribute | Inside.ParenList)) != 0) { if (size > 0 && stack[sp].inside == inside) { while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedOrBlock) != 0) { break; } sp--; } if (sp >= 0) { indentBuilder.Append(stack[sp].indent); if (stack[sp].lineNr == lineNr) { n = stack[sp].nSpaces; } } } else { while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedBlockOrCase) != 0) { indentBuilder.Append(stack[sp].indent); break; } sp--; } } if (nSpaces - n <= 0) { indentBuilder.Append('\t'); } else { indentBuilder.Append(' ', nSpaces - n); } } else if ((inside & (Inside.NestedComment | Inside.BlockComment)) != 0) { if (size > 0) { indentBuilder.Append(stack[sp].indent); if (stack[sp].lineNr == lineNr) { n = stack[sp].nSpaces; } } indentBuilder.Append(' ', nSpaces - n); } else if (inside == Inside.Case) { while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedOrBlock) != 0) { indentBuilder.Append(stack[sp].indent); break; } sp--; } if (ie.Options.IndentSwitchBody) { indentBuilder.Append('\t'); } nSpaces = 0; } else if ((inside & (Inside.FoldedOrBlock)) != 0) { while (sp >= 0) { if ((stack[sp].inside & Inside.FoldedBlockOrCase) != 0) // Optional: Check for Inside.ParenList to align the following lines like the previous line { indentBuilder.Append(stack[sp].indent); break; } sp--; } Inside parent = size > 0 ? stack[size - 1].inside : Inside.Empty; // This is a workaround to make anonymous methods indent nicely if (parent == Inside.ParenList) { stack[size - 1].indent = indentBuilder.ToString(); } if (inside == Inside.FoldedStatement) { indentBuilder.Append('\t'); } else if (inside == Inside.Block || inside == Inside.SquareBracketList) { if (parent != Inside.Case || nSpaces != -1) { indentBuilder.Append('\t'); } } nSpaces = 0; } else if ((inside & (Inside.Shebang | Inside.PreProcessor | Inside.StringOrChar)) != 0) { // if these fold, do not indent nSpaces = 0; } else if (inside == Inside.LineComment || inside == Inside.DocComment) { // can't actually fold, but we still want to push it onto the stack nSpaces = 0; } else { // not a valid argument? throw new ArgumentOutOfRangeException(); } // Replace additionally inserted spaces with tabs if (!ie.tabsToSpaces && !ie.keepAlignmentSpaces) { n = 0; for (int i = 0; i < indentBuilder.Length; i++) { if (indentBuilder[i] == ' ') { n++; if (n >= ie.indentWidth) { // Decrement the space count as we're having tabs now. nSpaces -= n; i -= n - 1; indentBuilder.Remove(i, n); indentBuilder.Insert(i, '\t'); n = 0; } } else { n = 0; } } } node.indent = indentBuilder.ToString(); node.keyword = keyword; node.nSpaces = nSpaces; node.lineNr = lineNr; node.inside = inside; node.ifelseBackupStack = null; if (size == stack.Length) { Array.Resize <Node> (ref stack, 2 * size); } stack[size++] = node; }
void PushOpenBrace (Inside inside) { if ((inside & (Inside.PreProcessor | Inside.StringOrChar | Inside.Comment)) != 0) return; // push a new block onto the stack if (inside == Inside.FoldedStatement) { string pKeyword; if (firstNonLwsp == -1) { pKeyword = stack.PeekKeyword (0); stack.Pop (); } else { pKeyword = keyword; } while (true) { if (stack.PeekInside (0) != Inside.FoldedStatement) break; string kw = stack.PeekKeyword (0); stack.Pop (); TrimIndent (); if (!string.IsNullOrEmpty (kw)) { pKeyword = kw; break; } } if (firstNonLwsp == -1) curIndent = stack.PeekIndent (0); stack.Push (Inside.Block, pKeyword, curLineNr, 0); } else if (inside == Inside.Case && (keyword == "default" || keyword == "case")) { if (curLineNr == stack.PeekLineNr (0) || firstNonLwsp == -1) { // e.g. "case 0: {" or "case 0:\n{" stack.Push (Inside.Block, keyword, curLineNr, -1); if (firstNonLwsp == -1) TrimIndent (); } else { stack.Push (Inside.Block, keyword, curLineNr, 0); } } else { stack.Push (Inside.Block, keyword, curLineNr, 0); // Destroys one lined expression block 'var s = "".Split (new char[] {' '});' // if (inside == Inside.ParenList) // TrimIndent (); } keyword = String.Empty; if (firstNonLwsp == -1) needsReindent = true; }
// Handlers for specific characters void PushHash (Inside inside) { // ignore if we are inside a string, char, or comment if ((inside & (Inside.StringOrChar | Inside.Comment)) != 0) return; // ignore if '#' is not the first significant char on the line if (rc != '\0') return; stack.Push (Inside.PreProcessor, null, curLineNr, 0); curIndent = String.Empty; needsReindent = false; }
void PushNewLine (Inside inside) { top: switch (inside) { case Inside.PreProcessor: // pop the preprocesor state unless the eoln is escaped if (rc != '\\') { keyword = stack.PeekKeyword (0); stack.Pop (); } break; case Inside.MultiLineComment: // nothing to do break; case Inside.DocComment: case Inside.LineComment: // pop the line comment keyword = stack.PeekKeyword (0); stack.Pop (); inside = stack.PeekInside (0); goto top; case Inside.VerbatimString: // nothing to do break; case Inside.StringLiteral: if (isEscaped) { /* I don't think c# allows breaking a * normal string across lines even * when escaping the carriage * return... but how else should we * handle this? */ break; } /* not escaped... error!! but what can we do, * eh? allow folding across multiple lines I * guess... */ break; case Inside.CharLiteral: /* this is an error... what to do? guess we'll * just pretend it never happened */ break; case Inside.Attribute: // nothing to do break; case Inside.ParenList: // nothing to do break; default: // Empty, FoldedStatement, and Block switch (rc) { case '\0': // nothing entered on this line break; case ':': canBeLabel = canBeLabel && inside != Inside.FoldedStatement; if ((keyword == "default" || keyword == "case") || canBeLabel) break; PushFoldedStatement (); break; case '[': // handled elsewhere break; case ']': // handled elsewhere break; case '(': // handled elsewhere break; case '{': // handled elsewhere break; case '}': // handled elsewhere break; case ';': // handled elsewhere break; case ',': // avoid indenting if we are in a list break; default: if (stack.PeekLineNr (0) == curLineNr) { // is this right? I don't remember why I did this... break; } if (inside == Inside.Block) { if (stack.PeekKeyword (0) == "struct" || stack.PeekKeyword (0) == "enum" || stack.PeekKeyword (0) == "=") { // just variable/value declarations break; } } PushFoldedStatement (); break; } break; } linebuf.Length = 0; beganInside = stack.PeekInside (0); curIndent = stack.PeekIndent (0); canBeLabel = true; firstNonLwsp = -1; lastNonLwsp = -1; wordStart = -1; prc = '\0'; pc = '\0'; rc = '\0'; curLineNr++; cursor++; }
void PushSlash (Inside inside) { // ignore these if ((inside & (Inside.PreProcessor | Inside.StringOrChar )) != 0) return; if (inside == Inside.LineComment) { stack.Pop (); // pop line comment stack.Push (Inside.DocComment, keyword, curLineNr, 0); } else if (inside == Inside.MultiLineComment) { // check for end of multi-line comment block if (pc == '*') { // restore the keyword and pop the multiline comment keyword = stack.PeekKeyword (0); stack.Pop (); } } else { // FoldedStatement, Block, Attribute or ParenList // check for the start of a single-line comment if (pc == '/') { stack.Push (Inside.LineComment, keyword, curLineNr, 0); // drop the previous '/': it belongs to this comment rc = prc; } } }
public void Push (Inside inside, string keyword, int lineNr, int nSpaces, string indent) { Node node; node.Indent = indent; node.Keyword = keyword; node.NumSpaces = nSpaces; node.LineNr = lineNr; node.Inside = inside; if (size == stack.Length) Array.Resize <Node> (ref stack, 2 * size); stack[size++] = node; }
void PushBackSlash (Inside inside) { // string and char literals can have \-escapes if ((inside & (Inside.StringLiteral | Inside.CharLiteral)) != 0) isEscaped = !isEscaped; }
public void Reset() { offset = 0; thisLineindent.Reset(); indent.Reset(); pc = '\0'; IsLineStart = true; addContinuation = false; popNextParenBlock = false; parenStack.Clear(); inside = Inside.Empty; nextBody = currentBody = Body.None; line = col = 1; }
public void Push(char ch) { if (readPreprocessorExpression) { wordBuf.Append(ch); } if (inside.HasFlag(Inside.VerbatimString) && pc == '"' && ch != '"') { inside &= ~Inside.StringLiteral; } switch (ch) { case '#': if (IsLineStart) { inside = Inside.PreProcessor; } break; case '/': if (IsInStringOrChar || IsInPreProcessorComment) { break; } if (pc == '/') { if (inside.HasFlag(Inside.Comment)) { inside |= Inside.DocComment; } else { inside |= Inside.Comment; } } break; case '*': if (IsInStringOrChar || IsInComment || IsInPreProcessorComment) { break; } if (pc == '/') { inside |= Inside.MultiLineComment; } break; case ' ': currentIndent.Append(' '); break; case '\t': var nextTabStop = (col - 1 + textEditorOptions.IndentSize) / textEditorOptions.IndentSize; col = 1 + nextTabStop * textEditorOptions.IndentSize; currentIndent.Append('\t'); offset++; return; case '"': if (IsInComment || IsInPreProcessorComment) { break; } if (inside.HasFlag(Inside.StringLiteral)) { if (pc != '\\') { inside &= ~Inside.StringLiteral; } break; } if (pc == '@') { inside |= Inside.VerbatimString; } else { inside |= Inside.StringLiteral; } break; case '<': case '[': case '(': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) { break; } parenStack.Push(new TextLocation(line, col)); popNextParenBlock = true; indent.Push(IndentType.Block); break; case '>': case ']': case ')': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) { break; } if (popNextParenBlock && parenStack.Count > 0) { parenStack.Pop(); } if (indent.Count > 0) { indent.Pop(); } indent.ExtraSpaces = 0; break; case ',': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) { break; } if (parenStack.Count > 0 && parenStack.Peek().Line == line) { if (indent.Count > 0) { indent.Pop(); } popNextParenBlock = false; indent.ExtraSpaces = parenStack.Peek().Column - 1 - thisLineindent.CurIndent; } break; case '{': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) { break; } currentBody = nextBody; if (indent.Count > 0 && indent.Peek() == IndentType.Continuation) { indent.Pop(); } addContinuation = false; AddIndentation(currentBody); break; case '}': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) { break; } if (indentDelta.CurIndent > 0) { indentDelta.Pop(); if (indentDelta.Count > 0 && indentDelta.Peek() == IndentType.Continuation) { indentDelta.Pop(); } } else { if (thisLineindent.Count > 0) { thisLineindent.Pop(); } if (indent.Count > 0) { indent.Pop(); } } break; case ';': if (IsInComment || IsInStringOrChar || IsInPreProcessorComment) { break; } if (indent.Count > 0 && indent.Peek() == IndentType.Continuation) { indent.Pop(); } break; case '\'': if (IsInComment || inside.HasFlag(Inside.StringLiteral) || IsInPreProcessorComment) { break; } if (inside.HasFlag(Inside.CharLiteral)) { if (pc != '\\') { inside &= ~Inside.CharLiteral; } } else { inside &= Inside.CharLiteral; } break; default: var nl = NewLine.GetDelimiterLength(ch, pc); if (nl == 2) { break; } if (nl == 1) { if (readPreprocessorExpression) { if (!eval(wordBuf.ToString())) { inside |= Inside.PreProcessorComment; } } inside &= ~(Inside.Comment | Inside.String | Inside.CharLiteral | Inside.PreProcessor); CheckKeyword(wordBuf.ToString()); wordBuf.Length = 0; indent.Push(indentDelta); indentDelta = new Indent(textEditorOptions); if (addContinuation) { indent.Push(IndentType.Continuation); } thisLineindent = indent.Clone(); addContinuation = false; IsLineStart = true; readPreprocessorExpression = false; col = 1; line++; currentIndent.Length = 0; } break; } if (!IsInComment && !IsInStringOrChar && !readPreprocessorExpression) { if ((wordBuf.Length == 0 ? char.IsLetter(ch) : char.IsLetterOrDigit(ch)) || ch == '_') { wordBuf.Append(ch); } else { if (inside.HasFlag(Inside.PreProcessor)) { if (wordBuf.ToString() == "endif") { inside &= ~Inside.PreProcessorComment; } else if (wordBuf.ToString() == "if") { readPreprocessorExpression = true; } else if (wordBuf.ToString() == "elif") { inside &= ~Inside.PreProcessorComment; readPreprocessorExpression = true; } } else { CheckKeyword(wordBuf.ToString()); } wordBuf.Length = 0; } } if (addContinuation) { indent.Push(IndentType.Continuation); addContinuation = false; } IsLineStart &= ch == ' ' || ch == '\t' || NewLine.IsNewLine(ch); pc = ch; if (!NewLine.IsNewLine(ch)) { col++; } offset++; }