Example #1
0
		public Enumeration (Tag tag, Project project, string ctags_output) : base (tag, project)
		{
			if (GetNamespace (tag, ctags_output)) return;
			if (GetClass (tag, ctags_output)) return;
			if (GetStructure (tag, ctags_output)) return;
			if (GetUnion (tag, ctags_output)) return;
		}
		/// <summary>
		/// Attempts to get the namespace encompasing the function
		/// returns true on success and false if it does not have one.
		/// NOTE: if it's a method then even if the class it belongs to
		/// has a namespace the method will not have a namespace since
		/// it should be placed under the class node and not the namespace node
		/// </summary>
		protected bool GetNamespace (Tag tag, string ctags_output)
		{
			string n;
			
			if ((n = tag.Namespace) != null) {
				int index = n.LastIndexOf (':');
				
				if (index > 0)
					n = n.Substring (index + 1);
				
				try {
					Tag namespaceTag = TagDatabaseManager.Instance.FindTag (
					    n, TagKind.Namespace, ctags_output);
					
					if (namespaceTag != null)
						parent = new Namespace (namespaceTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
		public LanguageItem (Tag tag, Project project)
		{
			this.project = project;
			this.name = tag.Name;
			this.file = tag.File;
			this.line = tag.Line;
			this.access = tag.Access;
		}
Example #4
0
		public LanguageItem (Tag tag, Project project)
		{
			this.project = project;
			this.name = tag.Name;
			this.file = tag.File;
			this.pattern = tag.Pattern;
			this.access = tag.Access;
		}
Example #5
0
		public Member (Tag tag, Project project, string ctags_output) : base (tag, project)
		{
			GetInstanceType (tag);
			
			if (GetClass (tag, ctags_output)) return;
			if (GetStructure (tag, ctags_output)) return;
			if (GetUnion (tag, ctags_output)) return;
		}
Example #6
0
        public Function(Tag tag, Project project, string ctags_output)
            : base(tag, project)
        {
            signature = tag.Signature;
            ParseSignature (tag.Signature);

            if (GetNamespace (tag, ctags_output)) return;
            if (GetClass (tag, ctags_output)) return;
            if (GetStructure (tag, ctags_output)) return;
            if (GetUnion (tag, ctags_output)) return;

            // TODO: Remove all this when sure it is no longer needed
            // (because we no longer generate prototype tags).
            //			if (tag.Kind == TagKind.Prototype) {
            //				Access = tag.Access;
            //				if (GetNamespace (tag, ctags_output)) return;
            //				if (GetClass (tag, ctags_output)) return;
            //				if (GetStructure (tag, ctags_output)) return;
            //				if (GetUnion (tag, ctags_output)) return;
            //			} else {
            //				// If it is not a prototype tag, we attempt to get the prototype tag
            //				// we need the prototype tag because the implementation tag
            //				// marks the belonging namespace as a if it were a class
            //				// and it does not have the access field.
            //				Tag prototypeTag = TagDatabaseManager.Instance.FindTag (Name, TagKind.Prototype, ctags_output);
            //
            //				if (prototypeTag == null) {
            //					// It does not have a prototype tag which means it is inline
            //					// and when it is inline it does have all the info we need
            //
            //					if (GetNamespace (tag, ctags_output)) return;
            //					if (GetClass (tag, ctags_output)) return;
            //					if (GetStructure (tag, ctags_output)) return;
            //					if (GetUnion (tag, ctags_output)) return;
            //
            //					return;
            //				}
            //
            //				// we need to re-get the access
            //				Access = prototypeTag.Access;
            //
            //				if (GetNamespace (prototypeTag, ctags_output)) return;
            //				if (GetClass (prototypeTag, ctags_output)) return;
            //				if (GetStructure (prototypeTag, ctags_output)) return;
            //				if (GetUnion (prototypeTag, ctags_output)) return;
            //			}
        }
Example #7
0
		/// <summary>
		/// Populates an instance's instanceType and isPointer fields 
		/// by matching its pattern against InstanceTypeExpression
		/// </summary>
		/// <param name="tag">
		/// The partially-populated tag of an instance
		/// <see cref="Tag"/>
		/// </param>
		/// <returns>
		/// Whether the regex was successfully matched
		/// <see cref="System.Boolean"/>
		/// </returns>
		protected bool GetInstanceType (Tag tag) {
			try {
				string declaration = null;
				
				using (StreamReader reader = new StreamReader (tag.File)) {
					for (ulong i=0; i<tag.Line; ++i) {
						declaration = reader.ReadLine ();
					}
				}
				
				Match m = InstanceTypeExpression.Match (declaration);
				
				if (null != m) {
					instanceType = m.Groups["type"].Value;
					isPointer = m.Groups["pointer"].Success;
					return true;
				}
			} catch { }
			
			return false;
		}
Example #8
0
		public Enumerator (Tag tag, Project project, string ctags_output) : base (tag, project)
		{
				GetEnumeration (tag, ctags_output);
		}
		protected bool GetClass (Tag tag, string ctags_output)
		{
			string c;
			
			if ((c = tag.Class) != null) {
				int index = c.LastIndexOf (':');
				
				if (index > 0)
					c = c.Substring (index + 1);
				
				try {
					Tag classTag = TagDatabaseManager.Instance.FindTag (
					    c, TagKind.Class, ctags_output);
					
					if (classTag != null)
						parent = new Class (classTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
		protected bool GetUnion (Tag tag, string ctags_output)
		{
			string u;
			
			if ((u = tag.Union) != null) {
				int index = u.LastIndexOf (':');
				
				if (index > 0)
					u = u.Substring (index + 1);
				
				try {
					Tag unionTag = TagDatabaseManager.Instance.FindTag (
					    u, TagKind.Union, ctags_output);
					
					if (unionTag != null)
						parent = new Union (unionTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
        Tag BinarySearch(string[] ctags_lines, TagKind kind, string name)
        {
            int low;
            int high = ctags_lines.Length - 2;             // last element is an empty string (because of the Split)
            int mid;
            int start_index = 0;

            // Skip initial comment lines
            while (ctags_lines[start_index].StartsWith("!_"))
            {
                start_index++;
            }

            low = start_index;

            while (low <= high)
            {
                mid = (low + high) / 2;
                string entry    = ctags_lines[mid];
                string tag_name = entry.Substring(0, entry.IndexOf('\t'));
                int    res      = string.CompareOrdinal(tag_name, name);

                if (res < 0)
                {
                    low = mid + 1;
                }
                else if (res > 0)
                {
                    high = mid - 1;
                }
                else
                {
                    // The tag we are at has the same name than the one we are looking for
                    // but not necessarily the same type, the actual tag we are looking
                    // for might be higher up or down, so we try both, starting with going down.
                    int  save       = mid;
                    bool going_down = true;
                    bool eof        = false;

                    while (true)
                    {
                        Tag tag = ctags.ParseTag(entry);

                        if (tag == null)
                        {
                            return(null);
                        }

                        if (tag.Kind == kind && tag_name == name)
                        {
                            return(tag);
                        }

                        if (going_down)
                        {
                            mid++;

                            if (mid >= ctags_lines.Length - 1)
                            {
                                eof = true;
                            }

                            if (!eof)
                            {
                                entry    = ctags_lines[mid];
                                tag_name = entry.Substring(0, entry.IndexOf('\t'));

                                if (tag_name != name)
                                {
                                    going_down = false;
                                    mid        = save - 1;
                                }
                            }
                            else
                            {
                                going_down = false;
                                mid        = save - 1;
                            }
                        }
                        else                             // going up
                        {
                            mid--;

                            if (mid < start_index)
                            {
                                return(null);
                            }

                            entry    = ctags_lines[mid];
                            tag_name = entry.Substring(0, entry.IndexOf('\t'));

                            if (tag_name != name)
                            {
                                return(null);
                            }
                        }
                    }
                }
            }

            return(null);
        }
		protected bool GetStructure (Tag tag, string ctags_output)
		{
			string s;
			
			if ((s = tag.Structure) != null) {
				int index = s.LastIndexOf (':');
				
				if (index > 0)
					s = s.Substring (index + 1);
				
				try {
					Tag classTag = TagDatabaseManager.Instance.FindTag (
					    s, TagKind.Structure, ctags_output);
					
					if (classTag != null)
						parent = new Structure (classTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
		private void AddInfo (FileInformation info, Tag tag, string ctags_output)
		{
			switch (tag.Kind)
			{
			case TagKind.Class:
				Class c = new Class (tag, info.Project, ctags_output);
				if (!info.Classes.Contains (c))
					info.Classes.Add (c);
				break;
			case TagKind.Enumeration:
				Enumeration e = new Enumeration (tag, info.Project, ctags_output);
				if (!info.Enumerations.Contains (e))
					info.Enumerations.Add (e);
				break;
			case TagKind.Enumerator:
				Enumerator en= new Enumerator (tag, info.Project, ctags_output);
				if (!info.Enumerators.Contains (en))
					info.Enumerators.Add (en);
				break;
			case TagKind.ExternalVariable:
				break;
			case TagKind.Function:
				Function f = new Function (tag, info.Project, ctags_output);
				if (!info.Functions.Contains (f))
					info.Functions.Add (f);
				break;
			case TagKind.Local:
				Local lo = new Local (tag, info.Project, ctags_output);
				if(!info.Locals.Contains (lo))
					info.Locals.Add (lo);
				break;
			case TagKind.Macro:
				Macro m = new Macro (tag, info.Project);
				if (!info.Macros.Contains (m))
					info.Macros.Add (m);
				break;
			case TagKind.Member:
				Member me = new Member (tag, info.Project, ctags_output);
				if (!info.Members.Contains (me))
					info.Members.Add (me);
				break;
			case TagKind.Namespace:
				Namespace n = new Namespace (tag, info.Project, ctags_output);
				if (!info.Namespaces.Contains (n))
					info.Namespaces.Add (n);
				break;
			case TagKind.Prototype:
				Function fu = new Function (tag, info.Project, ctags_output);
				if (!info.Functions.Contains (fu))
					info.Functions.Add (fu);
				break;
			case TagKind.Structure:
				Structure s = new Structure (tag, info.Project, ctags_output);
				if (!info.Structures.Contains (s))
					info.Structures.Add (s);
				break;
			case TagKind.Typedef:
				Typedef t = new Typedef (tag, info.Project, ctags_output);
				if (!info.Typedefs.Contains (t))
					info.Typedefs.Add (t);
				break;
			case TagKind.Union:
				Union u = new Union (tag, info.Project, ctags_output);
				if (!info.Unions.Contains (u))
					info.Unions.Add (u);
				break;
			case TagKind.Variable:
				Variable v = new Variable (tag, info.Project);
				if (!info.Variables.Contains (v))
					info.Variables.Add (v);
				break;
			default:
				break;
			}
		}
Example #14
0
		public Local (Tag tag, Project project, string ctags_output) : base (tag, project, ctags_output)
		{
		}
Example #15
0
		public Macro (Tag tag, Project project) : base (tag, project)
		{
		}
		protected bool GetEnumeration (Tag tag, string ctags_output)
		{
			string e;
			
			if ((e = tag.Enum) != null) {
				int index = e.LastIndexOf (':');
				
				if (index > 0)
					e = e.Substring (index + 1);
				
				try {
					Tag enumTag = TagDatabaseManager.Instance.FindTag (
					    e, TagKind.Enumeration, ctags_output);
					
					if (enumTag != null)
						parent = new Enumeration (enumTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
Example #17
0
		public Namespace (Tag tag, Project project, string ctags_output) : base (tag, project)
		{			
			GetNamespace (tag, ctags_output);
		}
Example #18
0
		public Variable (Tag tag, Project project) : base (tag, project)
		{
		}