void AttemptEmitLineDirective(CodeFileType type, int line, String fileName) { if (this.EmitLineDirectives) { this.AppendCodeSeparateLine(type, "#line " + line + " \"" + Path.GetFileName(fileName) + "\""); } }
public XElement GetTemplateByType(CodeFileType type) { var doc = XDocument.Load(Directory.GetCurrentDirectory() + "\\App_Data\\IntelliCode.ct"); return doc.Descendants("Name").Where(d => d.Value == type.ToString()) .Select(d => d.Parent).SingleOrDefault(); }
private void FillDataExtracted(CodeFileType fileType, TextBox obj, TextBox objName) { var section = _template.GetTemplateByType(fileType.ToString()).TemplatSections; obj.Text = section.Find(s => s.Name == "FileLocation").Value; objName.Text = section.Find(s => s.Name == "FileName").Value; }
public void AddFile(string File, CodeFileType Which) { CodeFile NewFile = new CodeFile(); NewFile.Name = File; NewFile.Type = Which; _Files.Add(NewFile); }
public void AddFile(string File, CodeFileType Which, string Dependant) { CodeFile NewFile = new CodeFile(); NewFile.Name = File; NewFile.Type = Which; NewFile.Dependant = Dependant; _Files.Add(NewFile); }
/// <summary> /// Parses a template and returns the generated code /// </summary> /// <returns></returns> public CodeFile[] ParseTemplate() { string type = _templateLines[0].Replace("#Type:", "").Replace("#", ""); _type = (CodeFileType)Enum.Parse(typeof(CodeFileType), type); if (_templateLines[1] == "#IndexDefinition#") return ParseIndexes(); else return ParseTablesAndViews(); }
void AppendCode(CodeFileType type, String code, Int32 start = 0, Int32 length = -1) { if (length == -1) { length = code.Length; } if (type == CodeFileType.HppFile) { this.SingleHpp.Append(code, start, length); } else { this.SingleCpp.Append(code, start, length); } }
public string AddFile(string relativePath, CodeFileType type) { if (string.IsNullOrEmpty(relativePath)) throw new ArgumentException(nameof(relativePath), nameof(relativePath)); var pathSplits = relativePath.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); var newPathSplits = new Stack<string>(); foreach (var split in ProjectDirectorySplits) { newPathSplits.Push(split); } foreach (var split in pathSplits) { if (split == "..") { newPathSplits.Pop(); } else { newPathSplits.Push(split); } } if (newPathSplits.Count == 0) return String.Empty; var resolved = string.Join(Path.DirectorySeparatorChar.ToString(), newPathSplits.Reverse().ToArray()); switch (type) { case CodeFileType.Compilation: CompilationPaths.Add(resolved); break; case CodeFileType.Content: ContentPaths.Add(resolved); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } return resolved; }
public UnitTestBuilder(string productName, CodeFileType type) : base(productName, type) { }
public Repository(string productName, CodeFileType type) : base(productName, type) { }
public BusinessManager(string productName, CodeFileType type) : base(productName, type) { }
public ServiceObject(string productName, CodeFileType type) : base(productName, type) { }
IncludeStatus ProcessIncludeCodeFile(Stack <String> debugFileStack, String codeFile, CodeFileType parentFile) { var status = IncludeStatus.None; var code = File.ReadAllText(codeFile); // If the file is a pragma once file, it should always be treated as a normal include and go into the include file if (PragmaOnceRegex.IsMatch(code)) { status = IncludeStatus.PragmaOnce; this.ProcessCodeFile(debugFileStack, codeFile, code, CodeFileType.HppFile); } else { // Otherwise, it's basically be included like an 'inl' file, which is always included into its parent this.ProcessCodeFile(debugFileStack, codeFile, code, parentFile); } return(status); }
void ProcessCodeFile(Stack <String> debugFileStack, String codeFile, String code, CodeFileType type) { if (debugFileStack.Contains(codeFile)) { var builder = new StringBuilder(); foreach (var file in debugFileStack) { builder.AppendLine(" " + file); } throw new Exception("Cycle of inclusion detected: \n" + builder.ToString()); } debugFileStack.Push(codeFile); if (debugFileStack.Count == 50) { throw new Exception("Possible cycle of inclusion! Recursion depth was too deep"); } var directoryDirective = new CompacterDirectives(); var directoryPath = NormalizePath(Path.GetDirectoryName(codeFile)); if (this.DirectoryDirectives.ContainsKey(directoryPath)) { directoryDirective = this.DirectoryDirectives[directoryPath]; } var directives = this.ParseDirectives(debugFileStack, code, directoryDirective); if (this.OutputDirectory != null) { var pathToOutput = Path.Combine(this.OutputDirectory, Path.GetFileName(codeFile)); //if (File.Exists(pathToOutput) == false) //{ // File.WriteAllText(pathToOutput, code); //} //else if (File.ReadAllText(pathToOutput) != code) //{ // String error = "The file '" + Path.GetFileName(pathToOutput) + "' has the same name as another file"; // error = error; // //throw new Exception("The file '" + Path.GetFileName(pathToOutput) + "' has the same name as another file"); //} } // If this is meant to only be included in a cpp file, then just set the type to cpp if (directives.CppOnly) { type = CodeFileType.CppFile; // Remove all pragma once declarations code = PragmaOnceRegex.Replace(code, String.Empty); } if (directives.PreprocessorCondition != null) { this.AppendCodeSeparateLine(type, "#if " + directives.PreprocessorCondition); } int line = 1; // When we compile, we want to make sure we get errors in the correct places this.AttemptEmitLineDirective(type, line, codeFile); var fullName = codeFile; var strIndex = 0; // Scan for includes var matches = IncludeRegex.Matches(code); foreach (Match match in matches) { // Skip any includes that are commented out // This does NOT catch multi-line comments! if (SingleLineComment.IsMatch(match.Value)) { continue; } // Cpps include both cpp and header files int prevCodeLength = match.Index - strIndex; this.AppendCode(type, code, strIndex, prevCodeLength); line += this.CountLines(code, strIndex, prevCodeLength); strIndex = match.Index + match.Length; var includeFile = match.Groups[1].Value; var fullPathToIncludeFile = this.ScanForInclude(includeFile, Path.GetDirectoryName(codeFile), debugFileStack); if (fullPathToIncludeFile != null) { if (this.ProcessedOnceIncludeFiles.Contains(fullPathToIncludeFile) == false) { var includeStatus = this.ProcessIncludeCodeFile(debugFileStack, fullPathToIncludeFile, type); // We only ever add the include to the 'all includes' if it contains a pragma-once // Otherwise, we may want to reprocess that include if (includeStatus == IncludeStatus.PragmaOnce) { this.ProcessedOnceIncludeFiles.Add(fullPathToIncludeFile); } // Since we just entered another file (and probably emitted) and now we're back in our own file, emit a line directive again) this.AttemptEmitLineDirective(type, line, codeFile); } } else { var afterInclude = match.Groups[2].Value; if (afterInclude.Contains("@ignore") == false) { this.EmitWarning(debugFileStack, "Unable to find '" + includeFile + "'"); } this.AppendCode(type, match.Value, 0, match.Value.Length); } } this.AppendCode(type, code, strIndex, code.Length - strIndex); if (directives.PreprocessorCondition != null) { this.AppendCode(type, Environment.NewLine + "#endif" + Environment.NewLine); } debugFileStack.Pop(); }
void AppendCodeSeparateLine(CodeFileType type, String code) { this.AppendCode(type, Environment.NewLine + code + Environment.NewLine); }
public CodeBuilderBase(string productName, CodeFileType type) { Template = new Template().GetTemplateByType(type); Type = type; ProductName = productName; }
private void SaveData(CodeFileType fileType, TextBox obj, TextBox objName) { _template.SaveTemplateSection(obj.Text, fileType.ToString(), "FileLocation"); _template.SaveTemplateSection(objName.Text, fileType.ToString(), "FileName"); }
public APIManager(string productName, CodeFileType type) : base(productName, type) { }
public void VerifyAddFileThrow(CodeFileType type) { var manager = new CodeFileManager(_rootPath); Assert.Throws<ArgumentException>(() => manager.AddFile(null, type)); Assert.Throws<ArgumentException>(() => manager.AddFile(string.Empty, type)); }