mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Added two new heuristics tests for the new C/C++/Obj-C heuristics
This commit is contained in:
		
							
								
								
									
										86
									
								
								samples/C++/16F88.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								samples/C++/16F88.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,86 @@ | ||||
| /* | ||||
|  * This file is part of PIC | ||||
|  * Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net) | ||||
|  * | ||||
|  * PIC is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * PIC is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| enum PIC16F88Instruction | ||||
| { | ||||
| 	ADDWF, | ||||
| 	ANDWF, | ||||
| 	CLRF, | ||||
| 	CLRW, | ||||
| 	COMF, | ||||
| 	DECF, | ||||
| 	DECFSZ, | ||||
| 	INCF, | ||||
| 	INCFSZ, | ||||
| 	IORWF, | ||||
| 	MOVF, | ||||
| 	MOVWF, | ||||
| 	NOP, | ||||
| 	RLF, | ||||
| 	RRF, | ||||
| 	SUBWF, | ||||
| 	SWAPF, | ||||
| 	XORWF, | ||||
| 	BCF, | ||||
| 	BSF, | ||||
| 	BTFSC, | ||||
| 	BTFSS, | ||||
| 	ADDLW, | ||||
| 	ANDLW, | ||||
| 	CALL, | ||||
| 	CLRWDT, | ||||
| 	GOTO, | ||||
| 	IORLW, | ||||
| 	MOVLW, | ||||
| 	RETFIE, | ||||
| 	RETLW, | ||||
| 	RETURN, | ||||
| 	SLEEP, | ||||
| 	SUBLW, | ||||
| 	XORLW | ||||
| }; | ||||
|  | ||||
| class PIC16F88 | ||||
| { | ||||
| public: | ||||
| 	PIC16F88(ROM *ProgramMemory); | ||||
| 	void Step(); | ||||
|  | ||||
| private: | ||||
| 	uint8_t q; | ||||
| 	bool nextIsNop, trapped; | ||||
| 	Memory *memory; | ||||
| 	ROM *program; | ||||
| 	Stack<uint16_t, 8> *CallStack; | ||||
| 	Register<uint16_t> *PC; | ||||
| 	Register<> *WREG, *PCL, *STATUS, *PCLATCH; | ||||
| 	PIC16F88Instruction inst; | ||||
| 	uint16_t instrWord; | ||||
|  | ||||
| private: | ||||
| 	void DecodeInstruction(); | ||||
| 	void ProcessInstruction(); | ||||
|  | ||||
| 	uint8_t GetBank(); | ||||
| 	uint8_t GetMemoryContents(uint8_t partialAddress); | ||||
| 	void SetMemoryContents(uint8_t partialAddress, uint8_t newVal); | ||||
| 	void CheckZero(uint8_t value); | ||||
| 	void StoreValue(uint8_t value, bool updateZero); | ||||
| 	uint8_t SetCarry(bool val); | ||||
| 	uint16_t GetPCHFinalBits(); | ||||
| }; | ||||
							
								
								
									
										32
									
								
								samples/C++/Memory16F88.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								samples/C++/Memory16F88.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| /* | ||||
|  * This file is part of PIC | ||||
|  * Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net) | ||||
|  * | ||||
|  * PIC is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * PIC is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| #include "Memory.h" | ||||
|  | ||||
| class Memory16F88 : public Memory | ||||
| { | ||||
| private: | ||||
| 	uint8_t memory[512]; | ||||
| 	std::map<uint32_t, MemoryLocation *> memoryMap; | ||||
|  | ||||
| public: | ||||
| 	Memory16F88(); | ||||
| 	uint8_t Dereference(uint8_t bank, uint8_t partialAddress); | ||||
| 	uint8_t *Reference(uint8_t bank, uint8_t partialAddress); | ||||
| 	uint8_t *operator [](uint32_t ref); | ||||
| }; | ||||
							
								
								
									
										76
									
								
								samples/C++/ThreadedQueue.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								samples/C++/ThreadedQueue.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,76 @@ | ||||
| /* | ||||
|  * This file is part of IRCBot | ||||
|  * Copyright © 2014 Rachel Mant (dx-mon@users.sourceforge.net) | ||||
|  * | ||||
|  * IRCBot is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * IRCBot is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| #ifndef __THREADED_QUEUE_H__ | ||||
| #define __THREADED_QUEUE_H__ | ||||
|  | ||||
| #include <pthread.h> | ||||
| #include <queue> | ||||
|  | ||||
| template<class T> | ||||
| class ThreadedQueue : public std::queue<T> | ||||
| { | ||||
| private: | ||||
| 	pthread_mutex_t queueMutex; | ||||
| 	pthread_cond_t queueCond; | ||||
|  | ||||
| public: | ||||
| 	ThreadedQueue() | ||||
| 	{ | ||||
| 		pthread_mutexattr_t mutexAttrs; | ||||
| 		pthread_condattr_t condAttrs; | ||||
|  | ||||
| 		pthread_mutexattr_init(&mutexAttrs); | ||||
| 		pthread_mutexattr_settype(&mutexAttrs, PTHREAD_MUTEX_ERRORCHECK); | ||||
| 		pthread_mutex_init(&queueMutex, &mutexAttrs); | ||||
| 		pthread_mutexattr_destroy(&mutexAttrs); | ||||
|  | ||||
| 		pthread_condattr_init(&condAttrs); | ||||
| 		pthread_condattr_setpshared(&condAttrs, PTHREAD_PROCESS_PRIVATE); | ||||
| 		pthread_cond_init(&queueCond, &condAttrs); | ||||
| 		pthread_condattr_destroy(&condAttrs); | ||||
| 	} | ||||
|  | ||||
| 	~ThreadedQueue() | ||||
| 	{ | ||||
| 		pthread_cond_destroy(&queueCond); | ||||
| 		pthread_mutex_destroy(&queueMutex); | ||||
| 	} | ||||
|  | ||||
| 	void waitItems() | ||||
| 	{ | ||||
| 		pthread_mutex_lock(&queueMutex); | ||||
| 		pthread_cond_wait(&queueCond, &queueMutex); | ||||
| 		pthread_mutex_unlock(&queueMutex); | ||||
| 	} | ||||
|  | ||||
| 	void signalItems() | ||||
| 	{ | ||||
| 		pthread_mutex_lock(&queueMutex); | ||||
| 		pthread_cond_broadcast(&queueCond); | ||||
| 		pthread_mutex_unlock(&queueMutex); | ||||
| 	} | ||||
|  | ||||
| 	void push(T item) | ||||
| 	{ | ||||
| 		std::queue<T>::push(item); | ||||
| 		signalItems(); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| #endif /*__THREADED_QUEUE_H__*/ | ||||
							
								
								
									
										93
									
								
								samples/C/ArrowLeft.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								samples/C/ArrowLeft.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,93 @@ | ||||
