-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pmderodat/preprocessing' into 'master'
Preprocessor: fix file reader when source file cannot be read Closes #1126 See merge request eng/libadalang/libadalang!1453
- Loading branch information
Showing
9 changed files
with
139 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pragma Foo ($Foo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pragma Foo; | ||
#end if; | ||
pragma Bar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
with Ada.Text_IO; use Ada.Text_IO; | ||
|
||
with GPR2.Context; | ||
with GPR2.Path_Name; | ||
with GPR2.Project.Tree; | ||
|
||
with Libadalang.Analysis; use Libadalang.Analysis; | ||
with Libadalang.Preprocessing; use Libadalang.Preprocessing; | ||
|
||
procedure Main is | ||
|
||
Ctx : Analysis_Context; | ||
|
||
procedure Process (Filename : String); | ||
-- Parse the requested file and print its diagnostics and parse tree | ||
|
||
------------- | ||
-- Process -- | ||
------------- | ||
|
||
procedure Process (Filename : String) is | ||
U : constant Analysis_Unit := | ||
Ctx.Get_From_File (Filename, Charset => "utf-8"); | ||
begin | ||
Put_Line ("== " & Filename & " =="); | ||
New_Line; | ||
if U.Has_Diagnostics then | ||
for D of U.Diagnostics loop | ||
Put_Line (U.Format_GNU_Diagnostic (D)); | ||
end loop; | ||
New_Line; | ||
end if; | ||
U.Root.Print; | ||
New_Line; | ||
end Process; | ||
|
||
-- Create a context from the example project | ||
|
||
Tree : GPR2.Project.Tree.Object; | ||
begin | ||
Tree.Load_Autoconf | ||
(Filename => GPR2.Path_Name.Create_File | ||
("p.gpr", GPR2.Path_Name.No_Resolution), | ||
Context => GPR2.Context.Empty); | ||
Ctx := Create_Context_From_Project (Tree); | ||
|
||
-- As a sanity check, first make sure that preprocessing is active | ||
|
||
Process ("foo.adb"); | ||
|
||
-- Then check error cases: the source file cannot be read | ||
|
||
Process ("no_such_file.adb"); | ||
|
||
-- Preprocessing aborts because of a syntax error | ||
|
||
Process ("invalid.adb"); | ||
|
||
-- Buffer decoding after preprocessing fails because of an encoding error | ||
|
||
Process ("bad_encoding.bin"); | ||
|
||
Put_Line ("Done."); | ||
end Main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
project P is | ||
package Compiler is | ||
for Default_Switches ("Ada") use ("-gnateDfoo=null"); | ||
end Compiler; | ||
end P; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
== foo.adb == | ||
|
||
PragmaNodeList[1:1-1:19] | ||
| PragmaNode[1:1-1:19] | ||
| |f_id: | ||
| | Id[1:8-1:11]: Foo | ||
| |f_args: | ||
| | BaseAssocList[1:13-1:17] | ||
| | | PragmaArgumentAssoc[1:13-1:17] | ||
| | | |f_name: <null> | ||
| | | |f_expr: | ||
| | | | Null[1:13-1:17]: null | ||
|
||
== no_such_file.adb == | ||
|
||
no_such_file.adb: Cannot open [working-dir]/no_such_file.adb | ||
|
||
CompilationUnitList[1:1-1:1]: <empty list> | ||
|
||
== invalid.adb == | ||
|
||
invalid.adb:2:2: no matching "#if" | ||
|
||
PragmaNodeList[1:1-3:12] | ||
| PragmaNode[1:1-1:12] | ||
| |f_id: | ||
| | Id[1:8-1:11]: Foo | ||
| |f_args: | ||
| | BaseAssocList[1:7-1:7]: <empty list> | ||
| PragmaNode[3:1-3:12] | ||
| |f_id: | ||
| | Id[3:8-3:11]: Bar | ||
| |f_args: | ||
| | BaseAssocList[3:7-3:7]: <empty list> | ||
|
||
== bad_encoding.bin == | ||
|
||
bad_encoding.bin:1:1: Could not decode source as "utf-8" | ||
|
||
CompilationUnitList[1:1-1:1]: <empty list> | ||
|
||
Done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
driver: ada-api | ||
main: main.adb | ||
canonicalize_working_dir: true | ||
control: | ||
- [XFAIL, "valgrind", "Pending resolution of eng/gpr/gpr-issues#43"] |