FeaturesCompletion

apla edited this page Feb 10, 2015 · 1 revision

layout: wiki-gui-page title: "Features: Autocompletion" permalink: /gui/FeaturesCompletion/

Autocompletion

Arduino IDE will get code completion and error check using eclipse's CDT.

libclang

I decided to use libclang for AST.

Here some links to fix various problems I've found so far.

I use libclang without AVR support because I don't need an error messages at this time, only source tokenizer.

Current status

Sometimes in future this part will go to the separate project. No reason to create C/C++ project environment to compile only Arduinos.

I created test environment using node-libclang, processed ino file and Arduino headers. To make it work, I need to add dll/so/dylib to library search path.

Code below produce some understandable and good looking output, but at this time external function prototypes from *.h not found in output.

all files

var libclang = require('libclang');
var Index = libclang.Index;
var Cursor = libclang.Cursor;
var TranslationUnit = libclang.TranslationUnit;

var index = new Index(true, true);

var source = "/var/folders/r4/d4l8c_ts4rsdc670pdkbtr0m0000gp/T/Sensor-cuwire-01189b11/Sensor.cpp";

var tu = TranslationUnit.fromSource(
	index,
	source, [
//		"-fsyntax-only",
		"-nostdinc",
//		"-nostdlibinc",
//		"-nobuiltininc",
// less warnings if platform/hardware flags not defined
		"-MMD",
		"-xc++",
		"-DF_CPU=16000000L",
		"-DARDUINO=158",
		"-DARDUINO_AVR_PRO",
		"-DARDUINO_ARCH_AVR",
		"-D__AVR_ATmega328P__",
		"-D__AVR__",
// end less warnings
		"-I/Applications/devel/Arduino.app/Contents/Java/hardware/tools/avr/lib/gcc/avr/4.8.1/include/",
		"-I/Applications/devel/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/",
		"-I/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino",
		"-I/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/variants/eightanaloginputs",
		"-I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/libraries/Wire",
		"-I/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/EEPROM",
		"-I/Users/apla/Documents/Arduino/libraries/Time",
		"-I/Users/apla/Documents/Arduino/libraries/DS3231RTC",
		"-I/Users/apla/Documents/Arduino/libraries/EtherCard",
		"-I/Users/apla/Documents/Arduino/libraries/JeeLib"
	]
);

//console.log (Cursor);

tu.cursor.visitChildren(function (parent) {
//	console.log (parent);
//	if (this.spelling === "analogRead") {
	console.log (this.spelling, this.kind, this.location.presumedLocation);
//	}
	switch (this.kind) {
		case Cursor.FunctionDecl:
			console.log('function', this.spelling, this.location.presumedLocation);
			// TODO: try/catch?
			var self = this;
//			this.visitChildren (function (parent) {
//				console.log ('function', self.spelling, 'has child', this.spelling);
//			});
			//console.log('displayName', this.displayName);
//			console.log (this);
//			process.exit(0);
			break;
		case Cursor.MacroDefinition:
//			console.log('macro', this.spelling);
			break;
		case Cursor.InclusionDirective:
//			console.log('inclusion', this.spelling);
			break;
	}
	return Cursor.Continue;
});

index.dispose();
//tu.dispose();

prototype of analogRead is declared between lines 115 and 150 of Arduino.h, but nothing found


bitClear 501 { filename: '/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h',
	line: 105,
	column: 9 }
bitWrite 501 { filename: '/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h',
	line: 106,
	column: 9 }
_NOP 501 { filename: '/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h',
	line: 110,
	column: 9 }
bit 501 { filename: '/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h',
	line: 115,
	column: 9 }
analogInPinToBit 501 { filename: '/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h',
	line: 150,
	column: 9 }
PROGMEM 502 { filename: '/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h',
	line: 154,
	column: 23 }
PROGMEM 502 { filename: '/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h',
	line: 155,
	column: 23 }
PROGMEM 502 { filename: '/Applications/devel/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h',
	line: 156,
	column: 23 }

Autocompletion links

binaries download


nodejs:


python:


notes:


clang/llvm for avr


legacy:


atom autocomplete clang

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.