| /* | ||||
|  * This file is part of GTK++ (libGTK++) | ||||
|  * Copyright © 2012 Rachel Mant (dx-mon@users.sourceforge.net) | ||||
|  * | ||||
|  * GTK++ is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * GTK++ is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| /* GdkPixbuf RGBA C-Source image dump */ | ||||
|  | ||||
| #ifdef __SUNPRO_C | ||||
| #pragma align 4 (ArrowLeft) | ||||
| #endif | ||||
| #ifdef __GNUC__ | ||||
| static const uint8_t ArrowLeft[] __attribute__ ((__aligned__ (4))) =  | ||||
| #else | ||||
| static const uint8_t ArrowLeft[] =  | ||||
| #endif | ||||
| { "" | ||||
|   /* Pixbuf magic (0x47646b50) */ | ||||
|   "GdkP" | ||||
|   /* length: header (24) + pixel_data (1600) */ | ||||
|   "\0\0\6X" | ||||
|   /* pixdata_type (0x1010002) */ | ||||
|   "\1\1\0\2" | ||||
|   /* rowstride (80) */ | ||||
|   "\0\0\0P" | ||||
|   /* width (20) */ | ||||
|   "\0\0\0\24" | ||||
|   /* height (20) */ | ||||
|   "\0\0\0\24" | ||||
|   /* pixel_data: */ | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\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\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377" | ||||
|   "\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377" | ||||
|   "\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\377\0\0\0\377\0" | ||||
|   "\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0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\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||||
|   "\0\0"}; | ||||
|  | ||||
|  | ||||
| @@ -32,6 +32,15 @@ class TestHeuristcs < Test::Unit::TestCase | ||||
|     languages = ["C++", "Objective-C"] | ||||
|     results = Heuristics.disambiguate_c(fixture("C++/render_adapter.cpp"), languages) | ||||
|     assert_equal Language["C++"], results.first | ||||
|     languages = ["C++", "Objective-C", "C"] | ||||
|     results = Heuristics.disambiguate_c(fixture("C++/ThreadedQueue.h"), languages) | ||||
|     assert_equal Language["C++"], results.first | ||||
|   end | ||||
|  | ||||
|   def test_c_by_heuristics | ||||
|     languages = ["C++", "Objective-C", "C"] | ||||
|     results = Heuristics.disambiguate_c(fixture("C/ArrowLeft.h"), languages) | ||||
|     assert_equal nil, results.first | ||||
|   end | ||||
|  | ||||
|   def test_detect_still_works_if_nothing_matches | ||||
|   | ||||
		Reference in New Issue
	
	Block a user